diff --git a/client/components/Reader/ServerStorage/ServerStorage.vue b/client/components/Reader/ServerStorage/ServerStorage.vue index 5807f368..0db07d4b 100644 --- a/client/components/Reader/ServerStorage/ServerStorage.vue +++ b/client/components/Reader/ServerStorage/ServerStorage.vue @@ -34,11 +34,14 @@ class ServerStorage extends Vue { } this.hashedStorageKey = utils.toBase58(cryptoUtils.sha256(this.serverStorageKey)); - this.oldProfiles = this.profiles; await this.loadProfiles(); this.checkCurrentProfile(); } + get serverSyncEnabled() { + return this.$store.state.reader.serverSyncEnabled; + } + get settings() { return this.$store.state.reader.settings; } @@ -79,7 +82,7 @@ class ServerStorage extends Vue { } async loadProfiles() { - if (!this.currentProfile) + if (!this.serverSyncEnabled) return; let prof = await this.storageGet({'profiles': {}}); @@ -103,7 +106,7 @@ class ServerStorage extends Vue { } async saveProfiles() { - if (!this.currentProfile || this.savingProfiles) + if (!this.serverSyncEnabled || this.savingProfiles) return; const diff = utils.getObjDiff(this.oldProfiles, this.profiles); diff --git a/client/components/Reader/SettingsPage/SettingsPage.vue b/client/components/Reader/SettingsPage/SettingsPage.vue index a8c79bf2..5aa0a60b 100644 --- a/client/components/Reader/SettingsPage/SettingsPage.vue +++ b/client/components/Reader/SettingsPage/SettingsPage.vue @@ -9,13 +9,21 @@ - + +
Управление синхронизацией настроек
+ + Включить синхронизацию с сервером + +
+ +
+
Профили устройств
- Выберите или добавьте профиль устройства, чтобы начать синхронизацию данных с сервером. - При выборе "Нет" синхронизация отключается. + Выберите или добавьте профиль устройства, чтобы начать синхронизацию настроек с сервером. +
При выборе "Нет" синхронизация настроек (но не книг) отключается.
@@ -37,13 +45,13 @@
- +
Ключ доступа
- Ключ доступа позволяет восстановить профили с настройками и список читаемых книг - на другом устройстве. Для этого необходимо передать его через почту, мессенджер или другим способом. + Ключ доступа позволяет восстановить профили с настройками и список читаемых книг. + Для этого необходимо передать ключ на устройство через почту, мессенджер или другим способом.
@@ -57,11 +65,13 @@
+
{{ partialStorageKey }} (часть вашего ключа) +

-
{{ serverStorageKey }}
+
{{ serverStorageKey }}

Скопировать ключ
@@ -94,6 +104,7 @@
+
@@ -521,6 +532,14 @@ class SettingsPage extends Vue { return this.$store.state.reader.settings; } + get serverSyncEnabled() { + return this.$store.state.reader.serverSyncEnabled; + } + + set serverSyncEnabled(newValue) { + this.commit('reader/setServerSyncEnabled', newValue); + } + get profiles() { return this.$store.state.reader.profiles; } @@ -615,10 +634,9 @@ class SettingsPage extends Vue { if (this.profiles[result.value]) { this.$alert('Такой профиль уже существует', 'Ошибка'); } else { - this.currentProfile = result.value; - await this.$nextTick();//даем возможность обновить currentProfile const newProfiles = Object.assign({}, this.profiles, {[result.value]: 1}); this.commit('reader/setProfiles', newProfiles); + this.currentProfile = result.value; } } } catch (e) { @@ -646,7 +664,6 @@ class SettingsPage extends Vue { const newProfiles = Object.assign({}, this.profiles); delete newProfiles[this.currentProfile]; this.commit('reader/setProfiles', newProfiles); - await this.$nextTick();//даем возможность сохранить profiles this.currentProfile = ''; } } @@ -670,11 +687,7 @@ class SettingsPage extends Vue { }); if (result.value && result.value.toLowerCase() == 'да') { - if (!this.currentProfile) - this.currentProfile = Object.keys(this.profiles)[0]; - await this.$nextTick();//даем возможность обновить currentProfile this.commit('reader/setProfiles', {}); - await this.$nextTick();//даем возможность сохранить profiles this.currentProfile = ''; } } catch (e) { @@ -697,6 +710,22 @@ class SettingsPage extends Vue { } async enterServerStorageKey() { + try { + const result = await this.$prompt(`Предупреждение! Изменение ключа доступа приведет к потере всех профилей и читаемых книг, привязанных к предыдущему ключу.` + + `

Введите новый ключ доступа:`, '', { + dangerouslyUseHTMLString: true, + confirmButtonText: 'OK', + cancelButtonText: 'Отмена', + inputValidator: (str) => { if (str && str.length == 44) return true; else return 'Неверный формат ключа'; }, + type: 'warning' + }); + + if (result.value && result.value.length == 44) { + this.commit('reader/setServerStorageKey', result.value); + } + } catch (e) { + // + } } async generateServerStorageKey() { diff --git a/client/store/modules/reader.js b/client/store/modules/reader.js index a83c2a51..61c7973d 100644 --- a/client/store/modules/reader.js +++ b/client/store/modules/reader.js @@ -177,6 +177,7 @@ for (const font of webFonts) // initial state const state = { toolBarActive: true, + serverSyncEnabled: false, serverStorageKey: '', profiles: {}, profilesRev: 0, @@ -195,6 +196,9 @@ const mutations = { setToolBarActive(state, value) { state.toolBarActive = value; }, + setServerSyncEnabled(state, value) { + state.serverSyncEnabled = value; + }, setServerStorageKey(state, value) { state.serverStorageKey = value; },