|
25 | 25 | <mo-theme-switcher
|
26 | 26 | v-model="form.theme"
|
27 | 27 | @change="handleThemeChange"
|
| 28 | + ref="themeSwitcher" |
28 | 29 | />
|
29 | 30 | </el-col>
|
30 | 31 | <el-col v-if="showHideAppMenuOption" class="form-item-sub" :span="16">
|
|
256 | 257 |
|
257 | 258 | <script>
|
258 | 259 | import is from 'electron-is'
|
| 260 | + import { dialog } from '@electron/remote' |
259 | 261 | import { mapState } from 'vuex'
|
260 |
| - import { cloneDeep } from 'lodash' |
| 262 | + import { cloneDeep, extend, isEmpty } from 'lodash' |
261 | 263 | import SubnavSwitcher from '@/components/Subnav/SubnavSwitcher'
|
262 | 264 | import SelectDirectory from '@/components/Native/SelectDirectory'
|
263 | 265 | import ThemeSwitcher from '@/components/Preference/ThemeSwitcher'
|
264 | 266 | import { availableLanguages, getLanguage } from '@shared/locales'
|
265 | 267 | import { getLocaleManager } from '@/components/Locale'
|
266 | 268 | import {
|
| 269 | + backupConfig, |
267 | 270 | calcFormLabelWidth,
|
| 271 | + changedConfig, |
268 | 272 | checkIsNeedRestart,
|
| 273 | + convertLineToComma, |
269 | 274 | diffConfig
|
270 | 275 | } from '@shared/utils'
|
271 | 276 | import { APP_RUN_MODE } from '@shared/constants'
|
| 277 | + import { reduceTrackerString } from '@shared/utils/tracker' |
272 | 278 |
|
273 | 279 | const initForm = (config) => {
|
274 | 280 | const {
|
|
338 | 344 | },
|
339 | 345 | data () {
|
340 | 346 | const { locale } = this.$store.state.preference.config
|
341 |
| - const form = initForm(this.$store.state.preference.config) |
342 |
| - const formOriginal = cloneDeep(form) |
| 347 | + const formOriginal = initForm(this.$store.state.preference.config) |
| 348 | + let form = {} |
| 349 | + form = initForm(extend(form, formOriginal, changedConfig.basic)) |
| 350 | +
|
| 351 | + if (backupConfig.theme === undefined) { |
| 352 | + backupConfig.theme = formOriginal.theme |
| 353 | + } else { |
| 354 | + formOriginal.theme = backupConfig.theme |
| 355 | + } |
| 356 | + backupConfig.locale = formOriginal.locale |
343 | 357 |
|
344 | 358 | return {
|
345 | 359 | form,
|
|
480 | 494 | return false
|
481 | 495 | }
|
482 | 496 |
|
483 |
| - const { btAutoDownloadContent, runMode, openAtLogin, autoHideWindow } = this.form |
484 |
| - const changed = diffConfig(this.formOriginal, this.form) |
485 | 497 | const data = {
|
486 |
| - ...changed |
| 498 | + ...diffConfig(this.formOriginal, this.form), |
| 499 | + ...changedConfig.advanced |
487 | 500 | }
|
488 |
| - if ('btAutoDownloadContent' in changed) { |
| 501 | +
|
| 502 | + const { btAutoDownloadContent, runMode, openAtLogin, autoHideWindow, btTracker, noProxy } = data |
| 503 | +
|
| 504 | + if ('btAutoDownloadContent' in data) { |
489 | 505 | data.pauseMetadata = !btAutoDownloadContent
|
490 | 506 | data.followMetalink = btAutoDownloadContent
|
491 | 507 | data.followTorrent = btAutoDownloadContent
|
492 | 508 | }
|
| 509 | +
|
| 510 | + if (btTracker) { |
| 511 | + data.btTracker = reduceTrackerString(convertLineToComma(btTracker)) |
| 512 | + } |
| 513 | +
|
| 514 | + if (noProxy) { |
| 515 | + data.noProxy = convertLineToComma(noProxy) |
| 516 | + } |
| 517 | +
|
493 | 518 | console.log('[Motrix] preference changed data:', data)
|
494 | 519 |
|
495 | 520 | this.$store.dispatch('preference/save', data)
|
|
502 | 527 | this.$msg.success(this.$t('preferences.save-fail-message'))
|
503 | 528 | })
|
504 | 529 |
|
| 530 | + changedConfig.basic = {} |
| 531 | + changedConfig.advanced = {} |
| 532 | +
|
505 | 533 | if (this.isRenderer) {
|
506 | 534 | this.$electron.ipcRenderer.send('command',
|
507 | 535 | 'application:open-at-login', openAtLogin)
|
508 | 536 |
|
509 |
| - if ('runMode' in changed) { |
| 537 | + if ('runMode' in data) { |
510 | 538 | this.$electron.ipcRenderer.send('command',
|
511 | 539 | 'application:toggle-dock', runMode === APP_RUN_MODE.STANDARD)
|
512 | 540 | }
|
513 | 541 |
|
514 |
| - if ('autoHideWindow' in changed) { |
| 542 | + if ('autoHideWindow' in data) { |
515 | 543 | this.$electron.ipcRenderer.send('command',
|
516 | 544 | 'application:auto-hide-window', autoHideWindow)
|
517 | 545 | }
|
|
520 | 548 | this.$electron.ipcRenderer.send('command',
|
521 | 549 | 'application:relaunch')
|
522 | 550 | }
|
| 551 | +
|
| 552 | + this.$electron.ipcRenderer.send('command', |
| 553 | + 'application:setup-protocols-client', data.protocols) |
| 554 | +
|
| 555 | + if (checkIsNeedRestart(data)) { |
| 556 | + this.$electron.ipcRenderer.send('command', 'application:relaunch') |
| 557 | + } |
523 | 558 | }
|
524 | 559 | })
|
525 | 560 | },
|
526 | 561 | resetForm (formName) {
|
| 562 | + this.$refs.themeSwitcher.currentValue = backupConfig.theme |
| 563 | + this.handleLocaleChange(this.formOriginal.locale) |
527 | 564 | this.syncFormConfig()
|
528 | 565 | }
|
| 566 | + }, |
| 567 | + beforeRouteLeave (to, from, next) { |
| 568 | + changedConfig.basic = diffConfig(this.formOriginal, this.form) |
| 569 | + if (to.path === '/preference/advanced') { |
| 570 | + next() |
| 571 | + } else { |
| 572 | + if (isEmpty(changedConfig.basic) && isEmpty(changedConfig.advanced)) { |
| 573 | + next() |
| 574 | + } else { |
| 575 | + dialog.showMessageBox({ |
| 576 | + type: 'warning', |
| 577 | + title: this.$t('preferences.not-saved'), |
| 578 | + message: this.$t('preferences.not-saved-confirm'), |
| 579 | + buttons: [this.$t('app.yes'), this.$t('app.no')], |
| 580 | + cancelId: 1 |
| 581 | + }).then(({ response }) => { |
| 582 | + if (response === 0) { |
| 583 | + if (changedConfig.basic.theme !== undefined) { |
| 584 | + this.$electron.ipcRenderer.send('command', |
| 585 | + 'application:change-theme', backupConfig.theme) |
| 586 | + } |
| 587 | + if (changedConfig.basic.locale !== undefined) { |
| 588 | + this.handleLocaleChange(this.formOriginal.locale) |
| 589 | + } |
| 590 | + changedConfig.basic = {} |
| 591 | + changedConfig.advanced = {} |
| 592 | + backupConfig.theme = undefined |
| 593 | + next() |
| 594 | + } |
| 595 | + }) |
| 596 | + } |
| 597 | + } |
529 | 598 | }
|
530 | 599 | }
|
531 | 600 | </script>
|
0 commit comments