Skip to content

a bunch of fixes#33

Merged
RainAfterDark merged 7 commits intomainfrom
fix/shell-and-tray
Mar 23, 2026
Merged

a bunch of fixes#33
RainAfterDark merged 7 commits intomainfrom
fix/shell-and-tray

Conversation

@RainAfterDark
Copy link
Copy Markdown
Collaborator

@RainAfterDark RainAfterDark commented Mar 22, 2026

Quick fixes for checking for interactive shell (when passing a command through nix develop --comand) for the dev shell (mentioned in #19) and the system tray failing to find the app icon from a raw path (fixed by passing a nativeImage type instead) (fixes #26).

@RainAfterDark
Copy link
Copy Markdown
Collaborator Author

marking as draft for now since there's still an asset loading issue

@RainAfterDark
Copy link
Copy Markdown
Collaborator Author

Took me a while to debug this only to find out that assets and transparent were mispelled this whole time, so I had to rename those files.

@RainAfterDark RainAfterDark marked this pull request as ready for review March 22, 2026 07:23
@RainAfterDark
Copy link
Copy Markdown
Collaborator Author

RainAfterDark commented Mar 22, 2026

Also I guess this only partially solves #26, there's still the problem of a more generalized autostart file solution for all targets. I'll see if I can come up with a better impl. There seems to be an electron API for this: (app.setLoginItemSettings(settings)), and I think only flatpak requires manually writing the config file such as mentioned in #14.

Edit: seems the electron login settings really only apply for win/macOS

- also add flatpak arg for system tray integration (StatusNotifier)
@RainAfterDark
Copy link
Copy Markdown
Collaborator Author

Alright, I think I ironed out all the wrinkles with the system tray. Icons should now properly load and flatpak required an additional permission for StatusNotifier. The generated autostart entries I've tested works in NixOS/flatpak as expected now. By default (if not on flatpak) I made it so that if linux-wallpaper-engine exists in the user's PATH, then it simply runs that. Would appreciate if it's tested to work on other platforms.

@jagrat7
Copy link
Copy Markdown
Owner

jagrat7 commented Mar 22, 2026

@claude review

@claude
Copy link
Copy Markdown

claude bot commented Mar 22, 2026

Claude finished @jagrat7's task in 3m 8s —— View job


PR Review: hotfix: interactive shell and tray

  • Gather context and understand request
  • Read changed files
  • Analyze code for bugs, issues, and improvements
  • Post review feedback

Overall this is a solid set of fixes — typo corrections, proper nativeImage usage for the tray, and a well-structured autostart service. A few issues worth addressing before merge:


src/main/main.tsresolveAssetPath logic bug

The control flow here has a subtle but significant problem for the Nix case:

const resolveAssetPath = (assetName: string): string => {
  // If packaged normally in forge-maker
  if (app.isPackaged)                                    // ← catches Nix too!
    return path.join(process.resourcesPath, 'assets', assetName)

  // If packaged with Nix...
  const appPath = app.getAppPath()
  if (appPath.includes('app.asar'))                      // ← unreachable for Nix
    return path.join(path.dirname(appPath), 'assets', assetName)
  ...
}

In the Nix package, makeWrapper calls Electron with --add-flags "$out/share/${pname}/app.asar". This means:

  • app.isPackaged is true (Electron detects it's loading from an asar)
  • process.resourcesPath points to Electron's own libexec/electron/resourcesnot $out/share/${pname}
  • The Nix-specific second block is never reached

The fix should check process.resourcesPath vs path.dirname(app.getAppPath()) to distinguish the two cases, or restructure the logic so Nix doesn't fall into the first branch. Something like:

if (app.isPackaged) {
  const appPath = app.getAppPath()
  // Nix: app.asar is passed directly as an arg, resources are co-located
  if (appPath.includes('app.asar') && path.dirname(appPath) !== process.resourcesPath)
    return path.join(path.dirname(appPath), 'assets', assetName)
  // Normal forge build
  return path.join(process.resourcesPath, 'assets', assetName)
}

Worth confirming whether the icon actually loads correctly from a Nix-built binary (not just dev mode). Fix this →


src/main/services/autostart.ts — Missing error handling

All file system operations (fs.mkdirSync, fs.writeFileSync, fs.unlinkSync) can throw on permission errors. A try-catch should wrap the write/delete operations to avoid crashing the app if the autostart dir is unwritable:

try {
  fs.writeFileSync(desktopFile, content.join('\n') + '\n')
} catch (err) {
  console.error('Failed to write autostart entry:', err)
}

Also note the desktop file content is missing a trailing newline (content.join('\n')content.join('\n') + '\n'). Not a functional issue but follows XDG convention.

src/main/services/autostart.tsFLATPAK_ID could be undefined

Line 27 and 81 use process.env.FLATPAK_ID unguarded:

return `flatpak run ${process.env.FLATPAK_ID}`;  // could produce "flatpak run undefined"

Worth adding a fallback: process.env.FLATPAK_ID ?? '' or guard with a check.

src/main/services/autostart.tssetAutostart called on every partial save

In settings.ts:27, setAutostart(settings.launchOnLogin) is called whenever any setting is saved. If launchOnLogin is not part of the partial update, it will be undefined and the function returns early — correct behavior. But if someone saves only e.g. { fps: 30 }, we write the desktop file again unnecessarily if launchOnLogin happens to be in the object. Minor, but worth being aware of.


Positives

  • shell.nix fix ($- == *i*): This is exactly the right way to detect interactive mode in bash. Clean fix.
  • nativeImage for tray: Correct approach — passing a raw path to Tray is unreliable across platforms; nativeImage is the proper API.
  • Autostart service extraction: Good separation of concerns. The exec command resolution (flatpak → PATH → electron → raw) is comprehensive and well thought out.
  • Flatpak --talk-name=org.kde.StatusNotifierWatcher: Needed for KDE tray support in sandboxed environments.
  • cp -a out/*/resources/. in package.nix: Correctly includes the full resources directory (including assets) rather than just the asar.
  • Typo fixes across all asset paths: Long overdue.

Copy link
Copy Markdown
Owner

@jagrat7 jagrat7 left a comment

Choose a reason for hiding this comment

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

I was able to get it to work as expected with the deb package. Have a look at the some of the syntax fixes claude recommended (some of them seem like bs) and merge it in when ready

@jaxiiruff
Copy link
Copy Markdown

jaxiiruff commented Mar 22, 2026

This is working very nicely good stuff @RainAfterDark I will leave #26 open until this is merged with a new release.

- refactor: only update autostart entry when necessary (setting mutation)
- guards on fs calls and getting process env vars
@RainAfterDark
Copy link
Copy Markdown
Collaborator Author

I resolved a couple of these:

src/main/services/autostart.ts — Missing error handling

src/main/services/autostart.ts — FLATPAK_ID could be undefined

src/main/services/autostart.ts — setAutostart called on every partial save

but this

src/main/main.ts — resolveAssetPath logic bug

isn't really a logic bug, running electron and passing the app.asar archive doesn't set the app.isPackaged flag to true from testing.

also while I was at it, I think I finally resolved the missing flatpak icon, it now shows up in warehouse:

image

@RainAfterDark RainAfterDark changed the title hotfix: interactive shell and tray a bunch of fixes Mar 23, 2026
@RainAfterDark
Copy link
Copy Markdown
Collaborator Author

just adding to mention that this should now completely resolve #26 and #11, I'll go ahead and merge

@RainAfterDark RainAfterDark linked an issue Mar 23, 2026 that may be closed by this pull request
@RainAfterDark RainAfterDark merged commit 9d0ebbc into main Mar 23, 2026
@RainAfterDark RainAfterDark mentioned this pull request Mar 23, 2026
@jagrat7 jagrat7 deleted the fix/shell-and-tray branch March 26, 2026 00:38
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.

Autostart & Tray issues on NixOS / Flatpak flatpak app icon

3 participants