Skip to content

feat: run app on background #793

Description

@bestagi

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

Activity

  1. dongfengweixiao commented on Jul 30, 2024

    @dongfengweixiao
    Contributor

    Snipaste_2024-07-30_10-58-46
    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

  2. Feichtmeier commented on Jul 30, 2024

    @Feichtmeier
    Member

    Snipaste_2024-07-30_10-58-46 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

    cool! 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?

  3. dongfengweixiao commented on Jul 30, 2024

    @dongfengweixiao
    Contributor

    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.

  4. Feichtmeier commented on Jul 30, 2024

    @Feichtmeier
    Member

    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

  5. dongfengweixiao commented on Jul 30, 2024

    @dongfengweixiao
    Contributor

    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?

  6. Feichtmeier commented on Jul 30, 2024

    @Feichtmeier
    Member
    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
    grafik
    or from the command "Flutter: Generate Localizations" in the command prompt in vscode

  7. Feichtmeier commented on Aug 22, 2024

    @Feichtmeier
    Member

    @dongfengweixiao it works in the snap :)

    However for Linux snap and flatpak we need to set the icon differently

  8. Feichtmeier commented on Aug 22, 2024

    @Feichtmeier
    Member

    damn this also didnt help @dongfengweixiao
    any idea to make the icon show for snaps and flatpaks?

  9. dongfengweixiao commented on Aug 22, 2024

    @dongfengweixiao
    Contributor

    let me look...

  10. dongfengweixiao commented on Aug 23, 2024

    @dongfengweixiao
    Contributor

    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';
      }
    }

    # - 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.


    @override
    void onWindowEvent(String eventName) {
    if ('show' == eventName || 'hide' == eventName) {
    updateTrayItems(context);
    }
    super.onWindowEvent(eventName);
    }

    Directly calling updateTrayItems in 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 between hide or display string 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.

  11. Feichtmeier commented on Aug 25, 2024

    @Feichtmeier
    Member

    Hey 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 yet

    Running 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

  12. changed the title [-]Feature request: run app on background[/-] [+]feat: run app on background[/+] on Apr 3, 2025
  13. added theissue type on May 16, 2025
  14. changed the issue type fromtoon May 16, 2025
  15. moved this to Backlog in MusicPodon May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Projects

  • Status
    Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions