diff --git a/src/renderer/components/Preference/Advanced.vue b/src/renderer/components/Preference/Advanced.vue index c0c5700c1..446f70e6c 100644 --- a/src/renderer/components/Preference/Advanced.vue +++ b/src/renderer/components/Preference/Advanced.vue @@ -371,16 +371,18 @@ import is from 'electron-is' import { dialog } from '@electron/remote' import { mapState } from 'vuex' - import { cloneDeep } from 'lodash' + import { cloneDeep, extend, isEmpty } from 'lodash' import randomize from 'randomatic' import * as clipboard from 'clipboard-polyfill' import ShowInFolder from '@/components/Native/ShowInFolder' import SubnavSwitcher from '@/components/Subnav/SubnavSwitcher' import userAgentMap from '@shared/ua' - import { trackerSourceOptions } from '@shared/constants' + import { APP_RUN_MODE, trackerSourceOptions } from '@shared/constants' import { + backupConfig, buildRpcUrl, calcFormLabelWidth, + changedConfig, checkIsNeedRestart, convertCommaToLine, convertLineToComma, @@ -391,6 +393,8 @@ import '@/components/Icons/dice' import '@/components/Icons/sync' import '@/components/Icons/refresh' + import { getLanguage } from '@shared/locales' + import { getLocaleManager } from '@/components/Locale' const initForm = (config) => { const { @@ -446,8 +450,9 @@ }, data () { const { locale } = this.$store.state.preference.config - const form = initForm(this.$store.state.preference.config) - const formOriginal = cloneDeep(form) + const formOriginal = initForm(this.$store.state.preference.config) + let form = {} + form = initForm(extend(form, formOriginal, changedConfig.advanced)) return { form, @@ -594,6 +599,10 @@ .then((config) => { this.form = initForm(config) this.formOriginal = cloneDeep(this.form) + if (changedConfig.basic.theme !== undefined) { + this.$electron.ipcRenderer.send('command', + 'application:change-theme', changedConfig.basic.theme) + } }) }, submitForm (formName) { @@ -603,15 +612,19 @@ return false } - const changed = diffConfig(this.formOriginal, this.form) const data = { - ...changed, - protocols: { - ...this.form.protocols - } + ...diffConfig(this.formOriginal, this.form), + ...changedConfig.basic + } + + const { btAutoDownloadContent, runMode, openAtLogin, autoHideWindow, btTracker, noProxy } = data + + if ('btAutoDownloadContent' in data) { + data.pauseMetadata = !btAutoDownloadContent + data.followMetalink = btAutoDownloadContent + data.followTorrent = btAutoDownloadContent } - const { btTracker, noProxy } = changed if (btTracker) { data.btTracker = reduceTrackerString(convertLineToComma(btTracker)) } @@ -632,7 +645,28 @@ this.$msg.success(this.$t('preferences.save-fail-message')) }) + changedConfig.basic = {} + changedConfig.advanced = {} + if (this.isRenderer) { + this.$electron.ipcRenderer.send('command', + 'application:open-at-login', openAtLogin) + + if ('runMode' in data) { + this.$electron.ipcRenderer.send('command', + 'application:toggle-dock', runMode === APP_RUN_MODE.STANDARD) + } + + if ('autoHideWindow' in data) { + this.$electron.ipcRenderer.send('command', + 'application:auto-hide-window', autoHideWindow) + } + + if (checkIsNeedRestart(data)) { + this.$electron.ipcRenderer.send('command', + 'application:relaunch') + } + this.$electron.ipcRenderer.send('command', 'application:setup-protocols-client', data.protocols) @@ -645,6 +679,41 @@ resetForm (formName) { this.syncFormConfig() } + }, + beforeRouteLeave (to, from, next) { + changedConfig.advanced = diffConfig(this.formOriginal, this.form) + if (to.path === '/preference/basic') { + next() + } else { + if (isEmpty(changedConfig.basic) && isEmpty(changedConfig.advanced)) { + next() + } else { + dialog.showMessageBox({ + type: 'warning', + title: this.$t('preferences.not-saved'), + message: this.$t('preferences.not-saved-confirm'), + buttons: [this.$t('app.yes'), this.$t('app.no')], + cancelId: 1 + }).then(({ response }) => { + if (response === 0) { + if (changedConfig.basic.theme !== undefined) { + this.$electron.ipcRenderer.send('command', + 'application:change-theme', backupConfig.theme) + } + if (changedConfig.basic.locale !== undefined) { + const lng = getLanguage(backupConfig.locale) + getLocaleManager().changeLanguage(lng) + this.$electron.ipcRenderer.send('command', + 'application:change-locale', lng) + } + changedConfig.basic = {} + changedConfig.advanced = {} + backupConfig.theme = undefined + next() + } + }) + } + } } } diff --git a/src/renderer/components/Preference/Basic.vue b/src/renderer/components/Preference/Basic.vue index 1a810b155..2d8cc7983 100644 --- a/src/renderer/components/Preference/Basic.vue +++ b/src/renderer/components/Preference/Basic.vue @@ -25,6 +25,7 @@ @@ -256,19 +257,24 @@ diff --git a/src/shared/locales/ar/preferences.js b/src/shared/locales/ar/preferences.js index a8a45b879..78c9005c5 100644 --- a/src/shared/locales/ar/preferences.js +++ b/src/shared/locales/ar/preferences.js @@ -78,5 +78,7 @@ export default { 'baidu-exporter-help': 'اضغط هنا لبدء الاستخدام', 'auto-update': 'التحديث التلقائي', 'auto-check-update': 'تحقق تلقائيًا من التحديث', - 'last-check-update-time': 'آخر مرة تم التحقق من وجود تحديثات' + 'last-check-update-time': 'آخر مرة تم التحقق من وجود تحديثات', + 'not-saved': 'التفضيلات غير محفوظة', + 'not-saved-confirm': 'ستفقد التفضيلات التي تم تغييرها ، هل أنت متأكد من المغادرة؟' } diff --git a/src/shared/locales/bg/preferences.js b/src/shared/locales/bg/preferences.js index 0c1c94475..be53253f4 100644 --- a/src/shared/locales/bg/preferences.js +++ b/src/shared/locales/bg/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': 'Кликнете тук, за да използвате', 'auto-update':'автоматично обновяване', 'auto-check-update':'автоматична проверка на актуализациите', - 'last-check-update-time': 'последната актуализация е проверена' + 'last-check-update-time': 'последната актуализация е проверена', + 'not-saved': 'Предпочитанията не са запазени', + 'not-saved-confirm': 'Променените предпочитания ще бъдат загубени, сигурни ли сте, че ще напуснете?' } diff --git a/src/shared/locales/ca/preferences.js b/src/shared/locales/ca/preferences.js index 08dcbd3d3..855493b47 100644 --- a/src/shared/locales/ca/preferences.js +++ b/src/shared/locales/ca/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': 'Fes click aquí per veure l\'ús', 'auto-update': 'Actualitzar automàticament', 'auto-check-update': 'Revisar actualitzacions automàticament', - 'last-check-update-time': 'Última revisió d\'actualitzacions' + 'last-check-update-time': 'Última revisió d\'actualitzacions', + 'not-saved': 'Preferències no desades', + 'not-saved-confirm': 'Les preferències modificades es perdran, esteu segur que marxareu?' } diff --git a/src/shared/locales/de/preferences.js b/src/shared/locales/de/preferences.js index 3b523ae5e..ac560e667 100644 --- a/src/shared/locales/de/preferences.js +++ b/src/shared/locales/de/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': 'mehr über die Verwendung zu erfahren', 'auto-update': 'Auto-Update', 'auto-check-update': 'Automatische Updates überprüfen', - 'last-check-update-time': 'letzte kontrolle update - zeit' + 'last-check-update-time': 'letzte kontrolle update - zeit', + 'not-saved': 'Einstellungen nicht gespeichert', + 'not-saved-confirm': 'Die geänderten Einstellungen gehen verloren. Möchten Sie wirklich gehen?' } diff --git a/src/shared/locales/el/preferences.js b/src/shared/locales/el/preferences.js index ea60c64bd..760fdc837 100644 --- a/src/shared/locales/el/preferences.js +++ b/src/shared/locales/el/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': 'Κάντε κλικ εδώ για χρήση', 'auto-update': 'Αυτόματη ενημέρωση', 'auto-check-update': 'Αυτόματος έλεγχος για ενημερώσεις', - 'last-check-update-time': 'Τελευταία φορά που έγινε έλεγχος για Ενημερώσεις' + 'last-check-update-time': 'Τελευταία φορά που έγινε έλεγχος για Ενημερώσεις', + 'not-saved': 'Οι προτιμήσεις δεν αποθηκεύτηκαν', + 'not-saved-confirm': 'Οι αλλαγμένες προτιμήσεις θα χαθούν, είστε σίγουροι ότι θα φύγετε;' } diff --git a/src/shared/locales/en-US/preferences.js b/src/shared/locales/en-US/preferences.js index e6d955952..c4d51bcc8 100644 --- a/src/shared/locales/en-US/preferences.js +++ b/src/shared/locales/en-US/preferences.js @@ -78,5 +78,7 @@ export default { 'baidu-exporter-help': 'Click here for usage', 'auto-update': 'Auto Update', 'auto-check-update': 'Automatically check for update', - 'last-check-update-time': 'Last Time Checking for Update' + 'last-check-update-time': 'Last Time Checking for Update', + 'not-saved': 'Preferences not saved', + 'not-saved-confirm': 'The modified preferences will be lost, are you sure to leave?' } diff --git a/src/shared/locales/es/preferences.js b/src/shared/locales/es/preferences.js index 140e580a7..a22d3f7aa 100644 --- a/src/shared/locales/es/preferences.js +++ b/src/shared/locales/es/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': 'Presiona aqui para ver el uso', 'auto-update': 'Auto-actualizar', 'auto-check-update': 'Revisar automáticamente por actualizaciones', - 'last-check-update-time': 'Última revisión de actualizaciones' + 'last-check-update-time': 'Última revisión de actualizaciones', + 'not-saved': 'Preferencias no guardadas', + 'not-saved-confirm': 'Las preferencias cambiadas se perderán, ¿está seguro de irse?' } diff --git a/src/shared/locales/fa/preferences.js b/src/shared/locales/fa/preferences.js index d4dda08f6..4677df4b7 100644 --- a/src/shared/locales/fa/preferences.js +++ b/src/shared/locales/fa/preferences.js @@ -78,5 +78,7 @@ export default { 'baidu-exporter-help': 'برای استفاده اینجا کلیک کنید', 'auto-update': 'به‌روز رسانی خودکار', 'auto-check-update': 'به صورت خودکار برای به‌روز رسانی بررسی کن', - 'last-check-update-time': 'آخرین زمان بررسی برای به‌روز رسانی' + 'last-check-update-time': 'آخرین زمان بررسی برای به‌روز رسانی', + 'not-saved': 'تنظیمات برگزیده ذخیره نشد', + 'not-saved-confirm': 'تنظیمات برگزیده تغییر یافته از بین خواهند رفت، آیا مطمئن هستید که می روید؟' } diff --git a/src/shared/locales/fr/preferences.js b/src/shared/locales/fr/preferences.js index ee7830130..30dfc1a3f 100644 --- a/src/shared/locales/fr/preferences.js +++ b/src/shared/locales/fr/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': 'Cliquez ici pour voir l\'utilisation', 'auto-update': 'Mettre à jour', 'auto-check-update': 'Mise à jour automatique', - 'last-check-update-time': 'dernier contrôle la mise à jour du temps' + 'last-check-update-time': 'dernier contrôle la mise à jour du temps', + 'not-saved': 'Préférences non enregistrées', + 'not-saved-confirm': 'Les préférences modifiées seront perdues, êtes-vous sûr de partir ?' } diff --git a/src/shared/locales/hu/preferences.js b/src/shared/locales/hu/preferences.js index 8235aabe8..b15df6155 100644 --- a/src/shared/locales/hu/preferences.js +++ b/src/shared/locales/hu/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': 'Kattincs ide a hasznalati naplohoz', 'auto-update': 'Automatikus frissités', 'auto-check-update': 'Automatikus keresen frissitéseket', - 'last-check-update-time': 'Legutolsó frissités:' + 'last-check-update-time': 'Legutolsó frissités:', + 'not-saved': 'A beállítások nincsenek mentve', + 'not-saved-confirm': 'A megváltozott beállítások elvesznek. Biztosan kilép?' } diff --git a/src/shared/locales/id/preferences.js b/src/shared/locales/id/preferences.js index f47d456a0..02ec59c0b 100644 --- a/src/shared/locales/id/preferences.js +++ b/src/shared/locales/id/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': 'Klik di sini untuk penggunaan', 'auto-update': 'Pembaruan Otomatis', 'auto-check-update': 'Secara otomatis memeriksa pembaruan', - 'last-check-update-time': 'Terakhir Kali Memeriksa Pembaruan' + 'last-check-update-time': 'Terakhir Kali Memeriksa Pembaruan', + 'not-saved': 'Preferensi tidak disimpan', + 'not-saved-confirm': 'Preferensi yang dimodifikasi akan hilang, apakah Anda yakin untuk keluar?' } diff --git a/src/shared/locales/it/preferences.js b/src/shared/locales/it/preferences.js index 7eef57528..f171e0c37 100644 --- a/src/shared/locales/it/preferences.js +++ b/src/shared/locales/it/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': 'Clicca qui per scoprire il funzionamento', 'auto-update': 'Auto Update', 'auto-check-update': 'Verifica automaticamente la disponibilità di aggiornamenti', - 'last-check-update-time': 'Ultima volta quando gli aggiornamenti sono stati verificati' + 'last-check-update-time': 'Ultima volta quando gli aggiornamenti sono stati verificati', + 'not-saved': 'Preferenze non salvate', + 'not-saved-confirm': 'Le preferenze modificate andranno perse, sei sicuro di uscire?' } diff --git a/src/shared/locales/ja/preferences.js b/src/shared/locales/ja/preferences.js index 40935a97d..a8e92ded7 100644 --- a/src/shared/locales/ja/preferences.js +++ b/src/shared/locales/ja/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': 'ここをクリックし使用説明を見る', 'auto-update': '自動更新', 'auto-check-update': '更新を自動で確認する', - 'last-check-update-time': '前回更新確認時間' + 'last-check-update-time': '前回更新確認時間', + 'not-saved': '設定が保存されていません', + 'not-saved-confirm': '変更された設定は失われます、よろしいですか?' } diff --git a/src/shared/locales/ko/preferences.js b/src/shared/locales/ko/preferences.js index f2b2944a3..606d406ad 100644 --- a/src/shared/locales/ko/preferences.js +++ b/src/shared/locales/ko/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': '사용법을 보려면 여기를 클릭하십시오.', 'auto-update': '자동 업데이트', 'auto-check-update': '업데이트 자동 확인', - 'last-check-update-time': '마지막 업데이트 확인 시간' + 'last-check-update-time': '마지막 업데이트 확인 시간', + 'not-saved': '환경설정이 저장되지 않았습니다', + 'not-saved-confirm': '수정된 기본 설정이 손실됩니다. 나가시겠습니까?' } diff --git a/src/shared/locales/nb/preferences.js b/src/shared/locales/nb/preferences.js index 5ca4cd44b..4ef8d7791 100644 --- a/src/shared/locales/nb/preferences.js +++ b/src/shared/locales/nb/preferences.js @@ -78,5 +78,7 @@ export default { 'baidu-exporter-help': 'Klikk her for bruk', 'auto-update': 'Automatisk oppdatering', 'auto-check-update': 'Sjekk automatisk for oppdatering', - 'last-check-update-time': 'Siste gang sjekket for oppdatering' + 'last-check-update-time': 'Siste gang sjekket for oppdatering', + 'not-saved': 'Preferansene er ikke lagret', + 'not-saved-confirm': 'De endrede preferansene vil gå tapt, er du sikker på at du vil forlate?' } diff --git a/src/shared/locales/pl/preferences.js b/src/shared/locales/pl/preferences.js index 2acec2202..b4631ad3f 100644 --- a/src/shared/locales/pl/preferences.js +++ b/src/shared/locales/pl/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': 'Naciśnij tutaj po pomoc', 'auto-update': 'Aktualizuj automatycznie', 'auto-check-update': 'Automatycznie sprawdzaj aktualizacje', - 'last-check-update-time': 'Ostatni raz kiedy sprawdzono aktualizację' + 'last-check-update-time': 'Ostatni raz kiedy sprawdzono aktualizację', + 'not-saved': 'Preferencje nie zostały zapisane', + 'not-saved-confirm': 'Zmienione preferencje zostaną utracone, czy na pewno chcesz wyjść?' } diff --git a/src/shared/locales/pt-BR/preferences.js b/src/shared/locales/pt-BR/preferences.js index b7d425891..069cc60e4 100644 --- a/src/shared/locales/pt-BR/preferences.js +++ b/src/shared/locales/pt-BR/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': 'Clique aqui ver as instruções de uso', 'auto-update': 'Atualização automática', 'auto-check-update': 'A verificação automática de atualizações', - 'last-check-update-time': 'última verificação do tempo de atualização' + 'last-check-update-time': 'última verificação do tempo de atualização', + 'not-saved': 'Preferências não salvas', + 'not-saved-confirm': 'As preferências modificadas serão perdidas. Tem certeza de que deseja sair?' } diff --git a/src/shared/locales/ro/preferences.js b/src/shared/locales/ro/preferences.js index 7aa51a7b6..042aa32b9 100644 --- a/src/shared/locales/ro/preferences.js +++ b/src/shared/locales/ro/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': 'Faceți clic aici pentru instrucțiuni', 'auto-update': 'Actualizare automată', 'auto-check-update': 'Verificați automat dacă sunt disponibile actualizări', - 'last-check-update-time': 'Ultima dată când au fost verificate actualizările disponibile' + 'last-check-update-time': 'Ultima dată când au fost verificate actualizările disponibile', + 'not-saved': 'Preferințele nu au fost salvate', + 'not-saved-confirm': 'Preferințele modificate se vor pierde, sunteți sigur că plecați?' } diff --git a/src/shared/locales/ru/preferences.js b/src/shared/locales/ru/preferences.js index 8c522e621..8440c8002 100644 --- a/src/shared/locales/ru/preferences.js +++ b/src/shared/locales/ru/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': 'Нажмите здесь для использования', 'auto-update': 'Автоматическое обновление', 'auto-check-update': 'Автоматически проверять обновления', - 'last-check-update-time': 'Последняя проверка на обновления прошла в' + 'last-check-update-time': 'Последняя проверка на обновления прошла в', + 'not-saved': 'Настройки не сохранены', + 'not-saved-confirm': 'Измененные настройки будут потеряны, вы обязательно уйдете?' } diff --git a/src/shared/locales/tr/preferences.js b/src/shared/locales/tr/preferences.js index 18cd44f57..219713b19 100644 --- a/src/shared/locales/tr/preferences.js +++ b/src/shared/locales/tr/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': 'Kullanım detayları için buraya tıklayın', 'auto-update': 'Otomatik güncelleme', 'auto-check-update': 'Otomatik Kontrol Güncellemesi', - 'last-check-update-time': 'Son Kontrol Güncelleme Saati' + 'last-check-update-time': 'Son Kontrol Güncelleme Saati', + 'not-saved': 'Tercihler kaydedilmedi', + 'not-saved-confirm': 'Değiştirilen tercihler kaybolacak, ayrılacağınızdan emin misiniz?' } diff --git a/src/shared/locales/uk/preferences.js b/src/shared/locales/uk/preferences.js index 4b8a06f66..386cbb890 100644 --- a/src/shared/locales/uk/preferences.js +++ b/src/shared/locales/uk/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': 'Натисніть тут для використання', 'auto-update': 'Автоматичне оновлення', 'auto-check-update': 'Автоматично перевіряти оновлення', - 'last-check-update-time': 'В останнє оновлення перевірялось' + 'last-check-update-time': 'В останнє оновлення перевірялось', + 'not-saved': 'Налаштування не збережено', + 'not-saved-confirm': 'Змінені параметри буде втрачено. Ви впевнені, що залишите?' } diff --git a/src/shared/locales/vi/preferences.js b/src/shared/locales/vi/preferences.js index 2b826c670..95f8c82f5 100644 --- a/src/shared/locales/vi/preferences.js +++ b/src/shared/locales/vi/preferences.js @@ -77,5 +77,7 @@ export default { 'baidu-exporter-help': 'Nhấn vào đây để sử dụng', 'auto-update': 'Tự động cập nhật', 'auto-check-update': 'Tự động kiểm tra cập nhật', - 'last-check-update-time': 'Kiểm tra cập nhật lần cuối' + 'last-check-update-time': 'Kiểm tra cập nhật lần cuối', + 'not-saved': 'Tùy chọn không được lưu', + 'not-saved-confirm': 'Các tùy chọn đã sửa đổi sẽ bị mất, bạn có chắc chắn thoát không?' } diff --git a/src/shared/locales/zh-CN/preferences.js b/src/shared/locales/zh-CN/preferences.js index ac7ed7965..1c7111ab8 100644 --- a/src/shared/locales/zh-CN/preferences.js +++ b/src/shared/locales/zh-CN/preferences.js @@ -80,5 +80,7 @@ export default { 'auto-check-update': '自动检查更新', 'last-check-update-time': '上次检查更新时间', 'follow-metalink': '自动开始下载磁力链接、种子内的文件', - 'follow-torrent': '种子下载完后自动下载种子内容' + 'follow-torrent': '种子下载完后自动下载种子内容', + 'not-saved': '设置未保存', + 'not-saved-confirm': '已修改的设置将会丢失,确定要离开吗?' } diff --git a/src/shared/locales/zh-TW/preferences.js b/src/shared/locales/zh-TW/preferences.js index bcb600c16..2fdd30ba2 100644 --- a/src/shared/locales/zh-TW/preferences.js +++ b/src/shared/locales/zh-TW/preferences.js @@ -76,5 +76,7 @@ export default { 'baidu-exporter-help': '點此檢視使用說明', 'auto-update': '自動更新', 'auto-check-update': '自動檢查更新', - 'last-check-update-time': '上次檢查更新時間' + 'last-check-update-time': '上次檢查更新時間', + 'not-saved': '設定未保存', + 'not-saved-confirm': '已修改的設定將會丟失,確定要離開嗎?' } diff --git a/src/shared/utils/index.js b/src/shared/utils/index.js index 3e5cd22ad..65dd263e9 100644 --- a/src/shared/utils/index.js +++ b/src/shared/utils/index.js @@ -6,6 +6,7 @@ import { isEmpty, isFunction, isNaN, + isPlainObject, kebabCase, omitBy, parseInt, @@ -608,7 +609,7 @@ export function removeExtensionDot (extension = '') { export function diffConfig (current = {}, next = {}) { const curr = pick(current, Object.keys(next)) const result = omitBy(next, (val, key) => { - if (isArray(val)) { + if (isArray(val) || isPlainObject(val)) { return JSON.stringify(curr[key]) === JSON.stringify(val) } return curr[key] === val @@ -706,3 +707,6 @@ export const intersection = (array1 = [], array2 = []) => { export const getInverseTheme = (theme) => { return (theme === APP_THEME.LIGHT) ? APP_THEME.DARK : APP_THEME.LIGHT } + +export const changedConfig = { basic: {}, advanced: {} } +export const backupConfig = { theme: undefined, locale: undefined }