feat(P3.T3): app:hostname IPC for device-name default
This commit is contained in:
@@ -114,6 +114,11 @@ export const CHANNELS = {
|
|||||||
// timeout, whichever comes first).
|
// timeout, whichever comes first).
|
||||||
/** Main → renderer: about to quit. Renderer wipes, then resolves. */
|
/** Main → renderer: about to quit. Renderer wipes, then resolves. */
|
||||||
APP_WIPE_BEFORE_QUIT: 'app:wipe-before-quit',
|
APP_WIPE_BEFORE_QUIT: 'app:wipe-before-quit',
|
||||||
|
|
||||||
|
// OS hostname — returns the machine hostname via Node's `os.hostname()`.
|
||||||
|
// Used by AuthContext on first launch to populate the `devices` row with
|
||||||
|
// a human-readable default device name. Returns null on failure.
|
||||||
|
APP_HOSTNAME: 'app:hostname',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
// ---- Screen sources ------------------------------------------------------
|
// ---- Screen sources ------------------------------------------------------
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { fileURLToPath } from 'node:url';
|
|||||||
|
|
||||||
import { CHANNELS } from './ipc-types';
|
import { CHANNELS } from './ipc-types';
|
||||||
import { register as registerAudioLoopback } from './modules/audio-loopback';
|
import { register as registerAudioLoopback } from './modules/audio-loopback';
|
||||||
|
import { register as registerAppHostname } from './modules/app-hostname';
|
||||||
import { register as registerAutostart } from './modules/autostart';
|
import { register as registerAutostart } from './modules/autostart';
|
||||||
import { register as registerFsScoped } from './modules/fs-scoped';
|
import { register as registerFsScoped } from './modules/fs-scoped';
|
||||||
import { register as registerNotifications } from './modules/notifications';
|
import { register as registerNotifications } from './modules/notifications';
|
||||||
@@ -254,6 +255,7 @@ if (!gotLock) {
|
|||||||
registerFsScoped();
|
registerFsScoped();
|
||||||
registerSql();
|
registerSql();
|
||||||
registerAutostart();
|
registerAutostart();
|
||||||
|
registerAppHostname();
|
||||||
|
|
||||||
// Window-dependent registrars — only call once mainWindow exists so
|
// Window-dependent registrars — only call once mainWindow exists so
|
||||||
// event emitters have somewhere to send.
|
// event emitters have somewhere to send.
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
// app:hostname adapter — returns the OS hostname via Node's `os.hostname()`.
|
||||||
|
// The renderer has no Node access (contextIsolation is ON), so it must ask
|
||||||
|
// main for this value. Used by AuthContext on first launch to populate the
|
||||||
|
// `devices` row with a human-readable default device name.
|
||||||
|
|
||||||
|
import os from 'node:os';
|
||||||
|
|
||||||
|
import { ipcMain } from 'electron';
|
||||||
|
|
||||||
|
import { CHANNELS } from '../ipc-types';
|
||||||
|
|
||||||
|
export function register(): void {
|
||||||
|
ipcMain.handle(CHANNELS.APP_HOSTNAME, (): string | null => {
|
||||||
|
try {
|
||||||
|
const h = os.hostname();
|
||||||
|
return typeof h === 'string' && h.length > 0 ? h : null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
+7
@@ -99,6 +99,13 @@ export interface ElectronAPI {
|
|||||||
/** Subscribe to the main-process pre-quit notification. Used by the
|
/** Subscribe to the main-process pre-quit notification. Used by the
|
||||||
* "Cache beim Schließen leeren" Settings toggle. */
|
* "Cache beim Schließen leeren" Settings toggle. */
|
||||||
onWipeBeforeQuit: (cb: () => Promise<void>) => () => void;
|
onWipeBeforeQuit: (cb: () => Promise<void>) => () => void;
|
||||||
|
|
||||||
|
/** Returns the OS hostname (via Node's `os.hostname()`). Used by
|
||||||
|
* AuthContext on first launch to populate the `devices` row with a
|
||||||
|
* human-readable default device name. Optional: always feature-check
|
||||||
|
* via `typeof window.electronAPI?.getHostname === 'function'` because
|
||||||
|
* the web build has no preload bridge. */
|
||||||
|
getHostname?: () => Promise<string | null>;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
@@ -160,6 +160,9 @@ const api = {
|
|||||||
setFullscreen: (enabled: boolean): Promise<void> =>
|
setFullscreen: (enabled: boolean): Promise<void> =>
|
||||||
ipcRenderer.invoke(CHANNELS.WINDOW_SET_FULLSCREEN, enabled),
|
ipcRenderer.invoke(CHANNELS.WINDOW_SET_FULLSCREEN, enabled),
|
||||||
|
|
||||||
|
// OS hostname ------------------------------------------------------------
|
||||||
|
getHostname: (): Promise<string | null> => ipcRenderer.invoke(CHANNELS.APP_HOSTNAME),
|
||||||
|
|
||||||
// Wipe-on-close ----------------------------------------------------------
|
// Wipe-on-close ----------------------------------------------------------
|
||||||
// Subscribe to the main-process pre-quit notification. The renderer's
|
// Subscribe to the main-process pre-quit notification. The renderer's
|
||||||
// callback does the actual wipe (memoryWipe.ts) and resolves; we ack
|
// callback does the actual wipe (memoryWipe.ts) and resolves; we ack
|
||||||
|
|||||||
Reference in New Issue
Block a user