Skip to content

Commit

Permalink
Backup creation and restore moved to lib-iitc-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
modos189 committed Jul 29, 2023
1 parent c57a587 commit 4d5dc1b
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 254 deletions.
31 changes: 9 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"@bundled-es-modules/deepmerge": "^4.3.1",
"@highlightjs/vue-plugin": "^1.0.2",
"await-timeout": "^1.1.1",
"core-js": "^3.6.5",
"highlight.js": "^10.7.3",
"jszip": "^3.10.1",
"lib-iitc-manager": "^1.6.1",
"lib-iitc-manager": "^1.7.0",
"scored-fuzzysearch": "^1.0.5",
"vue": "^2.6.11"
},
Expand Down
27 changes: 27 additions & 0 deletions src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,33 @@ browser.runtime.onMessage.addListener(async function(request) {
// If tab is closed, message goes nowhere and an error occurs. Ignore.
}
break;
case "getBackupData":
try {
browser.runtime
.sendMessage({
type: "resolveGetBackupData",
data: await manager.getBackupData(request.params)
})
.then();
} catch {
// If tab is closed, message goes nowhere and an error occurs. Ignore.
}
break;
case "setBackupData":
try {
browser.runtime
.sendMessage({
type: "resolveSetBackupData",
data: await manager.setBackupData(
request.params,
request.backup_data
)
})
.then();
} catch {
// If tab is closed, message goes nowhere and an error occurs. Ignore.
}
break;
case "setCustomChannelUrl":
await manager.setCustomChannelUrl(request.value);
break;
Expand Down
78 changes: 34 additions & 44 deletions src/settings/backup/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,7 @@

<script>
import { _ } from "@/i18n";
import {
createBackupZip,
filterExternalPlugins,
filterStorageIitcSettings,
filterStoragePluginsSettings
} from "./export";
import {
getBackupDataFromZip,
importBackupExternalPlugins,
importBackupIitcSettings,
importBackupPluginsSettings
} from "@/settings/backup/import";
import { getBackupDataFromZip, createBackupZip } from "./utils";
export default {
name: "PageBackup",
Expand All @@ -91,6 +80,16 @@ export default {
},
methods: {
_: _,
async handleExport() {
await browser.runtime.sendMessage({
type: "getBackupData",
params: {
settings: this.export_settings,
data: this.export_data,
external: this.export_external
}
});
},
async handleImport(e) {
const target = e.target;
const files = target.files;
Expand Down Expand Up @@ -121,41 +120,32 @@ export default {
this.show_import_data = false;
this.show_import_external = false;
if (this.import_settings)
await importBackupIitcSettings(this.backup_data.data.iitc_settings);
if (this.import_data)
await importBackupPluginsSettings(this.backup_data.data.plugins_data);
if (this.import_external)
await importBackupExternalPlugins(this.backup_data.external_plugins);
const message = _("backupRestored");
alert(message);
this.backup_data = {};
this.is_wait = false;
},
async handleExport() {
const backup = await this.getBackupData();
await createBackupZip(backup);
await browser.runtime.sendMessage({
type: "setBackupData",
params: {
settings: this.import_settings,
data: this.import_data,
external: this.import_external
},
backup_data: this.backup_data
});
},
async getBackupData() {
const backup = {
external_plugins: {},
data: {
iitc_settings: {},
plugins_data: {},
app: "IITC Button"
setListeners: function() {
browser.runtime.onMessage.addListener(function(request) {
switch (request.type) {
case "resolveGetBackupData":
createBackupZip(request.data).then();
break;
case "resolveSetBackupData":
alert(_("backupRestored"));
this.backup_data = {};
this.is_wait = false;
}
};
const all_storage = await browser.storage.local.get(null);
if (this.export_settings)
backup.data.iitc_settings = filterStorageIitcSettings(all_storage);
if (this.export_data)
backup.data.plugins_data = filterStoragePluginsSettings(all_storage);
if (this.export_external)
backup.external_plugins = filterExternalPlugins(all_storage);
return backup;
});
}
},
async mounted() {
this.setListeners();
}
};
</script>
Expand Down
73 changes: 0 additions & 73 deletions src/settings/backup/export.js

This file was deleted.

Loading

0 comments on commit 4d5dc1b

Please sign in to comment.