完善客户端模块与工作区能力
This commit is contained in:
29
electron/main/admin-access.ts
Normal file
29
electron/main/admin-access.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { timingSafeEqual } from 'node:crypto';
|
||||
|
||||
const ADMIN_PASSWORD = 'zhiniankeji666';
|
||||
|
||||
let adminSessionUnlocked = false;
|
||||
|
||||
function matchesAdminPassword(password: unknown): boolean {
|
||||
if (typeof password !== 'string') return false;
|
||||
|
||||
const received = Buffer.from(password, 'utf8');
|
||||
const expected = Buffer.from(ADMIN_PASSWORD, 'utf8');
|
||||
return received.length === expected.length && timingSafeEqual(received, expected);
|
||||
}
|
||||
|
||||
export function verifyAdminPassword(password: unknown): boolean {
|
||||
const valid = matchesAdminPassword(password);
|
||||
if (valid) {
|
||||
adminSessionUnlocked = true;
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
export function isAdminSessionUnlocked(): boolean {
|
||||
return adminSessionUnlocked;
|
||||
}
|
||||
|
||||
export function lockAdminSession(): void {
|
||||
adminSessionUnlocked = false;
|
||||
}
|
||||
@@ -258,7 +258,11 @@ function createWindow(): BrowserWindow {
|
||||
sandbox: false,
|
||||
webviewTag: false,
|
||||
},
|
||||
titleBarStyle: isMac ? 'hiddenInset' : useCustomTitleBar ? 'hidden' : 'default',
|
||||
// `hiddenInset` leaves a native top inset in the renderer viewport. That
|
||||
// makes a full-height Canvas look like it has an extra horizontal bar and
|
||||
// clips the top of the columns. `hidden` keeps the traffic lights while
|
||||
// giving the renderer the full window bounds.
|
||||
titleBarStyle: isMac ? 'hidden' : useCustomTitleBar ? 'hidden' : 'default',
|
||||
// Keep the native traffic lights on the same centerline as the 40px
|
||||
// renderer title bar. The native glyphs sit about 7px below the
|
||||
// configured origin, so y=13 centers them on the renderer controls.
|
||||
|
||||
@@ -13,6 +13,11 @@ import { getProviderService } from '../services/providers/provider-service';
|
||||
import type { ProviderConfig } from '../utils/secure-storage';
|
||||
import type { ProviderAccount } from '../shared/providers/types';
|
||||
import { validateApiKeyWithProvider } from '../services/providers/provider-validation';
|
||||
import {
|
||||
isAdminSessionUnlocked,
|
||||
lockAdminSession,
|
||||
verifyAdminPassword,
|
||||
} from './admin-access';
|
||||
|
||||
type UnifiedRequest = {
|
||||
id?: string;
|
||||
@@ -282,6 +287,15 @@ export function registerIpcHandlers(
|
||||
return { success: true, settings: await getAllSettings() };
|
||||
});
|
||||
|
||||
ipcMain.handle('admin:verifyPassword', (_event, password: unknown) => ({
|
||||
success: verifyAdminPassword(password),
|
||||
}));
|
||||
ipcMain.handle('admin:isUnlocked', () => isAdminSessionUnlocked());
|
||||
ipcMain.handle('admin:lock', () => {
|
||||
lockAdminSession();
|
||||
return { success: true };
|
||||
});
|
||||
|
||||
ipcMain.handle('shell:openExternal', (_event, url: string) => shell.openExternal(url));
|
||||
ipcMain.handle('shell:showItemInFolder', (_event, path: string) => shell.showItemInFolder(path));
|
||||
ipcMain.handle('shell:openPath', (_event, path: string) => shell.openPath(path));
|
||||
|
||||
Reference in New Issue
Block a user