-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suite-desktop): open system settings using desktopApi
- Loading branch information
1 parent
7413e2c
commit 1077075
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
55 changes: 55 additions & 0 deletions
55
packages/suite-desktop-core/src/modules/system-settings.ts
This file contains 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,55 @@ | ||
import { exec } from 'child_process'; | ||
|
||
import { isLinux, isMacOs, isWindows } from '@trezor/env-utils'; | ||
|
||
import { ipcMain } from '../typed-electron'; | ||
|
||
import type { ModuleInit } from './index'; | ||
|
||
export const SERVICE_NAME = 'system-settings'; | ||
|
||
const openSettings = (cmd: string, env?: Record<string, string>) => | ||
new Promise<any>(resolve => { | ||
exec(cmd, { env: { ...process.env, ...env } }, error => { | ||
if (error) { | ||
resolve({ success: false, error } as const); | ||
} else { | ||
resolve({ success: true } as const); | ||
} | ||
}); | ||
}); | ||
|
||
const openBluetoothSettings = () => { | ||
if (isLinux()) { | ||
// https://github.com/electron/electron/blob/ab2a4fd836d539194bc5cde5f0d665eddeb6a134/docs/api/environment-variables.md?plain=1#L190 | ||
// Electron modifies the value of XDG_CURRENT_DESKTOP | ||
const xdg = process.env.ORIGINAL_XDG_CURRENT_DESKTOP || process.env.XDG_CURRENT_DESKTOP; | ||
if (xdg?.includes('GNOME')) { | ||
return openSettings('gnome-control-center bluetooth', { | ||
XDG_CURRENT_DESKTOP: xdg, | ||
}); | ||
} else if (xdg?.includes('KDE')) { | ||
return openSettings('systemsettings5', { | ||
XDG_CURRENT_DESKTOP: xdg, | ||
}); | ||
} | ||
} | ||
if (isMacOs()) { | ||
return openSettings('open "x-apple.systempreferences:com.apple.Bluetooth"'); | ||
} | ||
if (isWindows()) { | ||
return openSettings('start ms-settings:bluetooth'); | ||
} | ||
|
||
return { success: false, error: 'Unsupported os' }; | ||
}; | ||
|
||
export const init: ModuleInit = () => { | ||
ipcMain.handle('system/open-settings', (_, settings) => { | ||
if (settings === 'bluetooth') { | ||
return openBluetoothSettings(); | ||
} | ||
|
||
return { success: false, error: `Unknown settings: ${settings}` }; | ||
}); | ||
}; |