diff --git a/lib/main.js b/lib/main.js
index b4ae4e5..e84561f 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -9,6 +9,7 @@
logging.setPrefix("main script");
const persistentRndStorage = require("./persistentRndStorage");
const notification = require("./notification");
+ const mobile = require("./mobile");
const registerSettingsContentScript = (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");
diff --git a/lib/mobile.js b/lib/mobile.js
new file mode 100644
index 0000000..020fcc4
--- /dev/null
+++ b/lib/mobile.js
@@ -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);
+ }));
+ };
+}());
\ No newline at end of file
diff --git a/manifest.json b/manifest.json
index c7cffdf..c44dcf3 100644
--- a/manifest.json
+++ b/manifest.json
@@ -23,6 +23,7 @@
"lib/dataUrls.js",
"lib/notification.js",
"lib/navigator.js",
+ "lib/mobile.js",
"lib/main.js"
]
},
diff --git a/options/options.html b/options/options.html
index 64c4803..12af5cf 100644
--- a/options/options.html
+++ b/options/options.html
@@ -21,6 +21,7 @@
+
diff --git a/options/options.js b/options/options.js
index 13b8c43..94c5227 100644
--- a/options/options.js
+++ b/options/options.js
@@ -17,6 +17,7 @@
const settingsMigration = require("../lib/settingsMigration");
require("./theme").init("options");
const modal = require("../lib/modal");
+ const mobile = require("../lib/mobile");
const callbacks = {
openNavigatorSettings: function(){
@@ -153,6 +154,9 @@
if (clear){
await browser.storage.local.clear();
await browser.storage.local.set({storageVersion: settings.storageVersion});
+ if (await mobile.isMobile()){
+ await mobile.applyMobileDefaults();
+ }
}
}
catch (error){
diff --git a/releaseNotes.txt b/releaseNotes.txt
index aaf3ee1..66e2bfe 100644
--- a/releaseNotes.txt
+++ b/releaseNotes.txt
@@ -5,6 +5,7 @@ Version 0.5.15:
new features:
- added screen protection
+ - added default values for mobile
fixes:
- background color of the textarea in the settings export was not readable in the dark theme when the value was invalid