Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions packages/uhk-agent/src/electron-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { AppUpdateService } from './services/app-update.service';
import { AppService } from './services/app.service';
import { SudoService } from './services/sudo.service';
import { SmartMacroDocService } from './services/smart-macro-doc.service';
import { TrayService } from './services/tray.service';
import isDev from 'electron-is-dev';
import { setMenu } from './electron-menu';
import { loadWindowState, saveWindowState } from './util/window';
Expand Down Expand Up @@ -58,6 +59,7 @@ let appService: AppService;
let sudoService: SudoService;
let packagesDir: string;
let smartMacroDocService: SmartMacroDocService;
let trayService: TrayService;

let areServicesInited = false;

Expand Down Expand Up @@ -111,10 +113,20 @@ async function createWindow() {
show: false
});

if (loadedWindowState.isFullScreen) {
win.setFullScreen(true);
} else if (loadedWindowState.isMaximized) {
win.maximize();
if (!trayService) {
trayService = new TrayService(logger, win);
}
else {
trayService.init(win);
}

const startMinimizedToTray = !!options['start-minimized-to-tray'];
if (!startMinimizedToTray) {
if (loadedWindowState.isFullScreen) {
win.setFullScreen(true);
} else if (loadedWindowState.isMaximized) {
win.maximize();
}
}

setMenu(win, options.devtools);
Expand Down Expand Up @@ -143,7 +155,18 @@ async function createWindow() {
});

win.once('ready-to-show', () => {
win.show();
void (async () => {
await trayService.initTrayIfEnabled();

if (startMinimizedToTray) {
trayService.startInTray({
isFullScreen: loadedWindowState.isFullScreen,
isMaximized: loadedWindowState.isMaximized,
});
} else {
win.show();
}
})();
});

win.webContents.on('did-finish-load', () => {
Expand Down Expand Up @@ -205,6 +228,8 @@ async function windowClosed() {
sudoService = null;
await smartMacroDocService.stop();
smartMacroDocService = null;
trayService?.destroy();
trayService = null;
}

if (isSecondInstance) {
Expand Down Expand Up @@ -273,9 +298,6 @@ if (isSecondInstance) {
app.exit();
});

app.on('will-quit', () => {
});

app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
Expand All @@ -284,17 +306,14 @@ if (isSecondInstance) {
.catch((error) => {
logger.error('[Electron Main] when activating the app: ', error);
});
} else if (!win.isVisible()) {
trayService.revealWindow();
}
});

app.on('second-instance', () => {
// Someone tried to run a second instance, we should focus our window.
if (win) {
if (win.isMinimized()) {
win.restore();
}
win.focus();
}
trayService.revealWindow();
});
}
// In this file you can include the rest of your app's specific main process
Expand Down
11 changes: 11 additions & 0 deletions packages/uhk-agent/src/images/tray-icons/agent-tray-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 0 additions & 15 deletions packages/uhk-agent/src/services/app-update.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { ipcMain } from 'electron';
import { autoUpdater } from 'electron-updater';
import { UpdateInfo, ProgressInfo } from 'builder-util-runtime';
import isDev from 'electron-is-dev';
import storage from 'electron-settings';
import { inspect } from 'node:util';

import {
ApplicationSettings,
CommandLineArgs,
ERR_UPDATER_INVALID_SIGNATURE,
IpcEvents,
Expand Down Expand Up @@ -143,17 +141,4 @@ export class AppUpdateService extends MainServiceBase {

return checkForUpdateOnStartUp;
}

private async getApplicationSettings(): Promise<ApplicationSettings> {
const value = await storage.get('application-settings');
if (!value) {
return {
checkForUpdateOnStartUp: true,
everAttemptedSavingToKeyboard: false
};
}

return JSON.parse(<string>value);
}

}
15 changes: 14 additions & 1 deletion packages/uhk-agent/src/services/main-service-base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { LogService } from 'uhk-common';
import storage from 'electron-settings';
import { ApplicationSettings, LogService } from 'uhk-common';

export class MainServiceBase {
constructor(protected logService: LogService,
Expand All @@ -14,4 +15,16 @@ export class MainServiceBase {
this.win.webContents.send(message, arg);
}

protected async getApplicationSettings(): Promise<ApplicationSettings> {
const value = await storage.get('application-settings');
if (!value) {
return {
checkForUpdateOnStartUp: true,
everAttemptedSavingToKeyboard: false
};
}

return JSON.parse(<string>value);
}

}
Loading