Files
clide/lib/kernel/src/window_controls.dart
T
Jeroen SchweitzerandClaude Opus 4.6 73e80a55a6 add Toolchain, GitClient, native directory picker
Toolchain centralizes binary resolution — replaces five ad-hoc
mechanisms (expandedPath, _resolveGit, _resolve, _resolvePtyc,
_existsOnPath). Resolves via Future.delayed after runApp to avoid
blocking the merged UI/platform thread on macOS.

GitClient wraps all git operations with a typed API. Every subprocess
call goes through _run() using toolchain.git + toolchain.gitEnv.
Replaces free functions in operations.dart.

Native directory picker: NSOpenPanel on macOS (method channel in
AppDelegate), GtkFileChooserDialog on Linux. Falls back to text-input
dialog on web or MissingPluginException. Shows "No git repo found"
dialog when the selected directory is not a git repository.

PqlClient and pane commands updated to use Toolchain. ToolCheck
replaced by Toolchain.missing/allOk. All IPC handlers now catch
GitException to prevent unhandled exceptions on the merged thread.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-25 13:18:39 +02:00

77 lines
1.8 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
enum ChromeStyle { seam, prompt, inline }
enum ResizeEdge { topLeft, top, topRight, left, right, bottomLeft, bottom, bottomRight }
class WindowControls extends ChangeNotifier {
static const _channel = MethodChannel('clide/window');
ChromeStyle _style = ChromeStyle.seam;
ChromeStyle get style => _style;
void setStyle(ChromeStyle s) {
if (_style == s) return;
_style = s;
notifyListeners();
}
Future<void> startResize(ResizeEdge edge) async {
try {
await _channel.invokeMethod('startResize', edge.index);
} on MissingPluginException {
// no-op
}
}
Future<void> startDrag() async {
try {
await _channel.invokeMethod('startDrag');
} on MissingPluginException {
// no-op
}
}
Future<void> minimize() async {
try {
await _channel.invokeMethod('minimize');
} on MissingPluginException {
// no-op
}
}
Future<void> toggleMaximize() async {
try {
await _channel.invokeMethod('maximize');
} on MissingPluginException {
// no-op
}
}
Future<void> close() async {
try {
await _channel.invokeMethod('close');
} on MissingPluginException {
// no-op
}
}
Future<bool> isMaximized() async {
try {
final result = await _channel.invokeMethod<bool>('isMaximized');
return result ?? false;
} on MissingPluginException {
return false;
}
}
/// Opens the native OS directory picker.
/// Returns the selected path, or null if the user cancelled.
/// Throws [MissingPluginException] if the platform has no handler,
/// so callers can fall back to a text-input dialog.
Future<String?> pickDirectory() {
return _channel.invokeMethod<String>('pickDirectory');
}
}