Skip to content

Commit 9e2a9d5

Browse files
committed
Fix logging
1 parent 6012722 commit 9e2a9d5

File tree

6 files changed

+20
-23
lines changed

6 files changed

+20
-23
lines changed

main/index.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ const makeTrackDict = require('./track-dict')
1212
const audio = require('./windows/audio')
1313
const player = require('./windows/player')
1414
const AudioLibrary = require('./lib/audio-library')
15-
const log = require('electron-log')
1615
const autoUpdater = require('electron-updater').autoUpdater
1716

1817
// handle uncaught exceptions before calling any functions
1918
process.on('uncaughtException', (err) => {
20-
log.error(err)
19+
console.error(err)
2120
})
2221

2322
const windows = [player, audio]
@@ -65,7 +64,7 @@ app.on('ready', function appReady () {
6564
artwork.init()
6665

6766
electron.powerMonitor.on('suspend', function pauseOnWake () {
68-
log.info('Entering sleep, pausing')
67+
broadcast('log', 'Entering sleep, pausing')
6968
ipcMain.emit('pause')
7069
})
7170

@@ -92,7 +91,7 @@ app.on('ready', function appReady () {
9291
// register autoUpdater
9392
if (!process.env.DEV_SERVER) {
9493
setTimeout(() => {
95-
log.info('autoUpdater: Auto update initalized...')
94+
broadcast('log', 'autoUpdater: Auto update initalized...')
9695
autoUpdater.checkForUpdatesAndNotify()
9796
}, 1000 * 3)
9897
}
@@ -103,17 +102,17 @@ app.on('ready', function appReady () {
103102
})
104103

105104
autoUpdater.on('checking-for-update', () => {
106-
log.info('autoUpdater: Checking for update...')
105+
broadcast('log', 'autoUpdater: Checking for update...')
107106
broadcast('au:checking-for-update')
108107
})
109108

110109
autoUpdater.on('update-available', (info) => {
111-
log.info('autoUpdater: Update available!')
110+
broadcast('log', 'autoUpdater: Update available!')
112111
broadcast('au:update-available', info)
113112
})
114113

115114
autoUpdater.on('update-not-available', (info) => {
116-
log.info('autoUpdater: No update available')
115+
broadcast('log', 'autoUpdater: No update available')
117116
broadcast('au:update-not-available', info)
118117
})
119118

@@ -122,7 +121,7 @@ app.on('ready', function appReady () {
122121
})
123122

124123
autoUpdater.on('update-downloaded', (info) => {
125-
log.info('autoUpdater: Update downloaded')
124+
broadcast('log', 'autoUpdater: Update downloaded')
126125
broadcast('au:update-downloaded', info)
127126
})
128127

@@ -146,7 +145,7 @@ app.on('ready', function appReady () {
146145

147146
function queue (ev, newIndex) {
148147
const newTrack = al.queue(newIndex)
149-
log.info(newTrack)
148+
broadcast('log', newTrack)
150149
broadcast('new-track', newTrack)
151150
if (player.win) {
152151
player.win.send('new-index', al.index)
@@ -163,7 +162,7 @@ app.on('ready', function appReady () {
163162
}
164163

165164
function handleGetPath (err, blobPath) {
166-
if (err) return log.error(err)
165+
if (err) return broadcast('log', err)
167166
al.currentTrack.artwork = blobPath
168167
if (player.win) {
169168
player.win.send('new-track', al.currentTrack)
@@ -247,16 +246,16 @@ app.on('ready', function appReady () {
247246
function handleNewTracks (err, newTrackDict) {
248247
state.loading = false
249248
broadcast('loading', false)
250-
if (err) return log.warn(err)
249+
if (err) return broadcast('log', err)
251250
const newState = al.load(newTrackDict)
252251
if (player.win) player.win.send('track-dict', newState.trackDict, newState.order, state.paths)
253252
console.timeEnd('update-library')
254-
log.info('Done scanning. Found ' + Object.keys(newState.trackDict).length + ' tracks.')
253+
broadcast('log', 'Done scanning. Found ' + Object.keys(newState.trackDict).length + ' tracks.')
255254
}
256255

257256
function updateLibrary (ev, paths) {
258257
if (state.loading) state.loading.destroy()
259-
log.info('Updating library with new path(s): ' + paths)
258+
broadcast('log', 'Updating library with new path(s): ' + paths)
260259
console.time('update-library')
261260
state.paths = paths
262261
state.loading = makeTrackDict(paths, handleNewTracks)
@@ -300,7 +299,7 @@ app.on('before-quit', function beforeQuit (e) {
300299
app.isQuitting = true
301300
e.preventDefault()
302301
setTimeout(function () {
303-
log.error('Saving state took too long. Quitting.')
302+
console.log('Saving state took too long. Quitting.')
304303
app.quit()
305304
}, 20000) // quit after 5 secs, at most
306305
persist.set({

main/track-dict.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const mm = require('music-metadata')
44
const writer = require('flush-write-stream')
55
const filter = require('through2-filter')
66
const pump = require('pump')
7-
const log = require('electron-log')
87
const validExtensions = ['m4a', 'mp3', 'ogg']
98

109
module.exports = makeTrackDict
@@ -20,7 +19,7 @@ function makeTrackDict (paths, cb) {
2019

2120
function handleEos (err) {
2221
if (err) return cb(err)
23-
log.info('')
22+
console.log('')
2423
cb(null, newTrackDict)
2524
}
2625
}
@@ -32,7 +31,7 @@ function isValidFile (data, enc, cb) {
3231

3332
function concatTrackDict (obj) {
3433
function writeTrackDict (data, enc, cb) {
35-
log.info(`Scanning ${data.filepath}`)
34+
console.log(`Scanning ${data.filepath}`)
3635
parseMetadata(data, handleMeta)
3736

3837
function handleMeta (err, meta) {
@@ -83,7 +82,7 @@ function parseMetadata (data, cb) {
8382
})
8483
}).catch(err => {
8584
// Ignore errors
86-
log.info(err.message += ` (file: ${filepath})`)
85+
console.log(err.message += ` (file: ${filepath})`)
8786
const { basename } = data
8887
const ext = path.extname(basename)
8988
const title = path.basename(basename, ext)

main/windows/audio.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const { app, BrowserWindow } = require('electron')
22
const path = require('path')
3-
const log = require('electron-log')
43
const remoteMain = require('@electron/remote/main')
54
const AUDIO_WINDOW = 'file://' + path.resolve(__dirname, '..', '..', 'renderer', 'audio', 'index.html')
65
const audio = module.exports = {
@@ -53,7 +52,7 @@ function show () {
5352

5453
function toggleDevTools () {
5554
if (!audio.win) return
56-
log.info('[AUDIO] Toggling dev tools')
55+
console.log('[AUDIO] Toggling dev tools')
5756
if (audio.win.webContents.isDevToolsOpened()) {
5857
audio.win.webContents.closeDevTools()
5958
audio.win.hide()

main/windows/player.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const { BrowserWindow, app } = require('electron')
22
const windowStateKeeper = require('electron-window-state')
33
const path = require('path')
4-
const log = require('electron-log')
54
const remoteMain = require('@electron/remote/main')
65
const PLAYER_WINDOW = 'file://' + path.resolve(__dirname, '..', '..', 'renderer', 'player', 'index.html')
76

@@ -63,7 +62,7 @@ function init () {
6362

6463
function toggleAlwaysOnTop () {
6564
if (!player.win) return
66-
log.info('[PLAYER] Toggling Always on Top')
65+
console.log('[PLAYER] Toggling Always on Top')
6766
if (player.win.isAlwaysOnTop()) {
6867
alwaysOnTop = false
6968
player.win.setAlwaysOnTop(alwaysOnTop)

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
"electron-context-menu": "^3.6.1",
8383
"electron-debug": "^3.0.1",
8484
"electron-default-menu": "^1.0.1",
85-
"electron-log": "^5.0.0-beta.16",
8685
"electron-store": "^8.1.0",
8786
"electron-updater": "^6.1.7",
8887
"electron-window-state": "^5.0.2",

renderer/player/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const choo = require('choo')
22
const { ipcRenderer } = require('electron')
33
const app = window.hyperamp = choo()
44

5+
ipcRenderer.on('log', (...args) => console.log(args))
6+
57
const entypoSprite = require('entypo').getNode()
68
document.body.insertAdjacentElement('afterbegin', entypoSprite)
79

0 commit comments

Comments
 (0)