Repository navigation
feat: run app on background #793
Description
Activity

I am trying to implement this feature. How do you feel about using https://pub.dev/packages/tray_manager to provide support for the system tray functionality?@Feichtmeier
I am trying to implement this feature. How do you feel about using https://pub.dev/packages/tray_manager to provide support for the system tray functionality?@Feichtmeiercool! I feel good with it :)
The only bad thing is that I am still struck with my home grown weird settings service
I think I should first port it to shared_prefrences so you can use it to store your setting?Yes, I saw that you mentioned in another issue that you are migrating persistence to shared_preferences.
However, in the current architecture, saving the default behavior of the close button is easy. I have already done most of the work on the current code. I will commit all the code to GitHub later.
Reacted by Frederik FeichtmeierYes, I saw that you mentioned in another issue that you are migrating persistence to shared_preferences.
However, in the current architecture, saving the default behavior of the close button is easy. I have already done most of the work on the current code. I will commit all the code to GitHub later.
ok :) Thank you for contributing
Yes, I saw that you mentioned in another issue that you are migrating persistence to shared_preferences.
However, in the current architecture, saving the default behavior of the close button is easy. I have already done most of the work on the current code. I will commit all the code to GitHub later.ok :) Thank you for contributing
enum CloseBtnAction { none('always ask'), hide('hide to tray'), close('close'); final String description; const CloseBtnAction(this.description); @override String toString() => name; }
class _CloseActionSection extends StatelessWidget with WatchItMixin { const _CloseActionSection(); @override Widget build(BuildContext context) { final model = di<SettingsModel>(); final closeBtnAction = watchPropertyValue((SettingsModel m) => m.closeBtnActionIndex); return YaruSection( margin: const EdgeInsets.only( left: kYaruPagePadding, top: kYaruPagePadding, right: kYaruPagePadding, ), headline: Text(context.l10n.closeButtonAction), child: Column( children: [ YaruTile( title: Text(context.l10n.closeButtonAction), trailing: YaruPopupMenuButton<CloseBtnAction>( icon: const DropDownArrow(), initialValue: closeBtnAction, child: Text(closeBtnAction.description), onSelected: (value) { model.setCloseBtnActionIndex(value); }, itemBuilder: (context) { return [ for (var i = 0; i < CloseBtnAction.values.length; ++i) PopupMenuItem( value: CloseBtnAction.values[i], child: Text(CloseBtnAction.values[i].description), ), ]; }, ), ), ], ), ); } }
It seems impossible to implement i18n in enum. Do you have any good suggestions?
enum CloseBtnAction { none('always ask'), hide('hide to tray'), close('close'); final String description; const CloseBtnAction(this.description); @override String toString() => name; }
yes, do it like this
enum CloseBtnAction { alwaysAsk, hideToTray, close; String localize(AppLocalizations l10n) => switch (this) { alwaysAsk => l10n.alwaysAsk, // <- create this in the english and (chinese?) arb files hideToTray => l10n.hideToTray, // <- create this in the english and (chinese?) arb files close => l10n.close, }; }
you can regen the arb files either from this button in vscode

or from the command "Flutter: Generate Localizations" in the command prompt in vscode@dongfengweixiao it works in the snap :)
However for Linux snap and flatpak we need to set the icon differently
- added 2 commits that reference this issue
on Aug 22, 2024 damn this also didnt help @dongfengweixiao
any idea to make the icon show for snaps and flatpaks?let me look...
musicpod/lib/app/view/system_tray.dart
Lines 31 to 39 in fd2d6da
String _icon() { if (Platform.isLinux) { return kAppId; } else if (Platform.isWindows) { return 'assets/images/tray_icon.ico'; } else { return 'assets/images/tray_icon.png'; } } The existing code causes MusicPod to not display the tray icon on Arch Linux. It may be necessary to determine whether the current program is running in a sandbox environment.
However, I have not yet verified whether this part of the code works effectively in a flatpak or snap environment.
bool isFlatpakEnv() { return File('/.flatpak-info').existsSync(); } String _icon() { if (isFlatpakEnv() || Platform.environment.containsKey('SNAP_NAME')) { return kAppId; } else if (Platform.isWindows) { return 'assets/images/tray_icon.ico'; } else { return 'assets/images/tray_icon.png'; } }
musicpod/.github/workflows/release.yml
Line 99 in fd2d6da
# - run: sudo apt install -y clang cmake curl libgtk-3-dev ninja-build pkg-config unzip libunwind-dev libmpv-dev libappindicator3-1 libappindicator3-dev Like in
release.yml, maybe snap and flatpak need to add libayatana-appindicator3 as a runtime dependency and add libayatana-appindicator3-dev as a build-time dependency.
musicpod/lib/app/view/app.dart
Lines 104 to 110 in fd2d6da
@override void onWindowEvent(String eventName) { if ('show' == eventName || 'hide' == eventName) { updateTrayItems(context); } super.onWindowEvent(eventName); } Directly calling
updateTrayItemsin app.dart will cause a_TypeError (Null check operator used on a null value)error. However, in the release version of the application, this does not affect the functionality of the tray (although you cannot switch betweenhideordisplaystring only). I think I have found a way to solve this problem. I will separate the system tray implementation into a service, which will listen to the window state.However, these changes need to be completed next week. I'm going on a trip this weekend to visit one of the filming locations of "Black Myth: Wukong," Mount Wutai in Shanxi, China.
Reacted by Frederik Feichtmeier and Muhamad Bestagi RomadhonHey guys I rethought about this:
I spent quite some time on using the actual media trays on macos, linux and windows. So there is already a media tray for music players we already use.
It is confusing and doesnt have the same functionalities as the native media trays
Plus even if it would not be confusing, we didnt figure out the icon situation yetRunning the app in the background is a different thing but also has some edge cases we didnt thought about yet:
- on linux musicpod can be used to open music files from the filemanager, if the app is hidden to tray, this does not work
- we didnt test how this behaves on windows and macos yet at all
Until we didnt figure this all out I will remove this from main again
- changed the title
[-]Feature request: run app on background[/-][+]feat: run app on background[/+]on Apr 3, 2025
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsBacklog

Thanks for this awesome Apps, I use it every day!
But it will be great if this app can run in background when I click X button and show a little icon at corner of desktop system tray