Skip to content

Commit

Permalink
Merge pull request #236 from mmurrell-r7/add-basic-logging
Browse files Browse the repository at this point in the history
Add basic logging
  • Loading branch information
mmurrell-r7 authored Oct 5, 2023
2 parents adf995a + 1ae6b07 commit 8e67fa5
Show file tree
Hide file tree
Showing 3 changed files with 1,742 additions and 2,515 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@xmldom/xmldom": "^0.8.10",
"body-parser": "^1.20.2",
"cookie-parser": "^1.4.6",
"electron-log": "^5.0.0-rc.1",
"electron-squirrel-startup": "^1.0.0",
"express": "^4.18.2",
"express-session": "^1.17.3",
Expand Down
22 changes: 17 additions & 5 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ const {
nativeTheme,
clipboard,
} = require('electron');
const log = require('electron-log');
const { app: Server } = require('./api/server');
const { loadTouchBar } = require('./touchbar');
const protocol = require('./protocol');
const { channels } = require('./containers/index');

log.initialize({ preload: true });

// See https://www.electronforge.io/config/makers/squirrel.windows#handling-startup-events
// for more details.
if (require('electron-squirrel-startup')) {
Expand Down Expand Up @@ -76,7 +79,7 @@ app.on('ready', async () => {
const port = Server.get('port');

Server.listen(port, host, () => {
console.log(`Server listening on ${host}:${port}`); // eslint-disable-line no-console
log.info(`Server listening on ${host}:${port}`);
});

Storage.set('session', {});
Expand All @@ -95,6 +98,7 @@ app.on('ready', async () => {
});

mainWindow.on('close', () => {
log.info('[Event] BrowserWindow close');
const bounds = mainWindow.getBounds();

Storage.set('lastWindowState', {
Expand All @@ -111,27 +115,35 @@ app.on('ready', async () => {
});

mainWindow.on('closed', () => {
log.info('[Event] BrowserWindow closed');
mainWindow = null;
});

if (isDev) {
mainWindow.openDevTools({ mode: 'detach' });
} else {
baseUrl = new URL(`awsaml:///${path.join(__dirname, '/../../build/index.html')}`).toString();
log.info(`baseUrl: ${baseUrl}`);
Server.set('baseUrl', baseUrl);
}

await mainWindow.loadURL(baseUrl);

mainWindow.on('ready-to-show', () => {
log.info('[Event] BrowserWindow ready-to-show');
mainWindow.show();
});

mainWindow.webContents.on('did-finish-load', () => loadTouchBar(mainWindow, storedMetadataUrls));
log.info('BrowserWindow.loadURL');
await mainWindow.loadURL(baseUrl);
log.info('BrowserWindow.loadURL completed');

mainWindow.webContents.on('did-finish-load', () => {
log.info('[Event] BrowserWindow did-finish-load');
loadTouchBar(mainWindow, storedMetadataUrls);
});

// set up IPC handlers
Object.entries(channels).forEach(([namespace, value = {}]) => {
console.log(`loading handlers for ${namespace}`); // eslint-disable-line no-console
log.info(`Loading handlers for ${namespace}`);
Object.entries(value).forEach(([channelName, handler]) => {
ipcMain.handle(channelName, handler);
});
Expand Down
Loading

0 comments on commit 8e67fa5

Please sign in to comment.