Fix ESLint warnings and and enable max warnings 0 to fail builds (#2101)
This commit is contained in:
+66
-54
@@ -3,13 +3,13 @@ import {
|
||||
session,
|
||||
BrowserWindow,
|
||||
dialog,
|
||||
globalShortcut,
|
||||
ipcMain,
|
||||
Menu,
|
||||
MenuItem,
|
||||
Notification,
|
||||
powerSaveBlocker,
|
||||
Tray,
|
||||
App,
|
||||
} from 'electron';
|
||||
import { Buffer } from 'node:buffer';
|
||||
import started from 'electron-squirrel-startup';
|
||||
@@ -41,8 +41,8 @@ app.setAsDefaultProtocolClient('goose');
|
||||
|
||||
// Triggered when the user opens "goose://..." links
|
||||
let firstOpenWindow: BrowserWindow;
|
||||
let pendingDeepLink = null; // Store deep link if sent before React is ready
|
||||
app.on('open-url', async (event, url) => {
|
||||
let pendingDeepLink: string | null = null; // Store deep link if sent before React is ready
|
||||
app.on('open-url', async (_event, url) => {
|
||||
pendingDeepLink = url;
|
||||
|
||||
// Parse the URL to determine the type
|
||||
@@ -156,13 +156,21 @@ let appConfig = {
|
||||
let windowCounter = 0;
|
||||
const windowMap = new Map<number, BrowserWindow>();
|
||||
|
||||
interface BotConfig {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
instructions: string;
|
||||
activities: string[];
|
||||
}
|
||||
|
||||
const createChat = async (
|
||||
app,
|
||||
app: App,
|
||||
query?: string,
|
||||
dir?: string,
|
||||
version?: string,
|
||||
resumeSessionId?: string,
|
||||
botConfig?: any // Bot configuration
|
||||
botConfig?: BotConfig
|
||||
) => {
|
||||
// Apply current environment settings before creating chat
|
||||
updateEnvironmentVariables(envToggles);
|
||||
@@ -202,7 +210,7 @@ const createChat = async (
|
||||
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
||||
// Open all links in external browser
|
||||
if (url.startsWith('http:') || url.startsWith('https:')) {
|
||||
require('electron').shell.openExternal(url);
|
||||
electron.shell.openExternal(url);
|
||||
return { action: 'deny' };
|
||||
}
|
||||
return { action: 'allow' };
|
||||
@@ -350,7 +358,7 @@ const openDirectoryDialog = async (replaceWindow: boolean = false) => {
|
||||
if (!result.canceled && result.filePaths.length > 0) {
|
||||
addRecentDir(result.filePaths[0]);
|
||||
const currentWindow = BrowserWindow.getFocusedWindow();
|
||||
const newWindow = await createChat(app, undefined, result.filePaths[0]);
|
||||
await createChat(app, undefined, result.filePaths[0]);
|
||||
if (replaceWindow) {
|
||||
currentWindow.close();
|
||||
}
|
||||
@@ -376,7 +384,7 @@ process.on('unhandledRejection', (error) => {
|
||||
handleFatalError(error instanceof Error ? error : new Error(String(error)));
|
||||
});
|
||||
|
||||
ipcMain.on('react-ready', (event) => {
|
||||
ipcMain.on('react-ready', () => {
|
||||
console.log('React ready event received');
|
||||
|
||||
if (pendingDeepLink) {
|
||||
@@ -399,7 +407,7 @@ ipcMain.on('react-ready', (event) => {
|
||||
});
|
||||
|
||||
// Handle directory chooser
|
||||
ipcMain.handle('directory-chooser', (_, replace: boolean = false) => {
|
||||
ipcMain.handle('directory-chooser', (_event, replace: boolean = false) => {
|
||||
return openDirectoryDialog(replace);
|
||||
});
|
||||
|
||||
@@ -447,11 +455,11 @@ ipcMain.handle('check-ollama', async () => {
|
||||
});
|
||||
|
||||
// Handle binary path requests
|
||||
ipcMain.handle('get-binary-path', (event, binaryName) => {
|
||||
ipcMain.handle('get-binary-path', (_event, binaryName) => {
|
||||
return getBinaryPath(app, binaryName);
|
||||
});
|
||||
|
||||
ipcMain.handle('read-file', (event, filePath) => {
|
||||
ipcMain.handle('read-file', (_event, filePath) => {
|
||||
return new Promise((resolve) => {
|
||||
exec(`cat ${filePath}`, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
@@ -467,7 +475,7 @@ ipcMain.handle('read-file', (event, filePath) => {
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.handle('write-file', (event, filePath, content) => {
|
||||
ipcMain.handle('write-file', (_event, filePath, content) => {
|
||||
return new Promise((resolve) => {
|
||||
const command = `cat << 'EOT' > ${filePath}
|
||||
${content}
|
||||
@@ -513,25 +521,27 @@ app.whenReady().then(async () => {
|
||||
const menu = Menu.getApplicationMenu();
|
||||
|
||||
// App menu
|
||||
const appMenu = menu.items.find((item) => item.label === 'Goose');
|
||||
// add Settings to app menu after About
|
||||
appMenu.submenu.insert(1, new MenuItem({ type: 'separator' }));
|
||||
appMenu.submenu.insert(
|
||||
1,
|
||||
new MenuItem({
|
||||
label: 'Settings',
|
||||
accelerator: 'CmdOrCtrl+,',
|
||||
click() {
|
||||
const focusedWindow = BrowserWindow.getFocusedWindow();
|
||||
if (focusedWindow) focusedWindow.webContents.send('set-view', 'settings');
|
||||
},
|
||||
})
|
||||
);
|
||||
appMenu.submenu.insert(1, new MenuItem({ type: 'separator' }));
|
||||
const appMenu = menu?.items.find((item) => item.label === 'Goose');
|
||||
if (appMenu?.submenu) {
|
||||
// add Settings to app menu after About
|
||||
appMenu.submenu.insert(1, new MenuItem({ type: 'separator' }));
|
||||
appMenu.submenu.insert(
|
||||
1,
|
||||
new MenuItem({
|
||||
label: 'Settings',
|
||||
accelerator: 'CmdOrCtrl+,',
|
||||
click() {
|
||||
const focusedWindow = BrowserWindow.getFocusedWindow();
|
||||
if (focusedWindow) focusedWindow.webContents.send('set-view', 'settings');
|
||||
},
|
||||
})
|
||||
);
|
||||
appMenu.submenu.insert(1, new MenuItem({ type: 'separator' }));
|
||||
}
|
||||
|
||||
// Add Environment menu items to View menu
|
||||
const viewMenu = menu.items.find((item) => item.label === 'View');
|
||||
if (viewMenu) {
|
||||
const viewMenu = menu?.items.find((item) => item.label === 'View');
|
||||
if (viewMenu?.submenu) {
|
||||
viewMenu.submenu.append(new MenuItem({ type: 'separator' }));
|
||||
viewMenu.submenu.append(
|
||||
new MenuItem({
|
||||
@@ -549,29 +559,29 @@ app.whenReady().then(async () => {
|
||||
|
||||
const fileMenu = menu?.items.find((item) => item.label === 'File');
|
||||
|
||||
// open goose to specific dir and set that as its working space
|
||||
fileMenu.submenu.append(
|
||||
new MenuItem({
|
||||
label: 'Open Directory...',
|
||||
accelerator: 'CmdOrCtrl+O',
|
||||
click: () => openDirectoryDialog(),
|
||||
})
|
||||
);
|
||||
|
||||
// Add Recent Files submenu
|
||||
const recentFilesSubmenu = buildRecentFilesMenu();
|
||||
if (recentFilesSubmenu.length > 0) {
|
||||
fileMenu.submenu.append(new MenuItem({ type: 'separator' }));
|
||||
if (fileMenu?.submenu) {
|
||||
// open goose to specific dir and set that as its working space
|
||||
fileMenu.submenu.append(
|
||||
new MenuItem({
|
||||
label: 'Recent Directories',
|
||||
submenu: recentFilesSubmenu,
|
||||
label: 'Open Directory...',
|
||||
accelerator: 'CmdOrCtrl+O',
|
||||
click: () => openDirectoryDialog(),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// Add menu items to File menu
|
||||
if (fileMenu && fileMenu.submenu) {
|
||||
// Add Recent Files submenu
|
||||
const recentFilesSubmenu = buildRecentFilesMenu();
|
||||
if (recentFilesSubmenu.length > 0) {
|
||||
fileMenu.submenu.append(new MenuItem({ type: 'separator' }));
|
||||
fileMenu.submenu.append(
|
||||
new MenuItem({
|
||||
label: 'Recent Directories',
|
||||
submenu: recentFilesSubmenu,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// Add menu items to File menu
|
||||
fileMenu.submenu.append(
|
||||
new MenuItem({
|
||||
label: 'New Chat Window',
|
||||
@@ -611,7 +621,9 @@ app.whenReady().then(async () => {
|
||||
);
|
||||
}
|
||||
|
||||
Menu.setApplicationMenu(menu);
|
||||
if (menu) {
|
||||
Menu.setApplicationMenu(menu);
|
||||
}
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
@@ -619,7 +631,7 @@ app.whenReady().then(async () => {
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on('create-chat-window', (_, query, dir, version, resumeSessionId, botConfig) => {
|
||||
ipcMain.on('create-chat-window', (_event, query, dir, version, resumeSessionId, botConfig) => {
|
||||
if (!dir?.trim()) {
|
||||
const recentDirs = loadRecentDirs();
|
||||
dir = recentDirs.length > 0 ? recentDirs[0] : null;
|
||||
@@ -627,12 +639,12 @@ app.whenReady().then(async () => {
|
||||
createChat(app, query, dir, version, resumeSessionId, botConfig);
|
||||
});
|
||||
|
||||
ipcMain.on('notify', (event, data) => {
|
||||
ipcMain.on('notify', (_event, data) => {
|
||||
console.log('NOTIFY', data);
|
||||
new Notification({ title: data.title, body: data.body }).show();
|
||||
});
|
||||
|
||||
ipcMain.on('logInfo', (_, info) => {
|
||||
ipcMain.on('logInfo', (_event, info) => {
|
||||
log.info('from renderer:', info);
|
||||
});
|
||||
|
||||
@@ -668,12 +680,12 @@ app.whenReady().then(async () => {
|
||||
});
|
||||
|
||||
// Handle binary path requests
|
||||
ipcMain.handle('get-binary-path', (event, binaryName) => {
|
||||
ipcMain.handle('get-binary-path', (_event, binaryName) => {
|
||||
return getBinaryPath(app, binaryName);
|
||||
});
|
||||
|
||||
// Handle metadata fetching from main process
|
||||
ipcMain.handle('fetch-metadata', async (_, url) => {
|
||||
ipcMain.handle('fetch-metadata', async (_event, url) => {
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
@@ -692,7 +704,7 @@ app.whenReady().then(async () => {
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on('open-in-chrome', (_, url) => {
|
||||
ipcMain.on('open-in-chrome', (_event, url) => {
|
||||
// On macOS, use the 'open' command with Chrome
|
||||
if (process.platform === 'darwin') {
|
||||
spawn('open', ['-a', 'Google Chrome', url]);
|
||||
|
||||
Reference in New Issue
Block a user