diff --git a/src/components/style_switcher/style_switcher.js b/src/components/style_switcher/style_switcher.js index 195c6b35..3b538ac7 100644 --- a/src/components/style_switcher/style_switcher.js +++ b/src/components/style_switcher/style_switcher.js @@ -160,6 +160,9 @@ export default { ) } } else if (origin === 'localStorage') { + if (type === 'snapshot_source_mismatch') { + return t(pre + 'snapshot_source_mismatch') + } // FE upgraded from v2 if (themeEngineVersion === 2) { return t(pre + 'upgraded_from_v2') @@ -345,7 +348,10 @@ export default { source.radii = this.currentRadii } - const theme = this.previewTheme + const theme = { + themeEngineVersion: CURRENT_VERSION, + ...this.previewTheme + } return { // To separate from other random JSON files and possible future source formats @@ -381,17 +387,34 @@ export default { const version = (origin === 'localstorage' && !theme.colors) ? 'l1' : fileVersion + const snapshotEngineVersion = (theme || {}).themeEngineVersion const themeEngineVersion = (source || {}).themeEngineVersion || 2 const versionsMatch = themeEngineVersion === CURRENT_VERSION + console.log( + theme !== undefined, + source !== undefined, + themeEngineVersion !== snapshotEngineVersion + ) + const sourceSnapshotMismatch = ( + theme !== undefined && + source !== undefined && + themeEngineVersion !== snapshotEngineVersion + ) // Force loading of source if user requested it or if snapshot // is unavailable const forcedSourceLoad = (source && forceUseSource) || !theme - if (!versionsMatch && + if (!(versionsMatch && !sourceSnapshotMismatch) && !forcedSourceLoad && version !== 'l1' && origin !== 'defaults' ) { - if (!theme) { + if (sourceSnapshotMismatch) { + this.themeWarning = { + origin, + themeEngineVersion, + type: 'snapshot_source_mismatch' + } + } else if (!theme) { this.themeWarning = { origin, noActionsPossible: true, @@ -428,7 +451,19 @@ export default { } this.dismissWarning() }, - loadThemeFromLocalStorage (confirmLoadSource = false) { + forceSnapshot() { + const { origin } = this.themeWarning + switch (origin) { + case 'localstorage': + this.loadThemeFromLocalStorage(false, true) + break + case 'file': + console.err('Forcing snapshout from file is not supported yet') + break + } + this.dismissWarning() + }, + loadThemeFromLocalStorage (confirmLoadSource = false, forceSnapshot = false) { const { customTheme: theme, customThemeSource: source @@ -442,7 +477,10 @@ export default { ) } else { this.loadTheme( - { theme, source }, + { + theme, + source: forceSnapshot ? theme : source + }, 'localStorage', confirmLoadSource ) @@ -451,7 +489,10 @@ export default { setCustomTheme () { this.$store.dispatch('setOption', { name: 'customTheme', - value: this.previewTheme + value: { + themeEngineVersion: CURRENT_VERSION, + ...this.previewTheme + } }) this.$store.dispatch('setOption', { name: 'customThemeSource', diff --git a/src/components/style_switcher/style_switcher.vue b/src/components/style_switcher/style_switcher.vue index 79c2fcd3..793d68f1 100644 --- a/src/components/style_switcher/style_switcher.vue +++ b/src/components/style_switcher/style_switcher.vue @@ -7,7 +7,21 @@ {{ themeWarningHelp }}
diff --git a/src/i18n/en.json b/src/i18n/en.json index 2622157a..81dde663 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -397,7 +397,9 @@ "clear_all": "Clear all", "clear_opacity": "Clear opacity", "load_theme": "Load theme", - "use_snapshot": "Keep as is", + "keep_as_is": "Keep as is", + "use_snapshot": "Old version", + "use_source": "New version", "help": { "upgraded_from_v2": "PleromaFE has been upgraded, theme could look a little bit different than you remember.", "v2_imported": "File you imported was made for older FE. We try to maximize compatibility but there still could be inconsitencies.", @@ -408,7 +410,8 @@ "fe_upgraded": "PleromaFE's theme engine upgraded after version update.", "fe_downgraded": "PleromaFE's version rolled back.", "migration_snapshot_ok": "Just to be safe, theme snapshot loaded. You can try loading theme data.", - "migration_napshot_gone": "For whatever reason snapshot was missing, some stuff could look different than you remember." + "migration_napshot_gone": "For whatever reason snapshot was missing, some stuff could look different than you remember.", + "snapshot_source_mismatch": "Versions conflict: most likely FE was rolled back and updated again, if you changed theme using older version of FE you most likely want to use old version, otherwise use new version." } }, "common": {