VulpesOS/assets/webapps/system.gaiamobile.org/js/app_migrator.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

75 lines
2 KiB
JavaScript

'use strict';
/* global Service */
/**
The app migrator is in charge of migrating app data between releases
*/
(function(exports) {
const HOMESCREEN_MANIFEST =
'app://homescreen.gaiamobile.org/manifest.webapp';
const VERTICALHOME_PREFS_STORE = 'vertical_preferences_store';
const MIGRATION_PREF = 'migrated';
var AppMigrator = function AppMigrator() {
};
AppMigrator.prototype = {
start: function() {
// Probably should not happen, but just to be safe we early exit in case
// we get a second migrate message.
if (this.migrating) {
return;
}
var self = this;
if (Service.query('justUpgraded')) {
self.migrating = true;
// Migrate to new home screen if migration hasn't already been
// performed.
navigator.getDataStores(VERTICALHOME_PREFS_STORE).then(
stores => {
if (stores.length < 1) {
console.error('Error opening verticalhome prefs datastore');
return;
}
var migrate = () => {
navigator.mozApps.getSelf().onsuccess = e => {
var app = e.target.result;
if (!app) {
console.error('Error retrieving app object');
return;
}
app.connect('verticalhome-migrate').then(ports => {
ports.forEach(port => {
port.postMessage({ action: 'migrate',
manifestURL: HOMESCREEN_MANIFEST });
});
}, e => {
console.error('Error communicating with verticalhome', e);
});
};
};
stores[0].get(MIGRATION_PREF).then(
migrated => {
if (!migrated) {
migrate();
}
}, e => {
console.error('Error getting verticalhome migration pref', e);
});
});
}
}
};
exports.AppMigrator = AppMigrator;
})(window);