add OOBE and update migration

OOBE can now be triggered every installation, whereas migration is 
trigerred for every update. However, update migration currently can't 
merge new and old, and this is TODO.
This commit is contained in:
buzzcode2007 2024-03-23 17:18:18 +08:00
parent ccac75e750
commit f27505504c
3 changed files with 48 additions and 11 deletions

View file

@ -2,29 +2,59 @@
This does not stand for "FamiCom" but instead on Finalization and Completion. This script provides installation run scripts. This does not stand for "FamiCom" but instead on Finalization and Completion. This script provides installation run scripts.
*/ */
class fc { import {read, write, init} from './secretariat.js';
let config = chrome.runtime.getURL('config/config.json');
export default class fc {
static hello() { static hello() {
chrome.tabs.create({ url: `https://codeberg.org/buzzcode2007/ShopAI/wiki` }, function (tab) {}); /* Start the out of the box experience.
*/
// the OOBE must be in the config.
fetch(config)
.then((response) => response.json())
.then((jsonData) => {
let configuration = jsonData[`OOBE`];
if (configuration) {
configuration.forEach((item) => {
chrome.tabs.create({ url: item }, function(tab) {});
});
};
})
.catch((error) => {
console.error(error);
});
}; };
static setup() { static setup() {
/* Initialize the set-up. /* Initialize the configuration.
Returns: the initialization result Returns: the initialization result
*/ */
// the OOBE must be in the config.
fetch(config)
.then((response) => response.json())
.then((jsonData) => {
let configuration = jsonData[`settings`];
// Run the storage initialization.
init(configuration);
})
.catch((error) => {
console.error(error);
});
} }
static trigger() { static trigger() {
chrome.runtime.onInstalled.addListener(function (object) { chrome.runtime.onInstalled.addListener(function (details) {
if (object.reason == chrome.runtime.OnInstalledReason.INSTALL) { if (details.reason == chrome.runtime.OnInstalledReason.INSTALL) {
fc.hello(); fc.hello();
};
fc.setup(); fc.setup();
}
}); });
} }

View file

@ -214,6 +214,10 @@ export function init(data) {
PREFERENCES_ALL[`managed`] = DATA_MANAGED; PREFERENCES_ALL[`managed`] = DATA_MANAGED;
}); });
chrome.storage.local.get(null, function(DATA_LOCAL){
PREFERENCES_ALL[`local`] = DATA_LOCAL;
});
chrome.storage.sync.get(null, function(DATA_SYNC){ chrome.storage.sync.get(null, function(DATA_SYNC){
PREFERENCES_ALL[`sync`] = DATA_SYNC; PREFERENCES_ALL[`sync`] = DATA_SYNC;
}); });
@ -245,7 +249,8 @@ export function init(data) {
PREFERENCE[`existing`] = ( PREFERENCE[`existing`] = (
((PREFERENCES_ALL[`sync`]) ? (PREFERENCES_ALL[`sync`]).hasOwnProperty(PREFERENCE[`name`]) : false) || ((PREFERENCES_ALL[`sync`]) ? (PREFERENCES_ALL[`sync`]).hasOwnProperty(PREFERENCE[`name`]) : false) ||
((PREFERENCES_ALL[`managed`]) ? (PREFERENCES_ALL[`managed`]).hasOwnProperty(PREFERENCE[`name`]) : false) ((PREFERENCES_ALL[`managed`]) ? (PREFERENCES_ALL[`managed`]).hasOwnProperty(PREFERENCE[`name`]) : false) ||
((PREFERENCES_ALL[`local`]) ? (PREFERENCES_ALL[`local`]).hasOwnProperty(PREFERENCE[`local`]) : false)
); );
if (!PREFERENCE[`existing`]) { if (!PREFERENCE[`existing`]) {

View file

@ -2,4 +2,6 @@
Shop wisely with AI! Shop wisely with AI!
*/ */
importScripts('fc.js'); import fc from './fc.js';
fc.run();