Skip to content

Commit

Permalink
Clean up logging, log more during startup path
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvicenti committed Dec 18, 2024
1 parent fe08dff commit 680d2bc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 48 deletions.
1 change: 0 additions & 1 deletion frontend/apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"cheerio": "1.0.0-rc.12",
"console-log-colors": "0.4.0",
"electron-context-menu": "3.6.1",
"electron-log": "^5.2.4",
"electron-squirrel-startup": "1.0.1",
"electron-store": "10.0.0",
"electron-trpc": "0.6.1",
Expand Down
5 changes: 3 additions & 2 deletions frontend/apps/desktop/src/app-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export function openInitialWindows() {
id: windowId,
})
})
} catch (error) {
error(`[MAIN]: openInitialWindows Error: ${JSON.stringify(error)}`)
} catch (e) {
log.error(`[MAIN]: openInitialWindows Error: ${e.message}`)
trpc.createAppWindow({routes: [defaultRoute]})
return
}
Expand Down Expand Up @@ -221,6 +221,7 @@ export const router = t.router({
}),
)
.mutation(async ({input}) => {
log.info(`[MAIN]: will createAppWindow ${JSON.stringify(input.routes)}`)
const allWindows = getWindowsState()
const destRoute = input.routes[input.routeIndex]
const destRouteKey = getRouteRefocusKey(destRoute)
Expand Down
34 changes: 17 additions & 17 deletions frontend/apps/desktop/src/auto-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ import {
MessageBoxOptions,
shell,
} from 'electron'
import log from 'electron-log/main'
import {updateElectronApp, UpdateSourceType} from 'update-electron-app'
import {debug, error} from './logger'

export function defaultCheckForUpdates() {
log.debug('[MAIN][AUTO-UPDATE]: checking for Updates')
debug('[MAIN][AUTO-UPDATE]: checking for Updates')
// ipcMain.emit(ipcMainEvents.CHECK_FOR_UPDATES_START)

autoUpdater.checkForUpdates()

// ipcMain.emit(ipcMainEvents.CHECK_FOR_UPDATES_END)
log.debug('[MAIN][AUTO-UPDATE]: checking for Updates END')
debug('[MAIN][AUTO-UPDATE]: checking for Updates END')
}

export const checkForUpdates =
process.platform == 'linux' ? linuxCheckForUpdates : defaultCheckForUpdates

export default function autoUpdate() {
if (!IS_PROD_DESKTOP) {
log.debug('[MAIN][AUTO-UPDATE]: Not available in development')
debug('[MAIN][AUTO-UPDATE]: Not available in development')
return
}
if (!isAutoUpdateSupported()) {
log.debug('[MAIN][AUTO-UPDATE]: Auto-Update is not supported')
debug('[MAIN][AUTO-UPDATE]: Auto-Update is not supported')
return
}

Expand Down Expand Up @@ -63,7 +63,7 @@ function setup() {
* - adopt the `feedback` variable to show/hide dialogs
*/

log.debug(`== [MAIN][AUTO-UPDATE]: IS_PROD_DEV + VERSION:`, {
debug(`== [MAIN][AUTO-UPDATE]: IS_PROD_DEV + VERSION:`, {
VERSION,
IS_PROD_DEV,
})
Expand All @@ -88,19 +88,19 @@ function setup() {
// autoUpdater.setFeedURL({url: updateUrl})

autoUpdater.on('error', (message) => {
log.error(
error(
`[MAIN][AUTO-UPDATE]: There was a problem updating the application: ${message}`,
)
})

autoUpdater.on('update-available', async () => {
log.debug(`[MAIN][AUTO-UPDATE]: update available, download will start`)
debug(`[MAIN][AUTO-UPDATE]: update available, download will start`)
try {
} catch (error) {}
})

autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
log.debug('[MAIN][AUTO-UPDATE]: New version downloaded')
debug('[MAIN][AUTO-UPDATE]: New version downloaded')
const dialogOpts: MessageBoxOptions = {
type: 'info',
buttons: ['Restart', 'Later'],
Expand All @@ -112,14 +112,14 @@ function setup() {

dialog.showMessageBox(dialogOpts).then((returnValue: any) => {
if (returnValue.response === 0) {
log.debug('[MAIN][AUTO-UPDATE]: Quit and Install')
debug('[MAIN][AUTO-UPDATE]: Quit and Install')
autoUpdater.quitAndInstall()
}
})
})

autoUpdater.on('update-not-available', (event: any) => {
log.debug('[MAIN][AUTO-UPDATE]: update not available', event)
debug('[MAIN][AUTO-UPDATE]: update not available', event)
})
}

Expand All @@ -132,15 +132,15 @@ export function linuxCheckForUpdates() {
process.arch
}/${app.getVersion()}`

log.debug('[MAIN][AUTO-UPDATE]: checking for Updates', UPDATE_URL)
debug('[MAIN][AUTO-UPDATE]: checking for Updates', UPDATE_URL)

// ipcMain.emit(ipcMainEvents.CHECK_FOR_UPDATES_START)
try {
// TODO: change this to fetch THE LATEST version and compare it with `app.getVersion()`
fetch(UPDATE_URL).then((res) => {
log.debug('[MAIN][AUTO-UPDATE]: LINUX FETCH RES', res)
debug('[MAIN][AUTO-UPDATE]: LINUX FETCH RES', res)
if ('name' in res && res.name) {
log.debug('[MAIN][AUTO-UPDATE]: LINUX NEED TO UPDATE', res)
debug('[MAIN][AUTO-UPDATE]: LINUX NEED TO UPDATE', res)
const dialogOpts: MessageBoxOptions = {
type: 'info',
buttons: ['Go and Download', 'Close'],
Expand All @@ -154,23 +154,23 @@ export function linuxCheckForUpdates() {

if (win) {
dialog.showMessageBox(win, dialogOpts).then((returnValue: any) => {
log.debug('[MAIN][AUTO-UPDATE]: Quit and Install')
debug('[MAIN][AUTO-UPDATE]: Quit and Install')
if (returnValue.response === 0)
shell.openExternal(
'https://github.com/seed-hypermedia/seed/releases/latest',
)
})
} else {
dialog.showMessageBox(dialogOpts).then((returnValue: any) => {
log.debug('[MAIN][AUTO-UPDATE]: Quit and Install')
debug('[MAIN][AUTO-UPDATE]: Quit and Install')
if (returnValue.response === 0)
shell.openExternal(
'https://github.com/seed-hypermedia/seed/releases/latest',
)
})
}
} else {
log.debug('[MAIN][AUTO-UPDATE]: LINUX IS UPDATED', res)
debug('[MAIN][AUTO-UPDATE]: LINUX IS UPDATED', res)
}
})
} catch (error) {}
Expand Down
11 changes: 1 addition & 10 deletions frontend/apps/desktop/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import {IS_PROD_DESKTOP} from '@shm/shared'
import * as legacyLogger from 'electron-log'
import {existsSync, rmSync} from 'fs'
import {join} from 'path'
import {MESSAGE} from 'triple-beam'
import winston from 'winston'
import DailyRotateFile from 'winston-daily-rotate-file'
import {userDataPath} from './app-paths'
import {MESSAGE} from 'triple-beam'

export const legacyLogsFilePath = legacyLogger.transports.file.getFile().path

if (existsSync(legacyLogsFilePath)) {
// throw away legacy logs for security reasons
rmSync(legacyLogsFilePath)
}

export const loggingDir = join(userDataPath, 'logs')

Expand Down
28 changes: 10 additions & 18 deletions frontend/apps/desktop/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
} from 'electron'

import contextMenu from 'electron-context-menu'
import log from 'electron-log/main'
import squirrelStartup from 'electron-squirrel-startup'
import path from 'node:path'
import {
Expand Down Expand Up @@ -87,7 +86,7 @@ if (IS_PROD_DESKTOP) {
maxQueueCount: 30,
// Called every time the number of requests in the queue changes.
queuedLengthChanged: (length) => {
log.debug('[MAIN]: Sentry queue changed', length)
logger.debug('[MAIN]: Sentry queue changed', length)
},
// Called before attempting to send an event to Sentry. Used to override queuing behavior.
//
Expand Down Expand Up @@ -352,24 +351,17 @@ if (shouldAutoUpdate == 'true') {
console.log('Auto-Update is set to OFF')
}

//Simple logging module Electron/Node.js/NW.js application. No dependencies. No complicated configuration.
log.initialize({
preload: true,
// It makes a renderer logger available trough a global electronLog instance
spyRendererConsole: true,
})

app.on('did-become-active', () => {
log.debug('[MAIN]: did-become-active Seed active')
logger.debug('[MAIN]: Seed active (did-become-active)')
if (BrowserWindow.getAllWindows().length === 0) {
log.debug('[MAIN]: will open the home window')
logger.debug('[MAIN]: will open the home window')
trpc.createAppWindow({
routes: [defaultRoute],
})
}
})
app.on('did-resign-active', () => {
// log.debug('[MAIN]: Seed no longer active')
// logger.debug('[MAIN]: Seed no longer active')
})

// dark mode support: https://www.electronjs.org/docs/latest/tutorial/dark-mode
Expand Down Expand Up @@ -580,30 +572,30 @@ ipcMain.on('open_path', (event, path) => {
const gotTheLock = app.requestSingleInstanceLock()

if (!gotTheLock) {
log.debug('[MAIN]: Another Seed already running. Quitting..')
logger.debug('[MAIN]: Another Seed already running. Quitting..')
app.quit()
} else {
app.on('ready', () => {
log.debug('[MAIN]: Seed ready')
logger.debug('[MAIN]: Seed ready')
openInitialWindows()
})
app.on('second-instance', handleSecondInstance)

app.on('window-all-closed', () => {
log.debug('[MAIN]: window-all-closed')
logger.debug('[MAIN]: window-all-closed')
globalShortcut.unregisterAll()
if (process.platform != 'darwin') {
log.debug('[MAIN]: will quit the app')
logger.debug('[MAIN]: will quit the app')
app.quit()
}
})
app.on('open-url', (_event, url) => {
handleUrlOpen(url)
})
app.on('activate', () => {
log.debug('[MAIN]: activate Seed Active')
logger.debug('[MAIN]: Seed Active (activate)')
if (BrowserWindow.getAllWindows().length === 0) {
log.debug('[MAIN]: will open the home window')
logger.debug('[MAIN]: will open the home window')
trpc.createAppWindow({
routes: [defaultRoute],
})
Expand Down

0 comments on commit 680d2bc

Please sign in to comment.