Improved: settings for update notification (#176)

This commit is contained in:
nobody 2020-11-14 12:31:17 +01:00
parent f32c55bbd2
commit d980beb889
No known key found for this signature in database
GPG Key ID: 8F6DE3D614FCFD7A
6 changed files with 42 additions and 34 deletions

View File

@ -66,7 +66,7 @@ const Setting = {
'DISABLE_PREFETCH': 'disablePrefetch',
'ENFORCE_STAGING': 'enforceStaging',
'SHOW_ICON_BADGE': 'showIconBadge',
'HIDE_RELEASE_NOTES': 'hideReleaseNotes',
'UPDATE_NOTIFICATION': 'updateNotification',
'STRIP_METADATA': 'stripMetadata',
'LAST_MAPPING_UPDATE': 'lastMappingUpdate',
'ALLOWLISTED_DOMAINS': 'allowlistedDomains',
@ -94,7 +94,7 @@ const SettingDefaults = {
[Setting.DOMAINS_MANIPULATE_DOM]: {},
[Setting.LOGGING]: false,
[Setting.ENFORCE_STAGING]: false,
[Setting.HIDE_RELEASE_NOTES]: false,
[Setting.UPDATE_NOTIFICATION]: 0,
[Setting.INTERNAL_STATISTICS]: false,
[Setting.INTERNAL_STATISTICS_DATA]: {},
[Setting.LAST_MAPPING_UPDATE]: '2020-01-01',

View File

@ -31,7 +31,7 @@ var main = {};
main._initializeSettings = function () {
storageManager.checkStorageType();
storageManager.type.get(SettingDefaults, function (items) {
storageManager.type.get(null, function (items) {
if (items === null) {
items = SettingDefaults; // Restore setting defaults.
}
@ -47,6 +47,13 @@ main._initializeSettings = function () {
items.allowlistedDomains = items.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
@ -64,35 +71,28 @@ main._showReleaseNotes = function (details) {
[Setting.LAST_MAPPING_UPDATE]: mappings.lastMappingUpdate
}, function() {
if (details.temporary !== true) {
storageManager.type.get([Setting.HIDE_RELEASE_NOTES], function (items) {
if (items.hideReleaseNotes !== 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.HIDE_RELEASE_NOTES], function (items) {
storageManager.type.get([Setting.LAST_MAPPING_UPDATE, Setting.UPDATE_NOTIFICATION], function (items) {
let mappingUpdate = items.lastMappingUpdate !== mappings.lastMappingUpdate;
if (mappingUpdate || !items.hideReleaseNotes) {
// Updated mappings.js
if (mappingUpdate) {
storageManager.type.set({
[Setting.LAST_MAPPING_UPDATE]: mappings.lastMappingUpdate
}, function() {
if (!items.hideReleaseNotes) {
});
}
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;

View File

@ -62,7 +62,7 @@ storageManager.migrateData = function (target) {
[Setting.DOMAINS_MANIPULATE_DOM]: data.domainsManipulateDOM,
[Setting.LOGGING]: data.logging,
[Setting.ENFORCE_STAGING]: data.enforceStaging,
[Setting.HIDE_RELEASE_NOTES]: data.hideReleaseNotes,
[Setting.UPDATE_NOTIFICATION]: data.updateNotification,
[Setting.LAST_MAPPING_UPDATE]: data.lastMappingUpdate,
[Setting.NEGATE_HTML_FILTER_LIST]: data.negateHtmlFilterList,
[Setting.SELECTED_ICON]: data.selectedIcon,
@ -141,6 +141,11 @@ storageManager._validation = function (content) {
}
delete content['whitelistedDomains'];
if (typeof content.hideReleaseNotes !== 'undefined') {
content.updateNotification = content.hideReleaseNotes ? 0 : 2;
delete content['hideReleaseNotes'];
}
for (const [key, value] of Object.entries(SettingDefaults)) {
// If type the same as default settings
if (typeof value === typeof content[key]) {

View File

@ -41,14 +41,16 @@
<div class="description-option" data-i18n-content="showIconBadgeDescription">Show the number of injected resources on the extension icon.</div>
</section>
<section class="option">
<div class="title-option">
<label class="b-contain">
<input data-option="hideReleaseNotes" type="checkbox">
<span data-i18n-content="hideReleaseNotesTitle">Disable release notes</span>
<div class="b-input"></div>
</label>
<div class="title-option b-contain">
<span data-i18n-content="updateNotificationTitle">Notification after an update</span>
</div>
<div class="description-option">
<select id="update-notification" data-option="updateNotification">
<option value="0" data-i18n-content="updateNotificationNever">Never (Silent Updates)</option>
<option value="1" data-i18n-content="updateNotificationOnlyRules">Only new CDN and rules</option>
<option value="2" data-i18n-content="updateNotificationAlways">Always</option>
</select>
</div>
<div class="description-option" data-i18n-content="hideReleaseNotesDescription">If enabled, you wont receive any information about new features in LocalCDN. This includes information about new uBlock/uMatrix rules.</div>
</section>
<section class="option">
<div class="title-option">

View File

@ -77,7 +77,7 @@ options._renderOptionsPanel = function () {
elements.blockMissing.checked = options._optionValues.blockMissing;
elements.disablePrefetch.checked = options._optionValues.disablePrefetch;
elements.stripMetadata.checked = options._optionValues.stripMetadata;
elements.hideReleaseNotes.checked = options._optionValues.hideReleaseNotes;
elements.updateNotification.value = options._optionValues.updateNotification;
elements.enableLogging.checked = options._optionValues.enableLogging;
elements.allowlistedDomains.value = domainAllowlist;
elements.domainsManipulateDOM.value = domainHtmlFilter;
@ -184,7 +184,7 @@ options._registerOptionChangedEventListeners = function (elements) {
elements.disablePrefetch.addEventListener('change', options._onOptionChanged);
elements.stripMetadata.addEventListener('change', options._onOptionChanged);
elements.enableLogging.addEventListener('change', options._onOptionChanged);
elements.hideReleaseNotes.addEventListener('change', options._onOptionChanged);
elements.updateNotification.addEventListener('change', options._onOptionChanged);
elements.allowlistedDomains.addEventListener('keyup', options._onOptionChanged);
elements.domainsManipulateDOM.addEventListener('keyup', options._onOptionChanged);
elements.negateHtmlFilterList.addEventListener('change', options._onOptionChanged);
@ -243,7 +243,7 @@ options._getOptionElements = function () {
[Setting.DISABLE_PREFETCH]: options._getOptionElement(Setting.DISABLE_PREFETCH),
[Setting.STRIP_METADATA]: options._getOptionElement(Setting.STRIP_METADATA),
[Setting.ALLOWLISTED_DOMAINS]: options._getOptionElement(Setting.ALLOWLISTED_DOMAINS),
[Setting.HIDE_RELEASE_NOTES]: options._getOptionElement(Setting.HIDE_RELEASE_NOTES),
[Setting.UPDATE_NOTIFICATION]: options._getOptionElement(Setting.UPDATE_NOTIFICATION),
[Setting.LOGGING]: options._getOptionElement(Setting.LOGGING),
['ruleSets']: document.getElementsByName('rule-sets'),
['copyRuleSet']: document.getElementById('button-copy-rule-set'),

View File

@ -84,6 +84,7 @@
<li>Updated: video.js v7.10.1 -> v7.10.2</li>
<li>Added: WebRTC Adapter v7.4.0</li>
<li>Added: lozad to cdnjs.cloudflare.com (<a href="https://codeberg.org/nobody/LocalCDN/issues/175">#175</a>)</li>
<li>Improved: Settings for update notification (<a href="https://codeberg.org/nobody/LocalCDN/issues/176">#176</a>)</li>
</ul>
<div id="generator-section">
<div class="topic-label">