mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-04-09 05:09:39 +00:00
Moved error logging to the browser console
This commit is contained in:
@@ -18,6 +18,7 @@ export class ElectronService {
|
||||
constructor() {
|
||||
if (this.isElectron) {
|
||||
this.electron = window.require('electron')
|
||||
this.receiveIPC('log', results => results.forEach(result => console.log(result)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { AnyFunction } from '../../shared/UtilFunctions'
|
||||
import { devLog } from '../../shared/ElectronUtilFunctions'
|
||||
import { createWriteStream } from 'fs'
|
||||
import * as needle from 'needle'
|
||||
import { Readable } from 'stream'
|
||||
@@ -111,11 +112,11 @@ class APIFileDownloader {
|
||||
} catch (err) {
|
||||
this.retryCount++
|
||||
if (this.retryCount <= RETRY_MAX) {
|
||||
console.log(`Failed to get file: Retry attempt ${this.retryCount}...`)
|
||||
devLog(`Failed to get file: Retry attempt ${this.retryCount}...`)
|
||||
if (this.wasCanceled) { return }
|
||||
this.startDownloadStream()
|
||||
} else {
|
||||
console.log(JSON.stringify(err))
|
||||
devLog(err)
|
||||
if (err?.code && err?.response?.statusText) {
|
||||
this.failDownload(downloadErrors.responseError(`${err.code} (${err.response.statusText})`))
|
||||
} else {
|
||||
@@ -241,7 +242,7 @@ class SlowFileDownloader {
|
||||
this.req.on('timeout', this.cancelable((type: string) => {
|
||||
this.retryCount++
|
||||
if (this.retryCount <= RETRY_MAX) {
|
||||
console.log(`TIMEOUT: Retry attempt ${this.retryCount}...`)
|
||||
devLog(`TIMEOUT: Retry attempt ${this.retryCount}...`)
|
||||
this.requestDownload(cookieHeader)
|
||||
} else {
|
||||
this.failDownload(downloadErrors.timeout(type))
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { readdir, unlink, mkdir as _mkdir } from 'fs'
|
||||
import { promisify } from 'util'
|
||||
import { join, extname } from 'path'
|
||||
import { AnyFunction } from 'src/electron/shared/UtilFunctions'
|
||||
import { AnyFunction } from '../../shared/UtilFunctions'
|
||||
import { devLog } from '../../shared/ElectronUtilFunctions'
|
||||
import * as node7z from 'node-7z'
|
||||
import * as zipBin from '7zip-bin'
|
||||
import * as unrarjs from 'node-unrar-js' // TODO find better rar library that has async extraction
|
||||
@@ -119,7 +120,7 @@ export class FileExtractor {
|
||||
let extractErrorOccured = false
|
||||
stream.on('error', this.cancelable(() => {
|
||||
extractErrorOccured = true
|
||||
console.log(`Failed to extract [${fullPath}]; retrying with .rar extractor...`)
|
||||
devLog(`Failed to extract [${fullPath}]; retrying with .rar extractor...`)
|
||||
this.extract(fullPath, true)
|
||||
}))
|
||||
|
||||
@@ -136,7 +137,7 @@ export class FileExtractor {
|
||||
private deleteArchive(fullPath: string) {
|
||||
unlink(fullPath, this.cancelable((err) => {
|
||||
if (err && err.code != 'ENOENT') {
|
||||
console.log(`Warning: failed to delete archive at [${fullPath}]`)
|
||||
devLog(`Warning: failed to delete archive at [${fullPath}]`)
|
||||
}
|
||||
|
||||
this.callbacks.complete()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { DownloadError } from './ChartDownload'
|
||||
import { tempPath } from '../../shared/Paths'
|
||||
import { AnyFunction } from 'src/electron/shared/UtilFunctions'
|
||||
import { AnyFunction } from '../../shared/UtilFunctions'
|
||||
import { devLog } from '../../shared/ElectronUtilFunctions'
|
||||
import { randomBytes as _randomBytes } from 'crypto'
|
||||
import { mkdir, access, constants } from 'fs'
|
||||
import { join } from 'path'
|
||||
@@ -90,7 +91,7 @@ export class FilesystemChecker {
|
||||
mkdir(tempChartPath, this.cancelable((err) => {
|
||||
if (err) {
|
||||
if (retryCount < 5) {
|
||||
console.log(`Error creating folder [${tempChartPath}], retrying with a different folder...`)
|
||||
devLog(`Error creating folder [${tempChartPath}], retrying with a different folder...`)
|
||||
this.createDownloadFolder(retryCount + 1)
|
||||
} else {
|
||||
this.callbacks.error(filesystemErrors.mkdirError(err), () => this.createDownloadFolder())
|
||||
|
||||
@@ -13,6 +13,7 @@ import { BrowserWindow } from 'electron'
|
||||
import { serverURL } from '../../shared/Paths'
|
||||
import * as fs from 'fs'
|
||||
import { promisify } from 'util'
|
||||
import { devLog } from '../../shared/ElectronUtilFunctions'
|
||||
|
||||
const unlink = promisify(fs.unlink)
|
||||
|
||||
@@ -99,7 +100,7 @@ export class GoogleAuth {
|
||||
|
||||
authServer.on('authCode', async (authCode) => {
|
||||
this.token = (await this.oAuth2Client.getToken(authCode)).tokens
|
||||
writeFile(TOKEN_PATH, this.token).catch(err => console.log('Got token, but failed to write it to TOKEN_PATH:', err))
|
||||
writeFile(TOKEN_PATH, this.token).catch(err => devLog('Got token, but failed to write it to TOKEN_PATH:', err))
|
||||
|
||||
this.authenticateWithToken()
|
||||
|
||||
@@ -133,7 +134,7 @@ export class GoogleAuth {
|
||||
'get',
|
||||
serverURL + `/api/data/client`, null, (err, response) => {
|
||||
if (err) {
|
||||
console.log('Could not authenticate because client info could not be retrieved from the server.')
|
||||
devLog('Could not authenticate because client info could not be retrieved from the server:', err)
|
||||
resolve(false)
|
||||
} else {
|
||||
this.oAuth2Client = new google.auth.OAuth2(response.body.CLIENT_ID, response.body.CLIENT_SECRET, REDIRECT_URI)
|
||||
@@ -179,7 +180,7 @@ export class GoogleAuth {
|
||||
try {
|
||||
await unlink(TOKEN_PATH)
|
||||
} catch (err) {
|
||||
console.log('Failed to delete token.')
|
||||
devLog('Failed to delete token:', err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { basename } from 'path'
|
||||
import { getSettingsHandler } from '../ipc/SettingsHandler.ipc'
|
||||
import { emitIPCEvent } from '../main'
|
||||
|
||||
/**
|
||||
* @returns The relative filepath from the library folder to `absoluteFilepath`.
|
||||
@@ -7,4 +8,11 @@ import { getSettingsHandler } from '../ipc/SettingsHandler.ipc'
|
||||
export function getRelativeFilepath(absoluteFilepath: string) {
|
||||
const settings = getSettingsHandler.getSettings()
|
||||
return basename(settings.libraryPath) + absoluteFilepath.substring(settings.libraryPath.length)
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message in the main BrowserWindow's console.
|
||||
*/
|
||||
export function devLog(...messages: any[]) {
|
||||
emitIPCEvent('log', messages)
|
||||
}
|
||||
@@ -106,6 +106,8 @@ export function getIPCEmitHandlers(): IPCEmitHandler<keyof IPCEmitEvents>[] {
|
||||
* The list of possible async IPC events that don't return values, mapped to their input types.
|
||||
*/
|
||||
export type IPCEmitEvents = {
|
||||
'log': any[]
|
||||
|
||||
'download': Download
|
||||
'download-updated': DownloadProgress
|
||||
'set-settings': Settings
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import * as randomBytes from 'randombytes'
|
||||
const sanitize = require('sanitize-filename')
|
||||
|
||||
// WARNING: do not import anything related to Electron; the code will not compile correctly.
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export type AnyFunction = (...args: any) => any
|
||||
|
||||
|
||||
Reference in New Issue
Block a user