Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions plugins/app/src/main/services/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { shell } from "electron"
import { nanoid } from "nanoid"
import { shellEnv } from "shell-env"

import { Service } from "@zenbujs/core/runtime"
import { DbService } from "@zenbujs/core/services"
Expand Down Expand Up @@ -291,6 +292,23 @@ type FlowController = {
pending: Deferred<string> | null
}

let shellEnvHydrated = false

async function hydrateShellEnv(): Promise<void> {
if (shellEnvHydrated || process.platform !== "darwin") return
shellEnvHydrated = true
try {
const env = await shellEnv()
process.env = {
...env,
...process.env,
PATH: env.PATH ?? process.env.PATH,
}
} catch (err) {
console.warn("[auth] shell env hydration failed:", err)
}
}

export class AuthService extends Service.create({
key: "auth",
deps: { db: DbService },
Expand All @@ -309,6 +327,8 @@ export class AuthService extends Service.create({
private flow: FlowController | null = null

async evaluate() {
await hydrateShellEnv()

// Surface any deferred errors pi's auth layer accumulated
// during boot (e.g. malformed `auth.json`). They go to the
// main-process console; the renderer surfaces "not configured"
Expand Down