-
Notifications
You must be signed in to change notification settings - Fork 418
fix(linux): detect Secret Service via D-Bus to prevent basic_text fallback #1908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+32
−0
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
fix(linux): detect Secret Service via D-Bus to prevent basic_text fal…
…lback
- Loading branch information
commit 639aaf94b938e5e335cbf6e86dc8bea1c7f430ff
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| import { execFileSync } from 'node:child_process'; | ||
| import { join } from 'node:path'; | ||
| import { config as dotenvConfig } from 'dotenv'; | ||
| import { app, BrowserWindow, dialog, ipcMain } from 'electron'; | ||
| import dockIcon from '@/assets/images/emdash/icon-dock.png?asset'; | ||
| import { PRODUCT_NAME } from '@shared/app-identity'; | ||
| import { registerRPCRouter } from '@shared/ipc/rpc'; | ||
| import { setupApplicationMenu } from './app/menu'; | ||
| import { registerAppScheme, setupAppProtocol } from './app/protocol'; | ||
| import { createMainWindow } from './app/window'; | ||
| import { providerTokenRegistry } from './core/account/provider-token-registry'; | ||
| import { emdashAccountService } from './core/account/services/emdash-account-service'; | ||
| import { agentHookService } from './core/agent-hooks/agent-hook-service'; | ||
| import { appService } from './core/app/service'; | ||
| import { localDependencyManager } from './core/dependencies/dependency-manager'; | ||
| import { editorBufferService } from './core/editor/editor-buffer-service'; | ||
| import { gitWatcherRegistry } from './core/git/git-watcher-registry'; | ||
| import { githubConnectionService } from './core/github/services/github-connection-service'; | ||
| import { projectManager } from './core/projects/project-manager'; | ||
| import { prSyncScheduler } from './core/pull-requests/pr-sync-scheduler'; | ||
| import { searchService } from './core/search/search-service'; | ||
| import { appSettingsService } from './core/settings/settings-service'; | ||
| import { updateService } from './core/updates/update-service'; | ||
| import { initializeDatabase } from './db/initialize'; | ||
| import { log } from './lib/logger'; | ||
| import { telemetryService } from './lib/telemetry'; | ||
| import { rpcRouter } from './rpc'; | ||
| import { resolveUserEnv } from './utils/userEnv'; | ||
|
|
||
| if (import.meta.env.DEV) { | ||
| dotenvConfig({ path: '.env.local', override: false }); | ||
| } | ||
|
|
||
| function secretServiceAvailable(): boolean { | ||
| try { | ||
| const output = execFileSync('dbus-send', [ | ||
| '--session', | ||
| '--print-reply=literal', | ||
| '--dest=org.freedesktop.DBus', | ||
| '/org/freedesktop/DBus', | ||
| 'org.freedesktop.DBus.NameHasOwner', | ||
| 'string:org.freedesktop.secrets', | ||
| ]) | ||
| .toString() | ||
| .trim(); | ||
|
|
||
| return output.includes('true'); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| if (process.platform === 'linux') { | ||
| app.commandLine.appendSwitch('ozone-platform-hint', 'auto'); | ||
|
|
||
| // Chromium's XDG_CURRENT_DESKTOP detection doesn't recognise modern compositors | ||
| // (Hyprland, sway, i3, dwm, etc.) and falls back to basic_text. Probe D-Bus | ||
| // directly instead and guide Chromium to the correct backend when available. | ||
| const isKDE = process.env.XDG_CURRENT_DESKTOP?.toLowerCase().includes('kde'); | ||
| const userOverrode = process.argv.some((a) => a.startsWith('--password-store=')); | ||
|
|
||
| if (!isKDE && !userOverrode && secretServiceAvailable()) { | ||
| app.commandLine.appendSwitch('password-store', 'gnome-libsecret'); | ||
| } | ||
| } | ||
|
krit22 marked this conversation as resolved.
|
||
|
|
||
| registerAppScheme(); | ||
|
|
||
| app.setName(PRODUCT_NAME); | ||
| app.setPath('userData', join(app.getPath('appData'), 'emdash')); | ||
|
|
||
| app.on('second-instance', () => { | ||
| const win = BrowserWindow.getAllWindows()[0]; | ||
| if (win?.isMinimized()) win.restore(); | ||
| win?.focus(); | ||
| }); | ||
|
|
||
| if (!import.meta.env.DEV && !app.requestSingleInstanceLock()) { | ||
| app.quit(); | ||
| process.exit(0); | ||
| } | ||
|
|
||
| if (import.meta.env.DEV) { | ||
| try { | ||
| app.dock?.setIcon(dockIcon); | ||
| } catch (err) { | ||
| log.warn('Failed to set dock icon:', err); | ||
| } | ||
| } | ||
|
|
||
| app.on('window-all-closed', () => { | ||
| if (process.platform !== 'darwin') { | ||
| app.quit(); | ||
| } | ||
| }); | ||
|
|
||
| app.on('activate', () => { | ||
| if (BrowserWindow.getAllWindows().length === 0) { | ||
| createMainWindow(); | ||
| } | ||
| }); | ||
|
|
||
| void app.whenReady().then(async () => { | ||
| await resolveUserEnv(); | ||
|
|
||
| try { | ||
| await initializeDatabase(); | ||
| searchService.initialize(); | ||
| void editorBufferService.pruneStale(); | ||
| } catch (error) { | ||
| log.error('Failed to initialize database:', error); | ||
| dialog.showErrorBox( | ||
| 'Database Initialization Failed', | ||
| `${PRODUCT_NAME} could not start because the database failed to initialize.\n\n${error instanceof Error ? error.message : String(error)}` | ||
| ); | ||
| app.quit(); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| await telemetryService.initialize({ installSource: app.isPackaged ? 'dmg' : 'dev' }); | ||
| } catch (e) { | ||
| log.warn('telemetry init failed:', e); | ||
| } | ||
|
|
||
| emdashAccountService.on('accountChanged', (username, userId, email) => { | ||
| void telemetryService.identify(username, userId, email); | ||
| }); | ||
| emdashAccountService.on('accountCleared', () => { | ||
| telemetryService.clearIdentity(); | ||
| }); | ||
|
|
||
| gitWatcherRegistry.initialize(); | ||
| prSyncScheduler.initialize(); | ||
| appService.initialize(); | ||
| await appSettingsService.initialize(); | ||
|
|
||
| agentHookService.initialize().catch((e) => { | ||
| log.error('Failed to start agent event service:', e); | ||
| }); | ||
|
|
||
| emdashAccountService.loadSessionToken().catch((e) => { | ||
| log.warn('Failed to load account session token:', e); | ||
| }); | ||
|
|
||
| providerTokenRegistry.register('github', (token) => githubConnectionService.storeToken(token)); | ||
|
|
||
| registerRPCRouter(rpcRouter, ipcMain); | ||
|
|
||
| localDependencyManager.probeAll().catch((e) => { | ||
| log.error('Failed to probe dependencies:', e); | ||
| }); | ||
|
|
||
| setupAppProtocol(join(app.getAppPath(), 'out', 'renderer')); | ||
| setupApplicationMenu(); | ||
| createMainWindow(); | ||
|
|
||
| try { | ||
| await updateService.initialize(); | ||
| } catch (error) { | ||
| if (app.isPackaged) { | ||
| log.error('Failed to initialize auto-update service:', error); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| app.on('before-quit', (event) => { | ||
| event.preventDefault(); | ||
| telemetryService.capture('app_closed'); | ||
| void telemetryService.dispose().finally(() => { | ||
| agentHookService.dispose(); | ||
| updateService.dispose(); | ||
| prSyncScheduler.dispose(); | ||
| void gitWatcherRegistry.dispose(); | ||
| void projectManager.dispose().catch((e) => { | ||
| log.error('Failed to shutdown project manager:', e); | ||
| }); | ||
| app.exit(0); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.