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._();
|
final sysTray = SysTray._();
|
||||||
|
|
||||||
class SysTray with TrayListener {
|
/// Handles system tray and window events
|
||||||
|
class SysTray with TrayListener, WindowListener {
|
||||||
SysTray._();
|
SysTray._();
|
||||||
|
|
||||||
static String getIcon({bool forcePng = false}) {
|
static String getIcon({bool forcePng = false}) {
|
||||||
|
|
@ -33,6 +34,8 @@ class SysTray with TrayListener {
|
||||||
if (_inited) return;
|
if (_inited) return;
|
||||||
_inited = true;
|
_inited = true;
|
||||||
|
|
||||||
|
windowManager.addListener(this);
|
||||||
|
|
||||||
updateIcon();
|
updateIcon();
|
||||||
try {
|
try {
|
||||||
await trayManager.setToolTip('freezer');
|
await trayManager.setToolTip('freezer');
|
||||||
|
|
@ -65,22 +68,19 @@ class SysTray with TrayListener {
|
||||||
MenuItem.separator(),
|
MenuItem.separator(),
|
||||||
MenuItem(
|
MenuItem(
|
||||||
label: 'Previous'.i18n,
|
label: 'Previous'.i18n,
|
||||||
onClick: (menuItem) => audioHandler.skipToPrevious()),
|
onClick: (_) => audioHandler.skipToPrevious()),
|
||||||
playing
|
playing
|
||||||
? MenuItem(
|
? MenuItem(label: 'Pause'.i18n, onClick: (_) => audioHandler.pause())
|
||||||
label: 'Pause'.i18n, onClick: (menuItem) => audioHandler.pause())
|
: MenuItem(label: 'Play'.i18n, onClick: (_) => audioHandler.play()),
|
||||||
: MenuItem(
|
MenuItem(label: 'Next'.i18n, onClick: (_) => audioHandler.skipToNext()),
|
||||||
label: 'Play'.i18n, onClick: (menuItem) => audioHandler.play()),
|
|
||||||
MenuItem(
|
|
||||||
label: 'Next'.i18n, onClick: (menuItem) => audioHandler.skipToNext()),
|
|
||||||
MenuItem.separator(),
|
MenuItem.separator(),
|
||||||
MenuItem(
|
MenuItem(
|
||||||
label: 'Show'.i18n,
|
label: 'Show'.i18n,
|
||||||
// we can safely ignore it if it errors, as it's expected
|
// we can safely ignore it if it errors, as it's expected
|
||||||
onClick: (menuItem) => windowManager.show().catchError((e) {})),
|
onClick: (_) => windowManager.show().catchError((e) {})),
|
||||||
MenuItem(
|
MenuItem(
|
||||||
label: 'Exit'.i18n,
|
label: 'Exit'.i18n,
|
||||||
onClick: (menuItem) async {
|
onClick: (_) async {
|
||||||
await audioHandler.pause();
|
await audioHandler.pause();
|
||||||
SystemNavigator.pop();
|
SystemNavigator.pop();
|
||||||
},
|
},
|
||||||
|
|
@ -103,5 +103,8 @@ class SysTray with TrayListener {
|
||||||
void onTrayIconRightMouseUp() => trayManager.popUpContextMenu();
|
void onTrayIconRightMouseUp() => trayManager.popUpContextMenu();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onTrayMenuItemClick(MenuItem menuItem) {}
|
void onWindowClose() {
|
||||||
|
// release resources before closing
|
||||||
|
audioHandler.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue