dispose resources on app close (prevents audio glitch)
This commit is contained in:
parent
cb05247b5d
commit
6e220073d8
|
@ -10,7 +10,8 @@ import 'package:window_manager/window_manager.dart';
|
|||
|
||||
final sysTray = SysTray._();
|
||||
|
||||
class SysTray with TrayListener {
|
||||
/// Handles system tray and window events
|
||||
class SysTray with TrayListener, WindowListener {
|
||||
SysTray._();
|
||||
|
||||
static String getIcon({bool forcePng = false}) {
|
||||
|
@ -33,6 +34,8 @@ class SysTray with TrayListener {
|
|||
if (_inited) return;
|
||||
_inited = true;
|
||||
|
||||
windowManager.addListener(this);
|
||||
|
||||
updateIcon();
|
||||
try {
|
||||
await trayManager.setToolTip('freezer');
|
||||
|
@ -65,22 +68,19 @@ class SysTray with TrayListener {
|
|||
MenuItem.separator(),
|
||||
MenuItem(
|
||||
label: 'Previous'.i18n,
|
||||
onClick: (menuItem) => audioHandler.skipToPrevious()),
|
||||
onClick: (_) => audioHandler.skipToPrevious()),
|
||||
playing
|
||||
? MenuItem(
|
||||
label: 'Pause'.i18n, onClick: (menuItem) => audioHandler.pause())
|
||||
: MenuItem(
|
||||
label: 'Play'.i18n, onClick: (menuItem) => audioHandler.play()),
|
||||
MenuItem(
|
||||
label: 'Next'.i18n, onClick: (menuItem) => audioHandler.skipToNext()),
|
||||
? MenuItem(label: 'Pause'.i18n, onClick: (_) => audioHandler.pause())
|
||||
: MenuItem(label: 'Play'.i18n, onClick: (_) => audioHandler.play()),
|
||||
MenuItem(label: 'Next'.i18n, onClick: (_) => audioHandler.skipToNext()),
|
||||
MenuItem.separator(),
|
||||
MenuItem(
|
||||
label: 'Show'.i18n,
|
||||
// we can safely ignore it if it errors, as it's expected
|
||||
onClick: (menuItem) => windowManager.show().catchError((e) {})),
|
||||
onClick: (_) => windowManager.show().catchError((e) {})),
|
||||
MenuItem(
|
||||
label: 'Exit'.i18n,
|
||||
onClick: (menuItem) async {
|
||||
onClick: (_) async {
|
||||
await audioHandler.pause();
|
||||
SystemNavigator.pop();
|
||||
},
|
||||
|
@ -103,5 +103,8 @@ class SysTray with TrayListener {
|
|||
void onTrayIconRightMouseUp() => trayManager.popUpContextMenu();
|
||||
|
||||
@override
|
||||
void onTrayMenuItemClick(MenuItem menuItem) {}
|
||||
void onWindowClose() {
|
||||
// release resources before closing
|
||||
audioHandler.stop();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue