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

feat: preference advanced show aria2 conf path #1440

Merged
merged 3 commits into from
Apr 23, 2023
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
14 changes: 11 additions & 3 deletions src/main/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 () {
Expand All @@ -42,6 +42,8 @@ export default class Application extends EventEmitter {
}

init () {
this.initContext()

this.initConfigManager()

this.initLocaleManager()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
})
Expand Down
6 changes: 1 addition & 5 deletions src/main/core/ConfigManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import Store from 'electron-store'

import {
getDhtPath,
getLogPath,
getSessionPath,
getUserDownloadsPath,
getMaxConnectionPerServer
} from '../utils/index'
Expand Down Expand Up @@ -70,7 +68,7 @@ export default class ConfigManager {
'max-connection-per-server': getMaxConnectionPerServer(),
'max-download-limit': 0,
'max-overall-download-limit': 0,
'max-overall-upload-limit': '1M',
'max-overall-upload-limit': 0,
'no-proxy': EMPTY_STRING,
'pause-metadata': false,
'pause': true,
Expand Down Expand Up @@ -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': [
Expand Down
36 changes: 36 additions & 0 deletions src/main/core/Context.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
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]
}
}
37 changes: 7 additions & 30 deletions src/main/core/Engine.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -26,7 +24,6 @@ export default class Engine {
this.i18n = getI18n()
this.systemConfig = options.systemConfig
this.userConfig = options.userConfig
this.basePath = this.getBasePath()
}

start () {
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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}`]
Expand Down
27 changes: 27 additions & 0 deletions src/main/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
11 changes: 11 additions & 0 deletions src/renderer/components/Preference/Advanced.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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
})
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/ar/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default {
'developer': 'المطور',
'user-agent': 'User-Agent',
'mock-user-agent': 'وكيل مستخدم وهمي',
'aria2-conf-path': 'مسار aria2.conf المدمج',
'app-log-path': 'مسار سجلات التطبيق',
'download-session-path': 'مسار التحميلات',
'session-reset': 'إعادة التحميل',
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/bg/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default {
'rpc-secret-tips': 'Гледайте инструкцията RPC Secret',
'developer':'developer',
'Mock-user-agent':'оформление User-Agent',
'aria2-conf-path': 'Вграден път за aria2.conf',
'app-log-path': 'път към дневника на приложението',
'download-session-path': 'качване на пътя на сесията',
'factory-reset': 'Настройки по подразбиране',
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/ca/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default {
'developer': 'Desenvolupador',
'user-agent': 'User-Agent',
'mock-user-agent': 'Mock User-Agent',
'aria2-conf-path': 'Ruta incorporada per al fitxer aria2.conf',
'app-log-path': 'Ruta del log',
'download-session-path': 'Ruta de descàrrega de la sessió',
'factory-reset': 'Reseteig de fàbrica',
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/de/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default {
'developer': 'Entwickler',
'user-agent': 'User-Agent',
'mock-user-agent': 'User-Agent simulieren',
'aria2-conf-path': 'Integrierter aria2.conf-Pfad',
'app-log-path': 'Appprotokollpfad',
'download-session-path': 'Downloadsitzungspfad',
'session-reset': 'Download-Session zurücksetzen',
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/el/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default {
'developer': 'Προγραμματιστής',
'user-agent': 'User-Agent',
'mock-user-agent': 'Πλαστό User-Agent',
'aria2-conf-path': 'Ενσωματωμένη διαδρομή aria2.conf',
'app-log-path': 'Διαδρομή για το αρχείο log της εφαρμογής',
'download-session-path': 'Διαδρομή λήψεων για αυτή τη συνεδρία',
'factory-reset': 'Επαναφορά στις εργοστασιακές ρυθμίσεις',
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/en-US/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default {
'developer': 'Developer',
'user-agent': 'User-Agent',
'mock-user-agent': 'Mock User-Agent',
'aria2-conf-path': 'Built-in aria2.conf path',
'app-log-path': 'App log path',
'download-session-path': 'Download session path',
'session-reset': 'Reset download session',
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/es/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default {
'developer': 'Desarrollador',
'user-agent': 'User-Agent',
'mock-user-agent': 'Falsear Agente de Usuario',
'aria2-conf-path': 'Ruta incorporada de aria2.conf',
'app-log-path': 'Ruta del registro',
'download-session-path': 'Ruta de descarga de la sesión',
'factory-reset': 'Restauración de fábrica',
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/fa/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default {
'developer': 'توسعه‌دهنده',
'user-agent': 'User-Agent',
'mock-user-agent': 'جعل عامل کاربر',
'aria2-conf-path': 'مسیر aria2.conf درونی',
'app-log-path': 'مسیر گزارش برنامه',
'download-session-path': 'مسیر نشست بارگیری',
'session-reset': 'بازنشانی نشست بارگیری',
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/fr/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default {
'developer': 'Développeur',
'user-agent': 'User-Agent',
'mock-user-agent': 'Mock User-Agent',
'aria2-conf-path': 'Chemin intégré de aria2.conf',
'app-log-path': 'Chemin des logs',
'download-session-path': 'Chemin de la session de téléchargement',
'factory-reset': 'Réinitialisation',
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/hu/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default {
'developer': 'feljesztö',
'user-agent': 'User-Agent',
'mock-user-agent': 'User-Agent-t',
'aria2-conf-path': 'Beépített aria2.conf útvonal',
'app-log-path': 'Alkalmazásnapló helye',
'download-session-path': 'Letöltés folyamat helye',
'factory-reset': 'Gyári viszaálitas',
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/id/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default {
'developer': 'Developer',
'user-agent': 'User-Agent',
'mock-user-agent': 'Mock User-Agent',
'aria2-conf-path': 'Jalur aria2.conf Bawaan',
'app-log-path': 'Lokasi Log Aplikasi',
'download-session-path': 'Lokasi Session Unduhan',
'factory-reset': 'Reset Pabrik',
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/it/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default {
'developer': 'Sviluppatore',
'user-agent': 'User-Agent',
'mock-user-agent': 'Cambia User-Agent',
'aria2-conf-path': 'Percorso incorporato di aria2.conf',
'app-log-path': 'Posizione log dell\'app',
'download-session-path': 'Posizione sessione di download',
'factory-reset': 'Reset di fabbrica',
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/ja/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default {
'developer': '開発者',
'user-agent': 'User-Agent',
'mock-user-agent': '偽装ユーザーエージェント(UA)',
'aria2-conf-path': '組み込みの aria2.conf パス',
'app-log-path': 'ログディレクトリを適用',
'download-session-path': 'セッションパスをダウンロード',
'factory-reset': '初期設定に戻す',
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/ko/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default {
'developer': '개발자',
'user-agent': 'User-Agent',
'mock-user-agent': '모의 사용자 에이전트',
'aria2-conf-path': '내장 된 aria2.conf 경로',
'app-log-path': '앱 로그 경로',
'download-session-path': '다운로드 세션 경로',
'session-reset': '다운로드 세션 초기화',
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/nb/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default {
'developer': 'Utvikler',
'user-agent': 'User-Agent',
'mock-user-agent': 'Mock User-Agent',
'aria2-conf-path': 'Innebygd aria2.conf-sti',
'app-log-path': 'Apploggbane',
'download-session-path': 'Last ned øktstien',
'session-reset': 'Tilbakestill nedlastingsøkten',
Expand Down
1 change: 1 addition & 0 deletions src/shared/locales/nl/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default {
'developer': 'Ontwikkelaar',
'user-agent': 'User-Agent',
'mock-user-agent': 'User-Agent nabootsen',
'aria2-conf-path': 'Ingebed pad voor aria2.conf',
'app-log-path': 'Applicatie log pad',
'download-session-path': 'Downloadsessie pad',
'session-reset': 'Reset download sessie',
Expand Down
Loading