snapshot/source mismatch case

This commit is contained in:
Henry Jameson 2020-01-22 02:44:39 +02:00
parent c1e3632f42
commit d98e31af45
3 changed files with 68 additions and 10 deletions

View file

@ -160,6 +160,9 @@ export default {
) )
} }
} else if (origin === 'localStorage') { } else if (origin === 'localStorage') {
if (type === 'snapshot_source_mismatch') {
return t(pre + 'snapshot_source_mismatch')
}
// FE upgraded from v2 // FE upgraded from v2
if (themeEngineVersion === 2) { if (themeEngineVersion === 2) {
return t(pre + 'upgraded_from_v2') return t(pre + 'upgraded_from_v2')
@ -345,7 +348,10 @@ export default {
source.radii = this.currentRadii source.radii = this.currentRadii
} }
const theme = this.previewTheme const theme = {
themeEngineVersion: CURRENT_VERSION,
...this.previewTheme
}
return { return {
// To separate from other random JSON files and possible future source formats // To separate from other random JSON files and possible future source formats
@ -381,17 +387,34 @@ export default {
const version = (origin === 'localstorage' && !theme.colors) const version = (origin === 'localstorage' && !theme.colors)
? 'l1' ? 'l1'
: fileVersion : fileVersion
const snapshotEngineVersion = (theme || {}).themeEngineVersion
const themeEngineVersion = (source || {}).themeEngineVersion || 2 const themeEngineVersion = (source || {}).themeEngineVersion || 2
const versionsMatch = themeEngineVersion === CURRENT_VERSION 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 // Force loading of source if user requested it or if snapshot
// is unavailable // is unavailable
const forcedSourceLoad = (source && forceUseSource) || !theme const forcedSourceLoad = (source && forceUseSource) || !theme
if (!versionsMatch && if (!(versionsMatch && !sourceSnapshotMismatch) &&
!forcedSourceLoad && !forcedSourceLoad &&
version !== 'l1' && version !== 'l1' &&
origin !== 'defaults' origin !== 'defaults'
) { ) {
if (!theme) { if (sourceSnapshotMismatch) {
this.themeWarning = {
origin,
themeEngineVersion,
type: 'snapshot_source_mismatch'
}
} else if (!theme) {
this.themeWarning = { this.themeWarning = {
origin, origin,
noActionsPossible: true, noActionsPossible: true,
@ -428,7 +451,19 @@ export default {
} }
this.dismissWarning() 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 { const {
customTheme: theme, customTheme: theme,
customThemeSource: source customThemeSource: source
@ -442,7 +477,10 @@ export default {
) )
} else { } else {
this.loadTheme( this.loadTheme(
{ theme, source }, {
theme,
source: forceSnapshot ? theme : source
},
'localStorage', 'localStorage',
confirmLoadSource confirmLoadSource
) )
@ -451,7 +489,10 @@ export default {
setCustomTheme () { setCustomTheme () {
this.$store.dispatch('setOption', { this.$store.dispatch('setOption', {
name: 'customTheme', name: 'customTheme',
value: this.previewTheme value: {
themeEngineVersion: CURRENT_VERSION,
...this.previewTheme
}
}) })
this.$store.dispatch('setOption', { this.$store.dispatch('setOption', {
name: 'customThemeSource', name: 'customThemeSource',

View file

@ -7,7 +7,21 @@
{{ themeWarningHelp }} {{ themeWarningHelp }}
</div> </div>
<div class="buttons"> <div class="buttons">
<template v-if="themeWarning.noActionsPossible"> <template v-if="themeWarning.type === 'snapshot_source_mismatch'">
<button
class="btn"
@click="forceLoad"
>
{{ $t('settings.style.switcher.use_source') }}
</button>
<button
class="btn"
@click="dismissWarning"
>
{{ $t('settings.style.switcher.use_snapshot') }}
</button>
</template>
<template v-else-if="themeWarning.noActionsPossible">
<button <button
class="btn" class="btn"
@click="dismissWarning" @click="dismissWarning"
@ -26,7 +40,7 @@
class="btn" class="btn"
@click="dismissWarning" @click="dismissWarning"
> >
{{ $t('settings.style.switcher.use_snapshot') }} {{ $t('settings.style.switcher.keep_as_is') }}
</button> </button>
</template> </template>
</div> </div>

View file

@ -397,7 +397,9 @@
"clear_all": "Clear all", "clear_all": "Clear all",
"clear_opacity": "Clear opacity", "clear_opacity": "Clear opacity",
"load_theme": "Load theme", "load_theme": "Load theme",
"use_snapshot": "Keep as is", "keep_as_is": "Keep as is",
"use_snapshot": "Old version",
"use_source": "New version",
"help": { "help": {
"upgraded_from_v2": "PleromaFE has been upgraded, theme could look a little bit different than you remember.", "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.", "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_upgraded": "PleromaFE's theme engine upgraded after version update.",
"fe_downgraded": "PleromaFE's version rolled back.", "fe_downgraded": "PleromaFE's version rolled back.",
"migration_snapshot_ok": "Just to be safe, theme snapshot loaded. You can try loading theme data.", "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": { "common": {