Features: - Welcome screen on first run (provider choice before LS starts) - 15+ AI providers (Google Gemini, OpenAI, Anthropic, DeepSeek, Ollama, etc.) - Provider config syncs to endpoints.json for translation proxy - Built-in Node.js translation proxy for non-native backends - Auto-update support, tray integration, URI scheme handler
209 lines
8.2 KiB
JavaScript
209 lines
8.2 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || (function () {
|
|
var ownKeys = function(o) {
|
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
var ar = [];
|
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
return ar;
|
|
};
|
|
return ownKeys(o);
|
|
};
|
|
return function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
})();
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.registerIpcHandlers = registerIpcHandlers;
|
|
const electron_1 = require("electron");
|
|
const electron_updater_1 = require("electron-updater");
|
|
const updater_1 = require("./updater");
|
|
const main_1 = __importDefault(require("electron-log/main"));
|
|
const fs = __importStar(require("fs/promises"));
|
|
const customScheme_1 = require("./customScheme");
|
|
const tray_1 = require("./tray");
|
|
/**
|
|
* Registers all IPC handlers for the main process.
|
|
*/
|
|
function registerIpcHandlers(storageManager) {
|
|
// Dialog
|
|
electron_1.ipcMain.handle('dialog:open-workspace', async () => {
|
|
const result = await electron_1.dialog.showOpenDialog({
|
|
properties: ['openDirectory', 'createDirectory'],
|
|
title: 'Open workspace',
|
|
});
|
|
if (result.canceled || result.filePaths.length === 0) {
|
|
return undefined;
|
|
}
|
|
return result.filePaths[0];
|
|
});
|
|
// Auto-updater
|
|
electron_1.ipcMain.handle('updater:apply', async () => {
|
|
(0, updater_1.broadcastState)({ type: 'ready' });
|
|
});
|
|
electron_1.ipcMain.handle('updater:quit-and-install', () => {
|
|
if (!electron_1.app.isPackaged) {
|
|
console.log('[AutoUpdater] Skipping quitAndInstall (requires a packaged app).');
|
|
return;
|
|
}
|
|
electron_updater_1.autoUpdater.quitAndInstall();
|
|
});
|
|
// Notifications
|
|
electron_1.ipcMain.handle('notification:send', (_, options) => {
|
|
const notification = new electron_1.Notification({
|
|
title: options.title,
|
|
body: options.body,
|
|
silent: options.silent ?? false,
|
|
});
|
|
notification.on('click', () => {
|
|
const win = electron_1.BrowserWindow.getAllWindows()[0];
|
|
if (win) {
|
|
if (win.isMinimized()) {
|
|
win.restore();
|
|
}
|
|
win.show();
|
|
win.focus();
|
|
if (options.payload) {
|
|
win.webContents.send('notification:clicked', options.payload);
|
|
}
|
|
}
|
|
});
|
|
notification.show();
|
|
});
|
|
// Note: copied from our desktop AGY implementation:
|
|
// vs/platform/nativeNotification/electron-main/electronNotificationService.ts
|
|
electron_1.ipcMain.handle('notification:open-system-preferences', async () => {
|
|
if (process.platform === 'darwin') {
|
|
void electron_1.shell.openExternal('x-apple.systempreferences:com.apple.preference.notifications');
|
|
}
|
|
else if (process.platform === 'win32') {
|
|
void electron_1.shell.openExternal('ms-settings:notifications');
|
|
}
|
|
else if (process.platform === 'linux') {
|
|
const { exec } = await Promise.resolve().then(() => __importStar(require('child_process')));
|
|
const commands = [
|
|
'gnome-control-center notifications',
|
|
'systemsettings kcm_notifications',
|
|
'xfce4-notifyd-config',
|
|
'gnome-control-center',
|
|
'systemsettings',
|
|
];
|
|
for (const command of commands) {
|
|
try {
|
|
exec(command);
|
|
return; // If one command executes without immediate error, assume success for now
|
|
}
|
|
catch {
|
|
// Try next
|
|
}
|
|
}
|
|
}
|
|
});
|
|
// Storage
|
|
electron_1.ipcMain.handle('storage:get-items', async () => {
|
|
return storageManager.getItems();
|
|
});
|
|
electron_1.ipcMain.handle('storage:update-items', async (_event, changes) => {
|
|
await storageManager.updateItems(changes);
|
|
});
|
|
// Logs
|
|
electron_1.ipcMain.handle('logs:electron', async () => {
|
|
try {
|
|
const logPath = main_1.default.transports.file.getFile().path;
|
|
const contents = await fs.readFile(logPath, 'utf-8');
|
|
return contents;
|
|
}
|
|
catch (err) {
|
|
return `Failed to read logs: ${String(err)}`;
|
|
}
|
|
});
|
|
// Sidecar extension custom scheme
|
|
electron_1.ipcMain.handle('extensions:send-authorities', async (_event, authorities) => {
|
|
customScheme_1.extensionAuthorities.clear();
|
|
for (const [key, value] of Object.entries(authorities)) {
|
|
customScheme_1.extensionAuthorities.set(key, value);
|
|
}
|
|
});
|
|
// Agent
|
|
electron_1.ipcMain.handle('agent:update-active-count', async (_event, count) => {
|
|
(0, tray_1.updateTrayAgentCount)(count);
|
|
});
|
|
// Window
|
|
electron_1.ipcMain.handle('window:set-title-bar-overlay', async (_event, options) => {
|
|
const win = electron_1.BrowserWindow.getFocusedWindow() || electron_1.BrowserWindow.getAllWindows()[0];
|
|
if (win && process.platform === 'win32') {
|
|
win.setTitleBarOverlay({
|
|
color: options.color,
|
|
symbolColor: options.symbolColor,
|
|
height: 30,
|
|
});
|
|
}
|
|
});
|
|
electron_1.ipcMain.handle('window:minimize', async () => {
|
|
const win = electron_1.BrowserWindow.getFocusedWindow() || electron_1.BrowserWindow.getAllWindows()[0];
|
|
if (win) {
|
|
win.minimize();
|
|
}
|
|
});
|
|
electron_1.ipcMain.handle('window:maximize', async () => {
|
|
const win = electron_1.BrowserWindow.getFocusedWindow() || electron_1.BrowserWindow.getAllWindows()[0];
|
|
if (win) {
|
|
win.maximize();
|
|
}
|
|
});
|
|
electron_1.ipcMain.handle('window:unmaximize', async () => {
|
|
const win = electron_1.BrowserWindow.getFocusedWindow() || electron_1.BrowserWindow.getAllWindows()[0];
|
|
if (win) {
|
|
win.unmaximize();
|
|
}
|
|
});
|
|
electron_1.ipcMain.handle('window:is-maximized', async () => {
|
|
const win = electron_1.BrowserWindow.getFocusedWindow() || electron_1.BrowserWindow.getAllWindows()[0];
|
|
return win ? win.isMaximized() : false;
|
|
});
|
|
electron_1.ipcMain.handle('window:close', async () => {
|
|
const win = electron_1.BrowserWindow.getFocusedWindow() || electron_1.BrowserWindow.getAllWindows()[0];
|
|
if (win) {
|
|
win.close();
|
|
}
|
|
});
|
|
electron_1.ipcMain.handle('window:toggle-devtools', async () => {
|
|
const win = electron_1.BrowserWindow.getFocusedWindow() || electron_1.BrowserWindow.getAllWindows()[0];
|
|
if (win) {
|
|
win.webContents.toggleDevTools();
|
|
}
|
|
});
|
|
// Auto-updater manual check
|
|
electron_1.ipcMain.handle('updater:check-for-updates', () => {
|
|
(0, updater_1.checkForUpdates)(true);
|
|
});
|
|
// Safe external shell launch
|
|
electron_1.ipcMain.handle('shell:open-external', async (_event, url) => {
|
|
if (url.startsWith('https://') || url.startsWith('http://')) {
|
|
await electron_1.shell.openExternal(url);
|
|
}
|
|
});
|
|
}
|