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'); _log.debug('Using saved window bounds (or defaults): $bounds');
unawaited(windowManager unawaited(windowManager
.waitUntilReadyToShow(WindowOptions( .waitUntilReadyToShow(const WindowOptions(
minimumSize: WindowDefaults.minSize, minimumSize: WindowDefaults.minSize,
skipTaskbar: isHidden, skipTaskbar: false,
)) ))
.then((_) async { .then((_) async {
await windowManagerHelper.setBounds(bounds); await windowManagerHelper.setBounds(bounds);
if (isHidden) { if (isHidden) {
await windowManager.setSkipTaskbar(true);
} else { } else {
await windowManager.show(); await windowManager.show();
} }

View File

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

View File

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