From f27505504c4ce7ba826bcf146fea1763a38c3de4 Mon Sep 17 00:00:00 2001 From: buzzcode2007 <73412182+buzz_lightsnack_2007@users.noreply.github.com> Date: Sat, 23 Mar 2024 17:18:18 +0800 Subject: [PATCH] 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. --- scripts/fc.js | 48 ++++++++++++++++++++++++++++++++++-------- scripts/secretariat.js | 7 +++++- scripts/shopAI.js | 4 +++- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/scripts/fc.js b/scripts/fc.js index df66013..fa9859a 100644 --- a/scripts/fc.js +++ b/scripts/fc.js @@ -2,29 +2,59 @@ 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() { - 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() { - /* Initialize the set-up. + /* Initialize the configuration. 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() { - chrome.runtime.onInstalled.addListener(function (object) { - if (object.reason == chrome.runtime.OnInstalledReason.INSTALL) { + chrome.runtime.onInstalled.addListener(function (details) { + if (details.reason == chrome.runtime.OnInstalledReason.INSTALL) { fc.hello(); - fc.setup(); - } + }; + fc.setup(); }); } diff --git a/scripts/secretariat.js b/scripts/secretariat.js index 77dac18..ff7b8b4 100644 --- a/scripts/secretariat.js +++ b/scripts/secretariat.js @@ -214,6 +214,10 @@ export function init(data) { 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){ PREFERENCES_ALL[`sync`] = DATA_SYNC; }); @@ -245,7 +249,8 @@ export function init(data) { PREFERENCE[`existing`] = ( ((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`]) { diff --git a/scripts/shopAI.js b/scripts/shopAI.js index b0abef5..63f4dc4 100644 --- a/scripts/shopAI.js +++ b/scripts/shopAI.js @@ -2,4 +2,6 @@ Shop wisely with AI! */ -importScripts('fc.js'); +import fc from './fc.js'; + +fc.run();