Skip to content

Conversation

@Zinkelburger
Copy link
Contributor

@Zinkelburger Zinkelburger commented Oct 11, 2025

Issue: closes #1652 #1517

Requirements

  • Filling out the template is required. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
  • issue was opened to discuss proposed changes before starting implementation. It is important do discuss changes before implementing them (Why should we add it? How should it work? How should it look? Where will it be? ...).
  • during development, node version specified in package.json was used (ie using nvm).
  • package versions and package-lock.json were not changed (npm install --no-save).
  • app version number was not changed.
  • all new code has tests to ensure against regressions.
  • npm run lint reports no offenses.
  • npm run test is error-free.
  • README and CHANGELOG were updated accordingly.
  • after PR is approved, all commits in it are squashed

Description of the Change

  1. Add Flatpak detection to AutoStart manager
  2. Changed AutoStart manager to async because d-bus methods are async
  3. Follow docs at doc-org.freedesktop.portal.Background for options field in setAutostart
  4. Get background status by checking for ~/.config/autostart/net.hovancik.Stretchly.desktop. Requires a PR to the flatpak repo. add autostart:ro permission flathub/net.hovancik.Stretchly#23

Verification Process

I was on Fedora 42.
I build the flatpak and ran it as described in net.hovancik.Stretchly

I checked the checkbox to "run at startup", and saw that a file was made in autostart, as expected.

cat ~/.config/autostart/net.hovancik.Stretchly.desktop    
[Desktop Entry]  
Type=Application  
Name=net.hovancik.Stretchly  
X-XDP-Autostart=net.hovancik.Stretchly  
Exec=flatpak run net.hovancik.Stretchly  
X-Flatpak=net.hovancik.Stretchly

When I unchecked the checkbox, the file no longer existed. Perfect.
When I checked the checkbox and rebooted my computer, stretchly opened on startup.

I fixed the error I spoke of previously

Log:

12:07:48.985 › Stretchly: setting autostart to true on linux (Flatpak)
12:07:48.991 › Stretchly: RequestBackground called for autostart=true, request path: /org/freedesktop/portal/desktop/request/1_266/stretchly_autostart_1760198868989_s3uwx
12:07:48.991 › Stretchly: Portal Response signal received - response: 0, results: {
  background: { signature: 'b', value: true },
  autostart: { signature: 'b', value: true }
}
12:07:48.993 › Stretchly: Autostart successfully enabled via XDG Portal.
12:07:49.951 › Stretchly: setting autostart to false on linux (Flatpak)
12:07:49.958 › Stretchly: Autostart disabled via XDG Portal (no response expected).
12:07:50.582 › Stretchly: setting autostart to true on linux (Flatpak)
12:07:50.590 › Stretchly: RequestBackground called for autostart=true, request path: /org/freedesktop/portal/desktop/request/1_266/stretchly_autostart_1760198870587_qae8dg
12:07:50.590 › Stretchly: Portal Response signal received - response: 0, results: {
  background: { signature: 'b', value: true },
  autostart: { signature: 'b', value: true }
}
12:07:50.591 › Stretchly: Autostart successfully enabled via XDG Portal.

@hovancik
Copy link
Owner

Is this WIP or should be finished? With regard to the PR in flathub, if any changes are expected

@Zinkelburger
Copy link
Contributor Author

That's a good point, the flathub PR is definitely wrong, that permission is not allowed.

I'll rethink how to do this, I had a lot of errors trying to get the current status, and reading "autostart" was a good workaround.

@Zinkelburger Zinkelburger marked this pull request as draft October 15, 2025 17:28
@hovancik
Copy link
Owner

Ok :)

@Zinkelburger Zinkelburger marked this pull request as ready for review October 20, 2025 20:24
@Zinkelburger
Copy link
Contributor Author

There were issues with the portal not initializing sometimes, so I moved it to main, hope that's ok.

Otherwise its pretty much the last PR + save autostart value to settings. Saving to settings is kinda buggy if the user manually deletes the file, but they're asking for trouble in that case!

@codecov
Copy link

codecov bot commented Oct 25, 2025

Codecov Report

❌ Patch coverage is 0% with 96 lines in your changes missing coverage. Please review.
✅ Project coverage is 14.45%. Comparing base (1045efc) to head (3694482).
⚠️ Report is 18 commits behind head on trunk.

Files with missing lines Patch % Lines
app/utils/flatpakPortalManager.js 0.00% 72 Missing ⚠️
app/utils/autostartManager.js 0.00% 18 Missing ⚠️
app/main.js 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #1670      +/-   ##
==========================================
- Coverage   14.92%   14.45%   -0.47%     
==========================================
  Files          35       36       +1     
  Lines        1963     2075     +112     
==========================================
+ Hits          293      300       +7     
- Misses       1670     1775     +105     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Zinkelburger Zinkelburger force-pushed the autostart_flatpak branch 2 times, most recently from a320161 to ca94739 Compare November 6, 2025 22:00
@Zinkelburger
Copy link
Contributor Author

Please note I have an issue running the flatpak with no flags on stretchly 1.19.0. I think there were some changes to the dependencies.

anbernal@anbernal-thinkpadt14sgen2i:~$ flatpak run net.hovancik.Stretchly
WAYLAND_DISPLAY: wayland-0
XDG_RUNTIME_DIR: /run/user/4215325
app  bus  doc  flatpak-info  p11-kit  pulse
[4:1117/002546.213869:ERROR:dbus/bus.cc:408] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[4:1117/002546.958812:ERROR:ui/ozone/platform/wayland/host/wayland_connection.cc:202] Failed to connect to Wayland display: No such file or directory (2)
[4:1117/002546.958846:ERROR:ui/ozone/platform/wayland/ozone_platform_wayland.cc:282] Failed to initialize Wayland platform
[4:1117/002546.958870:ERROR:ui/aura/env.cc:257] The platform failed to initialize.  Exiting.
/app/bin/run.sh: line 14:     4 Segmentation fault      (core dumped) zypak-wrapper /app/main/stretchly $FLAGS "$@"

To get it to work I have to add the --ozone-platform=x11

anbernal@anbernal-thinkpadt14sgen2i:~$ flatpak run net.hovancik.Stretchly --ozone-platform=x11
WAYLAND_DISPLAY: wayland-0
XDG_RUNTIME_DIR: /run/user/4215325
app  bus  doc  flatpak-info  p11-kit  pulse
[4:1117/003950.727471:ERROR:dbus/bus.cc:408] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[4:1117/003952.056727:ERROR:dbus/bus.cc:408] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[4:1117/003952.056822:ERROR:dbus/bus.cc:408] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
00:39:52.089 › Stretchly: initializing...
00:39:52.129 › Stretchly: migrating preferences from Stretchly v1.18.1 to v1.18.2
00:39:52.144 › Stretchly: migrating preferences from Stretchly v1.18.2 to v1.19.0
00:39:52.145 › Stretchly: not migrating audio to longBreakAudio

I'm not an expert and its late at night. Claude suggests
"Electron 39 changed the default Ozone platform behavior. You used to need to explicitly set --enable-features=UseOzonePlatform --ozone-platform=wayland. The default is now auto, and it tries to use Wayland when
XDG_SESSION_TYPE=wayland. But the Flatpak sandbox doesn't have --socket=wayland permission, so the socket isn't accessible"

@hovancik
Copy link
Owner

Yeah, that is a change in Electron :( Are you on Ubuntu? looks like issue in #1693

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds autostart functionality for Flatpak packages by implementing a new FlatpakPortalManager that interacts with the XDG Desktop Portal D-Bus API. The changes enable Stretchly to properly handle autostart when running as a Flatpak, addressing issues #1652 and #1517.

Key changes:

  • Created a new FlatpakPortalManager class to handle autostart via XDG Background Portal
  • Modified AutostartManager to be async and detect Flatpak environments
  • Added cleanup for D-Bus connections on app quit

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
app/utils/flatpakPortalManager.js New manager implementing XDG Background Portal integration for Flatpak autostart control
app/utils/autostartManager.js Updated to detect Flatpak, delegate to FlatpakPortalManager, and support async operations
app/utils/defaultSettings.js Added flatpakAutostart setting to cache autostart state
app/main.js Added D-Bus connection cleanup on quit and early portal initialization for Flatpak
CHANGELOG.md Documented the new Flatpak autostart functionality

@hovancik
Copy link
Owner

Made some changes, but one question: this is supposed to be triggered from Preferences. But I do not see where we actually load the value into Preferences. Or am I missing something?

@Zinkelburger
Copy link
Contributor Author

Made some changes, but one question: this is supposed to be triggered from Preferences. But I do not see where we actually load the value into Preferences. Or am I missing something?

The value is loaded via the flatpakAutostart setting (since we must cache it locally; the portal doesn't support querying status).

It gets injected into the Preferences window in app/main.js via settingsToSend():

async function settingsToSend () { 
  return Object.assign({}, settings.store, { openAtLogin: await autostartManager.autoLaunchStatus() })
}

This maps our cached flatpakAutostart value (returned by autoLaunchStatus) to the openAtLogin property that the Preferences UI expects.

- Add _waitForBusResponse to make it easier to read `setAutostart`
- Copilot change for `portalRequestTimeoutMs`
- Copilot change for `endsWith` handle token

Signed-off-by: Andrew Bernal <[email protected]>
@hovancik
Copy link
Owner

hovancik commented Dec 6, 2025

looks like you deleted my changes :(

@hovancik hovancik merged commit 4cd799d into hovancik:trunk Dec 6, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature request]: Autostart for Flatpaks

2 participants