Skip to content

Commit e7eec56

Browse files
authored
Update (#69)
* temp update * some more temp update * some more temp update * kinda working * some where in the middle * Optimize * Tests * Finally
1 parent e19b6f4 commit e7eec56

12 files changed

Lines changed: 1889 additions & 8 deletions

File tree

jest.config.cjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,32 @@ module.exports = {
6161
// For example:
6262
// testTimeout: 15000,
6363
// setupFiles: ['./src/cobolt-backend/test-setup.js'],
64+
},
65+
// Specific configuration for main process tests
66+
{
67+
preset: 'ts-jest',
68+
displayName: 'main',
69+
testMatch: ['<rootDir>/tests/__tests__/main/**/*.test.{js,jsx,ts,tsx}'],
70+
testEnvironment: 'node',
71+
moduleDirectories: [
72+
'node_modules',
73+
'release/app/node_modules',
74+
'src'
75+
],
76+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
77+
moduleNameMapper: {
78+
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/tests/mocks/fileMock.js',
79+
'\\.(css|less|sass|scss)$': 'identity-obj-proxy',
80+
'^electron$': '<rootDir>/tests/mocks/electronMock.js',
81+
'^sqlite3$': '<rootDir>/tests/mocks/sqlite3Mock.js'
82+
},
83+
setupFiles: [
84+
'./scripts/check-build-exists.ts'
85+
],
86+
testPathIgnorePatterns: ['./release/app/dist', './dll'],
87+
transform: {
88+
'^.+\\.[tj]s$': 'ts-jest',
89+
},
6490
}
6591
]
6692
};

src/main/main.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ import {
3737
} from '../cobolt-backend/utils/error_manager';
3838
import { loadConfig } from '../cobolt-backend/connectors/mcp_tools';
3939
import { stopOllama, setProgressWindow } from '../cobolt-backend/ollama_client';
40+
import AppUpdater from './updater';
4041

4142
let mainWindow: BrowserWindow | null = null;
4243
let loadingWindow: BrowserWindow | null = null;
4344
let initializationComplete: Promise<void> | null = null;
45+
let appUpdater: AppUpdater | null = null;
4446

4547
log.initialize();
4648

@@ -188,6 +190,12 @@ const createWindow = async (): Promise<void> => {
188190
// Set progress window for ollama client
189191
setProgressWindow(mainWindow);
190192

193+
// Initialize app updater after window is created
194+
log.info('[Main] Initializing app updater');
195+
appUpdater = new AppUpdater();
196+
appUpdater.setMainWindow(mainWindow);
197+
log.info('[Main] App updater initialized');
198+
191199
mainWindow.loadURL(resolveHtmlPath('index.html'));
192200

193201
mainWindow.on('ready-to-show', async () => {
@@ -252,6 +260,14 @@ const createWindow = async (): Promise<void> => {
252260
});
253261
}
254262
}, 1000); // Delay showing dialog to ensure UI is fully loaded
263+
264+
// Check for updates on startup
265+
if (app.isPackaged) {
266+
log.info('[Main] App is packaged, will check for updates on startup');
267+
appUpdater?.checkForUpdatesOnStartup();
268+
} else {
269+
log.info('[Main] App is not packaged, skipping auto-update check');
270+
}
255271
});
256272

257273
mainWindow.on('closed', () => {
@@ -657,6 +673,10 @@ ipcMain.handle('refresh-mcp-connections', async () => {
657673
}
658674
});
659675

676+
ipcMain.handle('get-app-version', () => {
677+
return app.getVersion();
678+
});
679+
660680
// Global error handlers
661681
process.on('uncaughtException', (error) => {
662682
showErrorDialog('Unexpected Error', error);

src/main/menu.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
BrowserWindow,
66
MenuItemConstructorOptions,
77
} from 'electron';
8+
import log from 'electron-log/main';
89

910
interface DarwinMenuItemConstructorOptions extends MenuItemConstructorOptions {
1011
selector?: string;
@@ -54,17 +55,17 @@ export default class MenuBuilder {
5455

5556
buildDarwinTemplate(): MenuItemConstructorOptions[] {
5657
const subMenuAbout: DarwinMenuItemConstructorOptions = {
57-
label: 'Electron',
58+
label: 'Cobolt',
5859
submenu: [
5960
{
60-
label: 'About ElectronReact',
61+
label: 'About Cobolt',
6162
selector: 'orderFrontStandardAboutPanel:',
6263
},
6364
{ type: 'separator' },
6465
{ label: 'Services', submenu: [] },
6566
{ type: 'separator' },
6667
{
67-
label: 'Hide ElectronReact',
68+
label: 'Hide Cobolt',
6869
accelerator: 'Command+H',
6970
selector: 'hide:',
7071
},
@@ -180,6 +181,15 @@ export default class MenuBuilder {
180181
shell.openExternal('https://github.com/electron/electron/issues');
181182
},
182183
},
184+
{ type: 'separator' },
185+
{
186+
label: 'Check for Updates...',
187+
click: () => {
188+
log.info('[Menu] Check for Updates clicked');
189+
this.mainWindow.webContents.send('check-for-updates-menu');
190+
log.info('[Menu] Sent check-for-updates-menu event to renderer');
191+
},
192+
},
183193
],
184194
};
185195

@@ -189,11 +199,18 @@ export default class MenuBuilder {
189199
? subMenuViewDev
190200
: subMenuViewProd;
191201

192-
return [subMenuAbout, subMenuEdit, subMenuView, subMenuWindow, subMenuHelp];
202+
// Cast to MenuItemConstructorOptions[] for compatibility with Menu.buildFromTemplate
203+
return [
204+
subMenuAbout,
205+
subMenuEdit,
206+
subMenuView,
207+
subMenuWindow,
208+
subMenuHelp,
209+
] as MenuItemConstructorOptions[];
193210
}
194211

195-
buildDefaultTemplate() {
196-
const templateDefault = [
212+
buildDefaultTemplate(): MenuItemConstructorOptions[] {
213+
const templateDefault: MenuItemConstructorOptions[] = [
197214
{
198215
label: '&File',
199216
submenu: [
@@ -272,7 +289,18 @@ export default class MenuBuilder {
272289
{
273290
label: 'Search Issues',
274291
click() {
275-
shell.openExternal('https://github.com/platinum-hill/cobolt/issues');
292+
shell.openExternal(
293+
'https://github.com/platinum-hill/cobolt/issues',
294+
);
295+
},
296+
},
297+
{ type: 'separator' },
298+
{
299+
label: 'Check for Updates...',
300+
click: () => {
301+
log.info('[Menu] Check for Updates clicked');
302+
this.mainWindow.webContents.send('check-for-updates-menu');
303+
log.info('[Menu] Sent check-for-updates-menu event to renderer');
276304
},
277305
},
278306
],

src/main/preload.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ const validChannels = {
2626
'update-core-models',
2727
'report-error',
2828
'refresh-mcp-connections',
29+
'check-for-updates',
30+
'check-for-updates-menu',
31+
'download-update',
32+
'download-and-install',
33+
'install-update',
34+
'enable-auto-install',
35+
'get-update-status',
36+
'get-app-version',
2937
],
3038
on: [
3139
'message-response',
@@ -35,6 +43,8 @@ const validChannels = {
3543
'setup-progress',
3644
'show-error-dialog',
3745
'refresh-models-list',
46+
'update-status',
47+
'check-for-updates-menu',
3848
],
3949
};
4050

0 commit comments

Comments
 (0)