Improve handling of hidden/shown window

This commit is contained in:
Dennis Fokin 2024-01-23 13:20:04 +01:00
parent 3c260e5bac
commit 127b1427f1
No known key found for this signature in database
GPG Key ID: 870B88256690D8BC
3 changed files with 9 additions and 9 deletions

View File

@ -141,15 +141,14 @@ Future<Widget> initialize(List<String> argv) async {
_log.debug('Using saved window bounds (or defaults): $bounds');
unawaited(windowManager
.waitUntilReadyToShow(WindowOptions(
.waitUntilReadyToShow(const WindowOptions(
minimumSize: WindowDefaults.minSize,
skipTaskbar: isHidden,
skipTaskbar: false,
))
.then((_) async {
await windowManagerHelper.setBounds(bounds);
if (isHidden) {
await windowManager.setSkipTaskbar(true);
} else {
await windowManager.show();
}

View File

@ -97,7 +97,6 @@ class DesktopWindowStateNotifier extends StateNotifier<WindowState>
} else {
await windowManager.show();
}
await windowManager.setSkipTaskbar(hidden);
await _prefs.setBool(windowHidden, hidden);
state = state.copyWith(hidden: hidden);
}

View File

@ -149,9 +149,10 @@ class _Systray extends TrayListener {
}
@override
void onTrayIconMouseDown() {
void onTrayIconMouseDown() async {
if (Platform.isMacOS) {
trayManager.popUpContextMenu();
await _updateContextMenu();
await trayManager.popUpContextMenu();
} else {
final now = DateTime.now().millisecondsSinceEpoch;
if (now - _lastClick < 500) {
@ -159,7 +160,7 @@ class _Systray extends TrayListener {
if (_isHidden) {
_ref.read(desktopWindowStateProvider.notifier).setWindowHidden(false);
} else {
windowManager.focus();
await windowManager.focus();
}
} else {
_lastClick = now;
@ -173,6 +174,7 @@ class _Systray extends TrayListener {
}
Future<void> _updateContextMenu() async {
final isVisible = await windowManager.isVisible();
await trayManager.setContextMenu(
Menu(
items: [
@ -207,11 +209,11 @@ class _Systray extends TrayListener {
),
MenuItem.separator(),
MenuItem(
label: _isHidden ? _l10n.s_show_window : _l10n.s_hide_window,
label: !isVisible ? _l10n.s_show_window : _l10n.s_hide_window,
onClick: (_) {
_ref
.read(desktopWindowStateProvider.notifier)
.setWindowHidden(!_isHidden);
.setWindowHidden(isVisible);
},
),
MenuItem.separator(),