Skip to content

config: add launched-from to specify launch source#7503

Merged
mitchellh merged 1 commit intomainfrom
push-yqxryqvkovmw
Jun 2, 2025
Merged

config: add launched-from to specify launch source#7503
mitchellh merged 1 commit intomainfrom
push-yqxryqvkovmw

Conversation

@mitchellh
Copy link
Copy Markdown
Contributor

Related to #7433

This extracts our "launched from desktop" logic into a config option. The default value is detection using the same logic as before, but now this can be overridden by the user.

This also adds the systemd and dbus activation sources from #7433.

There are a number of reasons why we decided to do this:

  1. It automatically gets us caching since the configuration is only loaded once (per reload, a rare occurrence).

  2. It allows us to override the logic when testing. Previously, we had to do more complex environment faking to get the same behavior.

  3. It forces exhaustive switches in any desktop handling code, which will make it easier to ensure valid behaviors if we introduce new launch sources (as we are in linux: add dbus and systemd activation services #7433).

  4. It lowers code complexity since callsites don't need to have N launchedFromX() checks and can use a single value.

Related to #7433

This extracts our "launched from desktop" logic into a config option.
The default value is detection using the same logic as before, but now
this can be overridden by the user.

This also adds the systemd and dbus activation sources from #7433.

There are a number of reasons why we decided to do this:

  1. It automatically gets us caching since the configuration is only
     loaded once (per reload, a rare occurrence).

  2. It allows us to override the logic when testing. Previously, we
     had to do more complex environment faking to get the same
     behavior.

  3. It forces exhaustive switches in any desktop handling code, which
     will make it easier to ensure valid behaviors if we introduce new
     launch sources (as we are in #7433).

  4. It lowers code complexity since callsites don't need to have N
     `launchedFromX()` checks and can use a single value.
Comment thread src/os/locale.zig
// do this when the app is launched from the desktop because then
// we're in an app bundle and we are expected to read from our
// Bundle's preferred languages.
if (internal_os.launchedFromDesktop()) language: {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I could be wrong, but I spent some time dwelling on this and I don't think we needed this guard. If we launch from a non-desktop source, one of the prior language setting cases should match first. If they don't, we should probably still try this.

Copy link
Copy Markdown
Member

@jcollie jcollie left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

@pluiedev pluiedev left a comment

Choose a reason for hiding this comment

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

Looks great

Comment thread src/config/Config.zig
Comment on lines +3132 to +3134
if (self.@"launched-from" == null) {
self.@"launched-from" = .detect();
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I dunno how I feel about this... Maybe we should add a _launched_from variable that is always non-null? I just don't like seeing .? everywhere I guess

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I felt the same way and thought the same thing, but was worried that it'd be too easy to not know which one to check as a consumer (there being 2 sources of seeming truth). The ? is optimized away in unsafe builds and I think the safety it affords in safe builds is fine.

@mitchellh mitchellh merged commit 70a3d9e into main Jun 2, 2025
73 of 74 checks passed
@mitchellh mitchellh deleted the push-yqxryqvkovmw branch June 2, 2025 16:07
@github-actions github-actions Bot added this to the 1.2.0 milestone Jun 2, 2025
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.

3 participants