mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 21:00:23 +01:00
Added default values for mobile
This commit is contained in:
parent
5020e0b070
commit
b7ba5c2050
@ -9,6 +9,7 @@
|
|||||||
logging.setPrefix("main script");
|
logging.setPrefix("main script");
|
||||||
const persistentRndStorage = require("./persistentRndStorage");
|
const persistentRndStorage = require("./persistentRndStorage");
|
||||||
const notification = require("./notification");
|
const notification = require("./notification");
|
||||||
|
const mobile = require("./mobile");
|
||||||
|
|
||||||
const registerSettingsContentScript = (function(){
|
const registerSettingsContentScript = (function(){
|
||||||
let unregisterSettingsContentScript = function(){};
|
let unregisterSettingsContentScript = function(){};
|
||||||
@ -187,6 +188,13 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mobile default settings
|
||||||
|
mobile.ifMobile(function(){
|
||||||
|
return browser.storage.local.get().then(mobile.applyMobileDefaults).catch(function(error){
|
||||||
|
logging.error("Unable to set mobile default values:", error);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
logging.message("end");
|
logging.message("end");
|
||||||
|
51
lib/mobile.js
Normal file
51
lib/mobile.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/* 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/. */
|
||||||
|
(function(){
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
let scope;
|
||||||
|
if ((typeof exports) !== "undefined"){
|
||||||
|
scope = exports;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
scope = require.register("./mobile", {});
|
||||||
|
}
|
||||||
|
|
||||||
|
const settings = require("./settings");
|
||||||
|
const settingDefinitions = require("./settingDefinitions");
|
||||||
|
|
||||||
|
scope.isMobile = function isMobile(){
|
||||||
|
// todo: proper mobile check (e.g. over browser.runtime.getBrowserInfo()) and no feature check
|
||||||
|
return Promise.resolve(
|
||||||
|
!browser.pageAction ||
|
||||||
|
!browser.pageAction.show ||
|
||||||
|
!browser.pageAction.openPopup
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
scope.ifMobile = function ifMobile(ifCallback, elseCallback){
|
||||||
|
return scope.isMobile().then(function(isMobile){
|
||||||
|
if (isMobile){
|
||||||
|
return ifCallback();
|
||||||
|
}
|
||||||
|
else if (elseCallback){
|
||||||
|
return elseCallback();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
scope.applyMobileDefaults = function applyMobileDefaults(storage = false){
|
||||||
|
return Promise.all(settingDefinitions.filter(function(definition){
|
||||||
|
return definition.hasOwnProperty("mobileDefaultValue") && (
|
||||||
|
!storage ||
|
||||||
|
!storage.hasOwnProperty(definition.name)
|
||||||
|
);
|
||||||
|
}).map(function(definition){
|
||||||
|
return settings.set(definition.name, definition.mobileDefaultValue);
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
}());
|
@ -23,6 +23,7 @@
|
|||||||
"lib/dataUrls.js",
|
"lib/dataUrls.js",
|
||||||
"lib/notification.js",
|
"lib/notification.js",
|
||||||
"lib/navigator.js",
|
"lib/navigator.js",
|
||||||
|
"lib/mobile.js",
|
||||||
"lib/main.js"
|
"lib/main.js"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
<script src="../lib/search.js"></script>
|
<script src="../lib/search.js"></script>
|
||||||
<script src="../lib/theme.js"></script>
|
<script src="../lib/theme.js"></script>
|
||||||
<script src="../lib/modal.js"></script>
|
<script src="../lib/modal.js"></script>
|
||||||
|
<script src="../lib/mobile.js"></script>
|
||||||
<script src="optionsGui.js"></script>
|
<script src="optionsGui.js"></script>
|
||||||
<script src="settingsDisplay.js"></script>
|
<script src="settingsDisplay.js"></script>
|
||||||
<script src="options.js"></script>
|
<script src="options.js"></script>
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
const settingsMigration = require("../lib/settingsMigration");
|
const settingsMigration = require("../lib/settingsMigration");
|
||||||
require("./theme").init("options");
|
require("./theme").init("options");
|
||||||
const modal = require("../lib/modal");
|
const modal = require("../lib/modal");
|
||||||
|
const mobile = require("../lib/mobile");
|
||||||
|
|
||||||
const callbacks = {
|
const callbacks = {
|
||||||
openNavigatorSettings: function(){
|
openNavigatorSettings: function(){
|
||||||
@ -153,6 +154,9 @@
|
|||||||
if (clear){
|
if (clear){
|
||||||
await browser.storage.local.clear();
|
await browser.storage.local.clear();
|
||||||
await browser.storage.local.set({storageVersion: settings.storageVersion});
|
await browser.storage.local.set({storageVersion: settings.storageVersion});
|
||||||
|
if (await mobile.isMobile()){
|
||||||
|
await mobile.applyMobileDefaults();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (error){
|
catch (error){
|
||||||
|
@ -5,6 +5,7 @@ Version 0.5.15:
|
|||||||
|
|
||||||
new features:
|
new features:
|
||||||
- added screen protection
|
- added screen protection
|
||||||
|
- added default values for mobile
|
||||||
|
|
||||||
fixes:
|
fixes:
|
||||||
- background color of the textarea in the settings export was not readable in the dark theme when the value was invalid
|
- background color of the textarea in the settings export was not readable in the dark theme when the value was invalid
|
||||||
|
Loading…
x
Reference in New Issue
Block a user