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

View File

@ -31,7 +31,7 @@ var main = {};
main._initializeSettings = function () { main._initializeSettings = function () {
storageManager.checkStorageType(); storageManager.checkStorageType();
storageManager.type.get(SettingDefaults, function (items) { storageManager.type.get(null, function (items) {
if (items === null) { if (items === null) {
items = SettingDefaults; // Restore setting defaults. items = SettingDefaults; // Restore setting defaults.
} }
@ -47,6 +47,13 @@ main._initializeSettings = function () {
items.allowlistedDomains = items.whitelistedDomains; 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; stateManager.selectedIcon = items.selectedIcon;
wrappers.setIcon({ wrappers.setIcon({
'path': stateManager.selectedIcon 'path': stateManager.selectedIcon
@ -64,35 +71,28 @@ main._showReleaseNotes = function (details) {
[Setting.LAST_MAPPING_UPDATE]: mappings.lastMappingUpdate [Setting.LAST_MAPPING_UPDATE]: mappings.lastMappingUpdate
}, function() { }, function() {
if (details.temporary !== true) { if (details.temporary !== true) {
storageManager.type.get([Setting.HIDE_RELEASE_NOTES], function (items) {
if (items.hideReleaseNotes !== true) {
chrome.tabs.create({ chrome.tabs.create({
'url': chrome.extension.getURL('pages/welcome/welcome.html'), 'url': chrome.extension.getURL('pages/welcome/welcome.html'),
'active': false 'active': false
}); });
} }
}); });
}
});
} else if (details.reason === chrome.runtime.OnInstalledReason.UPDATE) { } 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; let mappingUpdate = items.lastMappingUpdate !== mappings.lastMappingUpdate;
if (mappingUpdate || !items.hideReleaseNotes) {
// Updated mappings.js // Updated mappings.js
if (mappingUpdate) {
storageManager.type.set({ storageManager.type.set({
[Setting.LAST_MAPPING_UPDATE]: mappings.lastMappingUpdate [Setting.LAST_MAPPING_UPDATE]: mappings.lastMappingUpdate
}, function() { });
if (!items.hideReleaseNotes) { }
if ( (mappingUpdate && items.updateNotification == 1) || items.updateNotification == 2 ) {
chrome.tabs.create({ chrome.tabs.create({
'url': chrome.extension.getURL('pages/updates/updates.html?mappingupdate=' + mappingUpdate), 'url': chrome.extension.getURL('pages/updates/updates.html?mappingupdate=' + mappingUpdate),
'active': false 'active': false
}); });
}
});
} else { } else {
// No mappings.js update // No mappings.js update
return; return;

View File

@ -62,7 +62,7 @@ storageManager.migrateData = function (target) {
[Setting.DOMAINS_MANIPULATE_DOM]: data.domainsManipulateDOM, [Setting.DOMAINS_MANIPULATE_DOM]: data.domainsManipulateDOM,
[Setting.LOGGING]: data.logging, [Setting.LOGGING]: data.logging,
[Setting.ENFORCE_STAGING]: data.enforceStaging, [Setting.ENFORCE_STAGING]: data.enforceStaging,
[Setting.HIDE_RELEASE_NOTES]: data.hideReleaseNotes, [Setting.UPDATE_NOTIFICATION]: data.updateNotification,
[Setting.LAST_MAPPING_UPDATE]: data.lastMappingUpdate, [Setting.LAST_MAPPING_UPDATE]: data.lastMappingUpdate,
[Setting.NEGATE_HTML_FILTER_LIST]: data.negateHtmlFilterList, [Setting.NEGATE_HTML_FILTER_LIST]: data.negateHtmlFilterList,
[Setting.SELECTED_ICON]: data.selectedIcon, [Setting.SELECTED_ICON]: data.selectedIcon,
@ -141,6 +141,11 @@ storageManager._validation = function (content) {
} }
delete content['whitelistedDomains']; 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)) { for (const [key, value] of Object.entries(SettingDefaults)) {
// If type the same as default settings // If type the same as default settings
if (typeof value === typeof content[key]) { 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> <div class="description-option" data-i18n-content="showIconBadgeDescription">Show the number of injected resources on the extension icon.</div>
</section> </section>
<section class="option"> <section class="option">
<div class="title-option"> <div class="title-option b-contain">
<label class="b-contain"> <span data-i18n-content="updateNotificationTitle">Notification after an update</span>
<input data-option="hideReleaseNotes" type="checkbox"> </div>
<span data-i18n-content="hideReleaseNotesTitle">Disable release notes</span> <div class="description-option">
<div class="b-input"></div> <select id="update-notification" data-option="updateNotification">
</label> <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>
<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>
<section class="option"> <section class="option">
<div class="title-option"> <div class="title-option">

View File

@ -77,7 +77,7 @@ options._renderOptionsPanel = function () {
elements.blockMissing.checked = options._optionValues.blockMissing; elements.blockMissing.checked = options._optionValues.blockMissing;
elements.disablePrefetch.checked = options._optionValues.disablePrefetch; elements.disablePrefetch.checked = options._optionValues.disablePrefetch;
elements.stripMetadata.checked = options._optionValues.stripMetadata; 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.enableLogging.checked = options._optionValues.enableLogging;
elements.allowlistedDomains.value = domainAllowlist; elements.allowlistedDomains.value = domainAllowlist;
elements.domainsManipulateDOM.value = domainHtmlFilter; elements.domainsManipulateDOM.value = domainHtmlFilter;
@ -184,7 +184,7 @@ options._registerOptionChangedEventListeners = function (elements) {
elements.disablePrefetch.addEventListener('change', options._onOptionChanged); elements.disablePrefetch.addEventListener('change', options._onOptionChanged);
elements.stripMetadata.addEventListener('change', options._onOptionChanged); elements.stripMetadata.addEventListener('change', options._onOptionChanged);
elements.enableLogging.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.allowlistedDomains.addEventListener('keyup', options._onOptionChanged);
elements.domainsManipulateDOM.addEventListener('keyup', options._onOptionChanged); elements.domainsManipulateDOM.addEventListener('keyup', options._onOptionChanged);
elements.negateHtmlFilterList.addEventListener('change', options._onOptionChanged); elements.negateHtmlFilterList.addEventListener('change', options._onOptionChanged);
@ -243,7 +243,7 @@ options._getOptionElements = function () {
[Setting.DISABLE_PREFETCH]: options._getOptionElement(Setting.DISABLE_PREFETCH), [Setting.DISABLE_PREFETCH]: options._getOptionElement(Setting.DISABLE_PREFETCH),
[Setting.STRIP_METADATA]: options._getOptionElement(Setting.STRIP_METADATA), [Setting.STRIP_METADATA]: options._getOptionElement(Setting.STRIP_METADATA),
[Setting.ALLOWLISTED_DOMAINS]: options._getOptionElement(Setting.ALLOWLISTED_DOMAINS), [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), [Setting.LOGGING]: options._getOptionElement(Setting.LOGGING),
['ruleSets']: document.getElementsByName('rule-sets'), ['ruleSets']: document.getElementsByName('rule-sets'),
['copyRuleSet']: document.getElementById('button-copy-rule-set'), ['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>Updated: video.js v7.10.1 -> v7.10.2</li>
<li>Added: WebRTC Adapter v7.4.0</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>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> </ul>
<div id="generator-section"> <div id="generator-section">
<div class="topic-label"> <div class="topic-label">