From 9eddfcd48683c1d9245bb4fa1be450bf6e6a9ccf Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Wed, 6 Mar 2019 16:21:49 -0600 Subject: [PATCH 1/5] remove usless async --- src/models/storage.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/models/storage.ts b/src/models/storage.ts index f5e46ec61..92363b61a 100644 --- a/src/models/storage.ts +++ b/src/models/storage.ts @@ -144,7 +144,7 @@ class EntryStorage { } } - static async hasEncryptedEntry() { + static hasEncryptedEntry() { return new Promise( (resolve: (value: boolean) => void, reject: (reason: Error) => void) => { @@ -163,7 +163,7 @@ class EntryStorage { }); } - static async getExport(encryption: Encryption, encrypted?: boolean) { + static getExport(encryption: Encryption, encrypted?: boolean) { return new Promise( (resolve: (value: {[hash: string]: OTPStorage}) => void, reject: (reason: Error) => void) => { @@ -201,8 +201,7 @@ class EntryStorage { }); } - static async import( - encryption: Encryption, data: {[hash: string]: OTPStorage}) { + static import(encryption: Encryption, data: {[hash: string]: OTPStorage}) { return new Promise( (resolve: () => void, reject: (reason: Error) => void) => { try { @@ -285,7 +284,7 @@ class EntryStorage { }); } - static async add(encryption: Encryption, entry: OTPEntry) { + static add(encryption: Encryption, entry: OTPEntry) { return new Promise( (resolve: () => void, reject: (reason: Error) => void) => { try { @@ -306,7 +305,7 @@ class EntryStorage { }); } - static async update(encryption: Encryption, entry: OTPEntry) { + static update(encryption: Encryption, entry: OTPEntry) { return new Promise( (resolve: () => void, reject: (reason: Error) => void) => { try { @@ -327,7 +326,7 @@ class EntryStorage { }); } - static async set(encryption: Encryption, entries: OTPEntry[]) { + static set(encryption: Encryption, entries: OTPEntry[]) { return new Promise( (resolve: () => void, reject: (reason: Error) => void) => { try { @@ -347,7 +346,7 @@ class EntryStorage { }); } - static async get(encryption: Encryption) { + static get(encryption: Encryption) { return new Promise( (resolve: (value: OTPEntry[]) => void, reject: (reason: Error) => void) => { @@ -491,14 +490,14 @@ class EntryStorage { }); } - static async remove(hash: string) { + static remove(hash: string) { return new Promise( (resolve: () => void, reject: (reason: Error) => void) => { return BrowserStorage.remove(hash, resolve); }); } - static async delete(entry: OTPEntry) { + static delete(entry: OTPEntry) { return new Promise( (resolve: () => void, reject: (reason: Error) => void) => { try { From cbee3bf934c899135e8a672ff38626fe3989afd0 Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Wed, 6 Mar 2019 17:29:36 -0600 Subject: [PATCH 2/5] add policy option for install page --- manifest-chrome.json | 3 +++ schema-chrome.json | 35 +++++++++++++++++++++++++++++++++++ scripts/build.sh | 3 +++ src/background.ts | 6 +++++- src/models/storage.ts | 22 ++++++++++++++++++++++ 5 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 schema-chrome.json diff --git a/manifest-chrome.json b/manifest-chrome.json index 1437764a2..36c166329 100644 --- a/manifest-chrome.json +++ b/manifest-chrome.json @@ -18,6 +18,9 @@ "default_title": "__MSG_extShortName__", "default_popup": "view/popup.html" }, + "storage": { + "managed_schema": "schema.json" + }, "oauth2": { "client_id": "292457304165-u8ve4j79gag5o231n5u2pdtdrbfdo1hh.apps.googleusercontent.com", "scopes": [ diff --git a/schema-chrome.json b/schema-chrome.json new file mode 100644 index 000000000..ddf2a5720 --- /dev/null +++ b/schema-chrome.json @@ -0,0 +1,35 @@ +{ + "type": "object", + + "properties": { + "policyActive": { + "title": "Activate policy", + "description": "If set to true then policy options will be used. If false or undefined all policy options will be ignored.", + "type": "boolean" + }, + + "disableInstallHelp": { + "title": "Disable opening help page on install", + "description": "If set to true then help page will not be opened on install.", + "type": "boolean" + }, + + "disableSync": { + "title": "Disable 3rd party sync", + "description": "If set to true then 3rd party backup options will be hidden.", + "type": "boolean" + }, + + "storageArea": { + "title": "Storage area", + "description": "Set to 'sync' or 'local'. If set will force user to use specified storage area. This setting will not check if a user is currently using another storage space and may hide data.", + "type": "string" + }, + + "feedbackURL": { + "title": "Feedback URL", + "description": "Change the URL the feedback button opens.", + "type": "string" + } + } +} diff --git a/scripts/build.sh b/scripts/build.sh index 215908866..6ae95f287 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -58,6 +58,9 @@ if [[ $PLATFORM = "edge" ]]; then else cp -r build css images js _locales LICENSE view $PLATFORM cp manifest-$PLATFORM.json $PLATFORM/manifest.json + if [[ $PLATFORM = "chrome" ]]; then + cp schema-chrome.json $PLATFORM/schema.json + fi fi echo -e "\033[0;32mDone!\033[0m" diff --git a/src/background.ts b/src/background.ts index 60e8c990b..540008a71 100644 --- a/src/background.ts +++ b/src/background.ts @@ -265,9 +265,13 @@ function getBackupToken(service: string) { } // Show issue page after first install -chrome.runtime.onInstalled.addListener((details) => { +chrome.runtime.onInstalled.addListener(async (details) => { if (details.reason !== 'install') { return; + } else if (await ManagedStorage.isPolicyActive()) { + if (await ManagedStorage.get('disableInstallHelp')) { + return; + } } let url: string|null = null; diff --git a/src/models/storage.ts b/src/models/storage.ts index 92363b61a..86fac6a63 100644 --- a/src/models/storage.ts +++ b/src/models/storage.ts @@ -518,3 +518,25 @@ class EntryStorage { }); } } + +class ManagedStorage { + static isPolicyActive() { + return new Promise((resolve: (result: boolean) => void) => { + chrome.storage.managed.get((data) => { + if (data.policyActive) { + resolve(true); + } else { + resolve(false); + } + }); + }); + } + + static get(key: string) { + return new Promise((resolve: (result: boolean|string) => void) => { + chrome.storage.managed.get((data) => { + resolve(data[key]); + }); + }); + } +} From 00db264442eb71aa2d5220a68aabcc4daa3fe4b8 Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Wed, 6 Mar 2019 20:03:39 -0600 Subject: [PATCH 3/5] finish other policies --- schema-chrome.json | 12 +++--------- schema-firefox.json | 9 +++++++++ src/background.ts | 6 ++---- src/models/storage.ts | 36 +++++++++++++++++++++--------------- src/ui/menu.ts | 24 +++++++++++++++++++++--- view/popup.html | 8 ++++---- 6 files changed, 60 insertions(+), 35 deletions(-) create mode 100644 schema-firefox.json diff --git a/schema-chrome.json b/schema-chrome.json index ddf2a5720..f852f93ae 100644 --- a/schema-chrome.json +++ b/schema-chrome.json @@ -2,21 +2,15 @@ "type": "object", "properties": { - "policyActive": { - "title": "Activate policy", - "description": "If set to true then policy options will be used. If false or undefined all policy options will be ignored.", - "type": "boolean" - }, - "disableInstallHelp": { "title": "Disable opening help page on install", "description": "If set to true then help page will not be opened on install.", "type": "boolean" }, - "disableSync": { - "title": "Disable 3rd party sync", - "description": "If set to true then 3rd party backup options will be hidden.", + "disableBackup": { + "title": "Disable 3rd party backup", + "description": "If set to true then 3rd party backup options will be hidden. If 3rd party backup is already configured for a user this will not stop it.", "type": "boolean" }, diff --git a/schema-firefox.json b/schema-firefox.json new file mode 100644 index 000000000..e6ec67f5e --- /dev/null +++ b/schema-firefox.json @@ -0,0 +1,9 @@ +{ + "name": "authenticator@mymindstorm", + "description": "ignored", + "type": "storage", + "data": + { + + } +} diff --git a/src/background.ts b/src/background.ts index 540008a71..53a50aa61 100644 --- a/src/background.ts +++ b/src/background.ts @@ -268,10 +268,8 @@ function getBackupToken(service: string) { chrome.runtime.onInstalled.addListener(async (details) => { if (details.reason !== 'install') { return; - } else if (await ManagedStorage.isPolicyActive()) { - if (await ManagedStorage.get('disableInstallHelp')) { - return; - } + } else if (await ManagedStorage.get('disableInstallHelp')) { + return; } let url: string|null = null; diff --git a/src/models/storage.ts b/src/models/storage.ts index 86fac6a63..a928d56d1 100644 --- a/src/models/storage.ts +++ b/src/models/storage.ts @@ -4,8 +4,18 @@ /// class BrowserStorage { - private static getStorageLocation() { - if (localStorage.storageLocation !== 'sync' && + private static async getStorageLocation() { + const managedLocation = await ManagedStorage.get('storageArea'); + if (managedLocation === 'sync' || managedLocation === 'local') { + return new Promise((resolve) => { + if (localStorage.storageLocation !== managedLocation) { + localStorage.storageLocation = managedLocation; + } + resolve(managedLocation); + return; + }); + } else if ( + localStorage.storageLocation !== 'sync' && localStorage.storageLocation !== 'local') { return new Promise((resolve, reject) => { let amountSync: number; @@ -520,22 +530,18 @@ class EntryStorage { } class ManagedStorage { - static isPolicyActive() { - return new Promise((resolve: (result: boolean) => void) => { - chrome.storage.managed.get((data) => { - if (data.policyActive) { - resolve(true); - } else { - resolve(false); - } - }); - }); - } - static get(key: string) { return new Promise((resolve: (result: boolean|string) => void) => { chrome.storage.managed.get((data) => { - resolve(data[key]); + if (chrome.runtime.lastError) { + resolve(false); + } + if (data) { + if (data[key]) { + resolve(data[key]); + } + } + resolve(false); }); }); } diff --git a/src/ui/menu.ts b/src/ui/menu.ts index d1a40ca08..99b0e4fe4 100644 --- a/src/ui/menu.ts +++ b/src/ui/menu.ts @@ -53,7 +53,7 @@ function resize(zoom: number) { } } -function openHelp() { +async function openHelp() { let url = 'https://github.com/Authenticator-Extension/Authenticator/wiki/Chrome-Issues'; @@ -65,9 +65,25 @@ function openHelp() { 'https://github.com/Authenticator-Extension/Authenticator/wiki/Edge-Issues'; } - window.open(url, '_blank'); + const feedbackURL = await ManagedStorage.get('feedbackURL'); + if (typeof feedbackURL === 'string' && feedbackURL) { + url = feedbackURL; + } + + chrome.tabs.create({url}); } +let backupDisabled: boolean|string; +let storageArea: boolean|string; + +ManagedStorage.get('disableBackup').then((value) => { + backupDisabled = value; +}); + +ManagedStorage.get('storageArea').then((value) => { + storageArea = value; +}); + async function menu(_ui: UI) { const version = getVersion(); const zoom = Number(localStorage.zoom) || 100; @@ -81,7 +97,9 @@ async function menu(_ui: UI) { zoom, useAutofill, useHighContrast, - newStorageLocation: localStorage.storageLocation + newStorageLocation: localStorage.storageLocation, + backupDisabled, + storageArea }, methods: { openLink: (url: string) => { diff --git a/view/popup.html b/view/popup.html index 5798e0af7..8fb18a20f 100644 --- a/view/popup.html +++ b/view/popup.html @@ -203,15 +203,15 @@
{{ i18n.storage_location_info }}
- -
{{ i18n.storage_sync_info }}
+
{{ i18n.storage_sync_info }}

-
Google Drive
-
Dropbox
+
Google Drive
+
Dropbox
From 358d7f96c10b6a933b73a447be7b01b44c1b878b Mon Sep 17 00:00:00 2001 From: Brendan Early Date: Wed, 6 Mar 2019 20:11:23 -0600 Subject: [PATCH 4/5] gts fix --- src/ui/menu.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/menu.ts b/src/ui/menu.ts index 99b0e4fe4..46aa47afb 100644 --- a/src/ui/menu.ts +++ b/src/ui/menu.ts @@ -69,7 +69,7 @@ async function openHelp() { if (typeof feedbackURL === 'string' && feedbackURL) { url = feedbackURL; } - + chrome.tabs.create({url}); } From 9e5f810a188d09902822671c55145a23a3e0cb10 Mon Sep 17 00:00:00 2001 From: mymindstorm <27789806+mymindstorm@users.noreply.github.com> Date: Mon, 18 Mar 2019 22:48:36 -0500 Subject: [PATCH 5/5] Delete schema-firefox.json --- schema-firefox.json | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 schema-firefox.json diff --git a/schema-firefox.json b/schema-firefox.json deleted file mode 100644 index e6ec67f5e..000000000 --- a/schema-firefox.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "authenticator@mymindstorm", - "description": "ignored", - "type": "storage", - "data": - { - - } -}