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