diff --git a/src/components/settings_modal/tabs/appearance_tab.js b/src/components/settings_modal/tabs/appearance_tab.js index b4b40157..ddd501f2 100644 --- a/src/components/settings_modal/tabs/appearance_tab.js +++ b/src/components/settings_modal/tabs/appearance_tab.js @@ -16,6 +16,7 @@ import { getCssRules, getScopedVersion } from 'src/services/theme_data/css_utils.js' +import { deserialize } from 'src/services/theme_data/iss_deserializer.js' import SharedComputedObject from '../helpers/shared_computed_object.js' import ProfileSettingIndicator from '../helpers/profile_setting_indicator.vue' @@ -39,6 +40,7 @@ const AppearanceTab = { accept: '.json, .piss', validator: this.importValidator, onImport: this.onImport, + parser: this.importParser, onImportFailure: this.onImportFailure }), palettesKeys: [ @@ -263,21 +265,33 @@ const AppearanceTab = { importFile () { this.fileImporter.importData() }, + importParser (file, filename) { + if (filename.endsWith('.json')) { + return JSON.parse(file) + } else if (filename.endsWith('.piss')) { + return deserialize(file) + } + }, onImport (parsed, filename) { if (filename.endsWith('.json')) { this.$store.dispatch('setThemeCustom', parsed.source || parsed.theme) - this.$store.dispatch('applyTheme') + } else if (filename.endsWith('.piss')) { + this.$store.dispatch('setStyleCustom', parsed) } - - // this.loadTheme(parsed, 'file', forceSource) }, onImportFailure (result) { + console.error('Failure importing theme:', result) this.$store.dispatch('pushGlobalNotice', { messageKey: 'settings.invalid_theme_imported', level: 'error' }) }, importValidator (parsed, filename) { if (filename.endsWith('.json')) { const version = parsed._pleroma_theme_version return version >= 1 || version <= 2 + } else if (filename.endsWith('.piss')) { + if (!Array.isArray(parsed)) return false + if (parsed.length < 1) return false + if (parsed.find(x => x.component === '@meta') == null) return false + return true } }, isThemeActive (key) { diff --git a/src/components/settings_modal/tabs/style_tab/style_tab.js b/src/components/settings_modal/tabs/style_tab/style_tab.js index aa83fda2..dbf778db 100644 --- a/src/components/settings_modal/tabs/style_tab/style_tab.js +++ b/src/components/settings_modal/tabs/style_tab/style_tab.js @@ -597,7 +597,11 @@ export default { const styleImporter = newImporter({ accept: '.piss', - parser: (string) => deserialize(string), + parser (string) { return deserialize(string) }, + onImportFailure (result) { + console.error('Failure importing style:', result) + this.$store.dispatch('pushGlobalNotice', { messageKey: 'settings.invalid_theme_imported', level: 'error' }) + }, onImport (parsed, filename) { const editorComponents = parsed.filter(x => x.component.startsWith('@')) const rootComponent = parsed.find(x => x.component === 'Root') diff --git a/src/services/export_import/export_import.js b/src/services/export_import/export_import.js index 8865061f..348a9d00 100644 --- a/src/services/export_import/export_import.js +++ b/src/services/export_import/export_import.js @@ -46,7 +46,7 @@ export const newImporter = ({ const reader = new FileReader() reader.onload = ({ target }) => { try { - const parsed = parser(target.result) + const parsed = parser(target.result, filename) const validationResult = validator(parsed, filename) if (validationResult === true) { onImport(parsed, filename)