Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many bug fixes #870

Merged
merged 7 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 26 additions & 87 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 39 additions & 4 deletions xmcl-electron-app/main/ElectronLauncherApp.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { NetworkErrorCode, NetworkException } from '@xmcl/runtime-api'
import { LauncherApp, Shell } from '@xmcl/runtime/app'
import { LAUNCHER_NAME } from '@xmcl/runtime/constant'
import { Menu, app, net, shell } from 'electron'
import { stat } from 'fs-extra'
import { join } from 'path'
import { AnyError } from '~/util/error'
import { ElectronController } from './ElectronController'
import { ElectronSecretStorage } from './ElectronSecretStorage'
import { ElectronSession } from './ElectronSession'
import { IS_DEV } from './constant'
import defaultApp from './defaultApp'
import { definedPlugins } from './definedPlugins'
import { ElectronUpdater } from './utils/updater'
import { getWindowsUtils } from './utils/windowsUtils'
import { ElectronSession } from './ElectronSession'
import { stat } from 'fs-extra'

class ElectronShell implements Shell {
showItemInFolder = shell.showItemInFolder
Expand Down Expand Up @@ -107,8 +109,41 @@ export default class ElectronLauncherApp extends LauncherApp {
app.commandLine?.appendSwitch('ozone-platform-hint', 'auto')
}

fetch: typeof fetch = (...args: any[]) => {
return net.fetch(args[0], args[1] ? { ...args[1], bypassCustomProtocolHandlers: true } : undefined) as any
fetch: typeof fetch = async (...args: any[]) => {
try {
return await net.fetch(args[0], args[1] ? { ...args[1], bypassCustomProtocolHandlers: true } : undefined) as any
} catch (e) {
if (e instanceof Error) {
let code: NetworkErrorCode | undefined
if (e.message === 'net::ERR_CONNECTION_CLOSED') {
code = NetworkErrorCode.CONNECTION_CLOSED
} else if (e.message === 'net::ERR_INTERNET_DISCONNECTED') {
code = NetworkErrorCode.INTERNET_DISCONNECTED
} else if (e.message === 'net::ERR_TIMED_OUT') {
code = NetworkErrorCode.TIMED_OUT
} else if (e.message === 'net::ERR_CONNECTION_RESET') {
code = NetworkErrorCode.CONNECTION_RESET
} else if (e.message === 'net::ERR_CONNECTION_TIMED_OUT') {
code = NetworkErrorCode.CONNECTION_TIMED_OUT
} else if (e.message === 'net::ERR_NAME_NOT_RESOLVED') {
code = NetworkErrorCode.DNS_NOTFOUND
} else if (e.message === 'net::NETWORK_CHANGED') {
code = NetworkErrorCode.NETWORK_CHANGED
}
if (code) {
// expected exceptions
throw new NetworkException({
type: 'networkException',
code,
})
}
// unexpected errors
if (e.message.startsWith('net::')) {
throw new AnyError('NetworkError', e.message)
}
}
throw e
}
}

windowsUtils = getWindowsUtils(this, this.logger)
Expand Down
2 changes: 1 addition & 1 deletion xmcl-electron-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@types/graceful-fs": "^4.1.5",
"@types/lodash.debounce": "^4.0.7",
"@types/lodash.throttle": "^4.1.7",
"@types/node": "~18",
"@types/node": "~20",
"@types/semver": "^7.3.13",
"@types/yauzl": "^2.10.0",
"@types/yazl": "^2.4.2",
Expand Down
Loading
Loading