-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
304 additions
and
95 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_desktop_tools/flutter_desktop_tools.dart'; | ||
import 'package:flutter_hooks/flutter_hooks.dart'; | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
import 'package:spotube/collections/intents.dart'; | ||
import 'package:spotube/provider/playlist_queue_provider.dart'; | ||
import 'package:spotube/provider/user_preferences_provider.dart'; | ||
|
||
void useInitSysTray(WidgetRef ref) { | ||
final context = useContext(); | ||
final systemTray = useRef<SystemTray?>(null); | ||
|
||
final initializeMenu = useCallback(() async { | ||
systemTray.value?.destroy(); | ||
final playlistQueue = ref.read(PlaylistQueueNotifier.notifier); | ||
final preferences = ref.read(userPreferencesProvider); | ||
if (!preferences.showSystemTrayIcon) { | ||
await systemTray.value?.destroy(); | ||
systemTray.value = null; | ||
return; | ||
} | ||
final enabled = | ||
playlistQueue.isLoaded && playlistQueue.state?.isLoading != true; | ||
systemTray.value = await DesktopTools.createSystemTrayMenu( | ||
title: "Spotube", | ||
iconPath: "assets/spotube-logo.png", | ||
windowsIconPath: "assets/spotube-logo.ico", | ||
items: [ | ||
MenuItemLabel( | ||
label: "Show/Hide", | ||
name: "show-hide", | ||
onClicked: (item) async { | ||
if (await DesktopTools.window.isVisible()) { | ||
await DesktopTools.window.hide(); | ||
} else { | ||
await DesktopTools.window.show(); | ||
} | ||
}, | ||
), | ||
MenuSeparator(), | ||
MenuItemLabel( | ||
label: "Play/Pause", | ||
name: "play-pause", | ||
enabled: enabled, | ||
onClicked: (_) async { | ||
Actions.maybeInvoke<PlayPauseIntent>( | ||
context, PlayPauseIntent(ref)) ?? | ||
PlayPauseAction().invoke(PlayPauseIntent(ref)); | ||
}, | ||
), | ||
MenuItemLabel( | ||
label: "Next", | ||
name: "next", | ||
enabled: enabled && (playlistQueue.state?.tracks.length ?? 0) > 1, | ||
onClicked: (p0) async { | ||
await playlistQueue.next(); | ||
}, | ||
), | ||
MenuItemLabel( | ||
label: "Previous", | ||
name: "previous", | ||
enabled: enabled && (playlistQueue.state?.tracks.length ?? 0) > 1, | ||
onClicked: (p0) async { | ||
await playlistQueue.previous(); | ||
}, | ||
), | ||
MenuSeparator(), | ||
MenuItemLabel( | ||
label: "Quit", | ||
name: "quit", | ||
onClicked: (item) async { | ||
await DesktopTools.window.close(); | ||
}, | ||
), | ||
], | ||
onEvent: (event, tray) async { | ||
if (DesktopTools.platform.isWindows) { | ||
switch (event) { | ||
case SystemTrayEvent.click: | ||
await DesktopTools.window.show(); | ||
break; | ||
case SystemTrayEvent.rightClick: | ||
await tray.popUpContextMenu(); | ||
break; | ||
default: | ||
} | ||
} else { | ||
switch (event) { | ||
case SystemTrayEvent.rightClick: | ||
await DesktopTools.window.show(); | ||
break; | ||
case SystemTrayEvent.click: | ||
await tray.popUpContextMenu(); | ||
break; | ||
default: | ||
} | ||
} | ||
}, | ||
); | ||
}, [ref]); | ||
|
||
useReassemble(initializeMenu); | ||
|
||
ref.listen<PlaylistQueue?>( | ||
PlaylistQueueNotifier.provider, | ||
(previous, next) { | ||
initializeMenu(); | ||
}, | ||
); | ||
ref.listen( | ||
userPreferencesProvider.select((s) => s.showSystemTrayIcon), | ||
(previous, next) { | ||
initializeMenu(); | ||
}, | ||
); | ||
|
||
useEffect(() { | ||
WidgetsBinding.instance.addPostFrameCallback((_) { | ||
initializeMenu(); | ||
}); | ||
return () async { | ||
await systemTray.value?.destroy(); | ||
}; | ||
}, [initializeMenu]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.