feat: preference advanced show aria2 conf path

This commit is contained in:
Dr_rOot
2023-04-23 18:16:44 +08:00
parent 363cef2959
commit f4e56ca4b7
6 changed files with 93 additions and 38 deletions
+11 -3
View File
@@ -17,6 +17,7 @@ import {
reduceTrackerString
} from '@shared/utils/tracker'
import logger from './core/Logger'
import Context from './core/Context'
import ConfigManager from './core/ConfigManager'
import { setupLocaleManager } from './ui/Locale'
import Engine from './core/Engine'
@@ -32,7 +33,6 @@ import TouchBarManager from './ui/TouchBarManager'
import TrayManager from './ui/TrayManager'
import DockManager from './ui/DockManager'
import ThemeManager from './ui/ThemeManager'
import { getSessionPath } from './utils'
export default class Application extends EventEmitter {
constructor () {
@@ -42,6 +42,8 @@ export default class Application extends EventEmitter {
}
init () {
this.initContext()
this.initConfigManager()
this.initLocaleManager()
@@ -83,6 +85,10 @@ export default class Application extends EventEmitter {
this.emit('application:initialized')
}
initContext () {
this.context = new Context()
}
initConfigManager () {
this.configListeners = {}
this.configManager = new ConfigManager()
@@ -644,7 +650,7 @@ export default class Application extends EventEmitter {
app.clearRecentDocuments()
const sessionPath = this.configManager.getUserConfig('session-path') || getSessionPath()
const sessionPath = this.context.get('session-path')
setTimeout(() => {
unlink(sessionPath, function (err) {
logger.info('[Motrix] Removed the download seesion file:', err)
@@ -874,10 +880,12 @@ export default class Application extends EventEmitter {
ipcMain.handle('get-app-config', async () => {
const systemConfig = this.configManager.getSystemConfig()
const userConfig = this.configManager.getUserConfig()
const context = this.context.get()
const result = {
...systemConfig,
...userConfig
...userConfig,
...context
}
return result
})
-4
View File
@@ -4,8 +4,6 @@ import Store from 'electron-store'
import {
getDhtPath,
getLogPath,
getSessionPath,
getUserDownloadsPath,
getMaxConnectionPerServer
} from '../utils/index'
@@ -113,14 +111,12 @@ export default class ConfigManager {
'last-check-update-time': 0,
'last-sync-tracker-time': 0,
'locale': app.getLocale(),
'log-path': getLogPath(),
'new-task-show-downloading': true,
'no-confirm-before-delete-task': false,
'open-at-login': false,
'protocols': { 'magnet': true, 'thunder': false },
'resume-all-when-app-launched': false,
'run-mode': APP_RUN_MODE.STANDARD,
'session-path': getSessionPath(),
'task-notification': true,
'theme': APP_THEME.AUTO,
'tracker-source': [
+37 -1
View File
@@ -1,3 +1,39 @@
export default class Context {
import logger from './Logger'
import {
getEnginePath,
getAria2BinPath,
getAria2ConfPath,
getLogPath,
getSessionPath
} from '../utils'
const { platform, arch } = process
export default class Context {
constructor () {
this.init()
}
init () {
// The key of Context cannot be the same as that of userConfig and systemConfig.
this.context = {
platform: platform,
arch: arch,
'log-path': getLogPath(),
'session-path': getSessionPath(),
'engine-path': getEnginePath(platform, arch),
'aria2-bin-path': getAria2BinPath(platform, arch),
'aria2-conf-path': getAria2ConfPath(platform, arch)
}
logger.info('[Motrix] Context.init===>', this.context)
}
get (key) {
if (typeof key === 'undefined') {
return this.context
}
return this.context[key]
}
}
+7 -30
View File
@@ -1,15 +1,13 @@
import { app } from 'electron'
import is from 'electron-is'
import { existsSync, writeFile, unlink } from 'fs'
import { resolve, join } from 'path'
import { spawn } from 'child_process'
import logger from './Logger'
import { getI18n } from '../ui/Locale'
import {
getEngineBin,
getEngineArch,
getEnginePidPath,
getAria2BinPath,
getAria2ConfPath,
getSessionPath,
transformConfig
} from '../utils/index'
@@ -26,7 +24,6 @@ export default class Engine {
this.i18n = getI18n()
this.systemConfig = options.systemConfig
this.userConfig = options.userConfig
this.basePath = this.getBasePath()
}
start () {
@@ -37,7 +34,7 @@ export default class Engine {
return
}
const binPath = this.getBinPath()
const binPath = this.getEngineBinPath()
const args = this.getStartArgs()
this.instance = spawn(binPath, args, {
windowsHide: false,
@@ -84,13 +81,8 @@ export default class Engine {
})
}
getBinPath () {
const binName = getEngineBin(platform)
if (!binName) {
throw new Error(this.i18n.t('app.engine-damaged-message'))
}
const result = join(this.basePath, `/engine/${binName}`)
getEngineBinPath () {
const result = getAria2BinPath(platform, arch)
const binIsExist = existsSync(result)
if (!binIsExist) {
logger.error('[Motrix] engine bin is not exist:', result)
@@ -100,25 +92,10 @@ export default class Engine {
return result
}
getBasePath () {
const result = is.dev()
? this.getDevBasePath()
: resolve(app.getAppPath(), '..')
return result
}
getDevBasePath () {
const ah = getEngineArch(platform, arch)
const base = `../../../extra/${platform}/${ah}`
const result = resolve(__dirname, base)
return result
}
getStartArgs () {
const confPath = join(this.basePath, '/engine/aria2.conf')
const confPath = getAria2ConfPath(platform, arch)
const sessionPath = this.userConfig['session-path'] || getSessionPath()
const sessionPath = getSessionPath()
const sessionIsExist = existsSync(sessionPath)
let result = [`--conf-path=${confPath}`, `--save-session=${sessionPath}`]
+27
View File
@@ -49,6 +49,33 @@ export function getEngineArch (platform, arch) {
return result
}
export const getDevEnginePath = (platform, arch) => {
const ah = getEngineArch(platform, arch)
const base = `../../../extra/${platform}/${ah}/engine`
const result = resolve(__dirname, base)
return result
}
export const getProdEnginePath = () => {
return resolve(app.getAppPath(), '../engine')
}
export const getEnginePath = (platform, arch) => {
return is.dev() ? getDevEnginePath(platform, arch) : getProdEnginePath()
}
export const getAria2BinPath = (platform, arch) => {
const base = getEnginePath(platform, arch)
const binName = getEngineBin(platform)
const result = resolve(base, `./${binName}`)
return result
}
export const getAria2ConfPath = (platform, arch) => {
const base = getEnginePath(platform, arch)
return resolve(base, './aria2.conf')
}
export function transformConfig (config) {
const result = []
for (const [k, v] of Object.entries(config)) {
@@ -348,6 +348,16 @@
:label="`${$t('preferences.developer')}: `"
:label-width="formLabelWidth"
>
<el-col class="form-item-sub" :span="24">
{{ $t('preferences.aria2-conf-path') }}
<el-input placeholder="" disabled v-model="aria2ConfPath">
<mo-show-in-folder
slot="append"
v-if="isRenderer"
:path="aria2ConfPath"
/>
</el-input>
</el-col>
<el-col class="form-item-sub" :span="24">
{{ $t('preferences.app-log-path') }}
<el-input placeholder="" disabled v-model="logPath">
@@ -520,6 +530,7 @@
},
...mapState('preference', {
config: state => state.config,
aria2ConfPath: state => state.config.aria2ConfPath,
logPath: state => state.config.logPath,
sessionPath: state => state.config.sessionPath
})