LocalCDN-Firefox-Chrome-Brave/core/main.js

115 lines
3.3 KiB
JavaScript
Raw Normal View History

2020-02-27 13:45:29 +01:00
/**
* Entry Point
2020-06-30 18:41:58 +02:00
* Belongs to LocalCDN (since 2020-02-26)
* (Origin: Decentraleyes)
2020-02-27 13:45:29 +01:00
*
* @author Thomas Rientjes
* @since 2016-04-04
2020-06-30 18:41:58 +02:00
*
* @author nobody
* @since 2020-02-26
*
2020-02-27 13:45:29 +01:00
* @license MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
'use strict';
/**
* Main
*/
var main = {};
/**
* Private Methods
*/
main._initializeSettings = function () {
2020-08-30 18:56:36 +02:00
storageManager.checkStorageType();
storageManager.type.get(null, function (items) {
2020-02-27 13:45:29 +01:00
if (items === null) {
2020-08-30 18:35:08 +02:00
items = SettingDefaults; // Restore setting defaults.
2020-02-27 13:45:29 +01:00
}
if (items.disablePrefetch !== false) {
chrome.privacy.network.networkPredictionEnabled.set({
'value': false
});
}
2020-10-17 07:39:28 +02:00
// Copy old data
2020-10-18 09:12:20 +02:00
if (Object.keys(items.allowlistedDomains).length === 0) {
2020-10-17 07:39:28 +02:00
items.allowlistedDomains = items.whitelistedDomains;
}
2020-11-14 12:33:40 +01:00
// Delete old key
if (typeof items.whitelistedDomains !== 'undefined') {
delete items['whitelistedDomains'];
storageManager.type.remove('whitelistedDomains');
}
// Convert value of notifications
if (typeof items.hideReleaseNotes !== 'undefined') {
items.updateNotification = items.hideReleaseNotes ? 0 : 2;
delete items['hideReleaseNotes'];
storageManager.type.remove('hideReleaseNotes');
}
stateManager.selectedIcon = items.selectedIcon;
wrappers.setIcon({
'path': stateManager.selectedIcon
}, 'Enabled');
2020-02-27 13:45:29 +01:00
2020-08-30 18:56:36 +02:00
storageManager.type.set(items);
2020-02-27 13:45:29 +01:00
});
};
main._showReleaseNotes = function (details) {
2020-08-30 18:56:36 +02:00
storageManager.checkStorageType();
if (details.reason === chrome.runtime.OnInstalledReason.INSTALL) {
2020-08-30 18:56:36 +02:00
storageManager.type.set({
[Setting.LAST_MAPPING_UPDATE]: mappings.lastMappingUpdate
}, function() {
if (details.temporary !== true) {
chrome.tabs.create({
'url': chrome.extension.getURL('pages/welcome/welcome.html'),
'active': false
});
}
});
} else if (details.reason === chrome.runtime.OnInstalledReason.UPDATE) {
storageManager.type.get([Setting.LAST_MAPPING_UPDATE, Setting.UPDATE_NOTIFICATION], function (items) {
let mappingUpdate = items.lastMappingUpdate !== mappings.lastMappingUpdate;
// Updated mappings.js
if (mappingUpdate) {
2020-08-30 18:56:36 +02:00
storageManager.type.set({
[Setting.LAST_MAPPING_UPDATE]: mappings.lastMappingUpdate
});
}
if ( (mappingUpdate && items.updateNotification == 1) || items.updateNotification == 2 ) {
chrome.tabs.create({
'url': chrome.extension.getURL('pages/updates/updates.html?mappingupdate=' + mappingUpdate),
'active': false
});
} else {
// No mappings.js update
return;
}
});
2020-02-27 13:45:29 +01:00
}
};
/**
* Initializations
*/
chrome.runtime.onInstalled.addListener(main._showReleaseNotes);
main._initializeSettings();