import { app, BrowserWindow, Menu, nativeImage, Tray } from 'electron';
import path from 'path';
import { fileURLToPath } from 'url';
import { startMcpServer } from './mcp-server.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
let mainWindow;
let tray;
function createTray() {
const isWin = process.platform === 'win32';
const iconName = isWin ? 'icon.ico' : 'icon.png';
const iconPath = path.join(__dirname, iconName);
console.log('Loading tray icon from:', iconPath);
const icon = nativeImage.createFromPath(iconPath);
if (icon.isEmpty()) {
console.error('Failed to load tray icon!');
}
tray = new Tray(icon);
const contextMenu = Menu.buildFromTemplate([
{ label: 'Open Window', click: () => mainWindow.show() },
{ type: 'separator' },
{ label: 'Quit', click: () => {
app.isQuitting = true;
app.quit();
}}
]);
tray.setToolTip('SQLite Vector MCP Server');
tray.setContextMenu(contextMenu);
tray.on('double-click', () => {
mainWindow.show();
});
}
function createWindow() {
mainWindow = new BrowserWindow({
width: 600,
height: 400,
show: true,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
},
});
mainWindow.loadFile(path.join(__dirname, 'index.html'));
mainWindow.on('close', (event) => {
if (!app.isQuitting) {
event.preventDefault();
mainWindow.hide();
}
return false;
});
mainWindow.on('closed', function () {
mainWindow = null;
});
}
app.whenReady().then(() => {
createWindow();
createTray();
startMcpServer(3000);
console.log('Electron app is ready and MCP server started on port 3000');
});
// 常駐のために全てのウィンドウが閉じても終了しないようにする
app.on('window-all-closed', function () {
// 通常は何もしない
});
app.on('before-quit', () => {
app.isQuitting = true;
});