Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions manifest-chrome.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
29 changes: 29 additions & 0 deletions schema-chrome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"type": "object",

"properties": {
"disableInstallHelp": {
"title": "Disable opening help page on install",
"description": "If set to true then help page will not be opened on install.",
"type": "boolean"
},

"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"
},

"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"
}
}
}
3 changes: 3 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 3 additions & 1 deletion src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,11 @@ 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.get('disableInstallHelp')) {
return;
}

let url: string|null = null;
Expand Down
51 changes: 39 additions & 12 deletions src/models/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@
/// <reference path="./otp.ts" />

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;
Expand Down Expand Up @@ -144,7 +154,7 @@ class EntryStorage {
}
}

static async hasEncryptedEntry() {
static hasEncryptedEntry() {
return new Promise(
(resolve: (value: boolean) => void,
reject: (reason: Error) => void) => {
Expand All @@ -163,7 +173,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) => {
Expand Down Expand Up @@ -201,8 +211,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 {
Expand Down Expand Up @@ -285,7 +294,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 {
Expand All @@ -306,7 +315,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 {
Expand All @@ -327,7 +336,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 {
Expand All @@ -347,7 +356,7 @@ class EntryStorage {
});
}

static async get(encryption: Encryption) {
static get(encryption: Encryption) {
return new Promise(
(resolve: (value: OTPEntry[]) => void,
reject: (reason: Error) => void) => {
Expand Down Expand Up @@ -491,14 +500,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 {
Expand All @@ -519,3 +528,21 @@ class EntryStorage {
});
}
}

class ManagedStorage {
static get(key: string) {
return new Promise((resolve: (result: boolean|string) => void) => {
chrome.storage.managed.get((data) => {
if (chrome.runtime.lastError) {
resolve(false);
}
if (data) {
if (data[key]) {
resolve(data[key]);
}
}
resolve(false);
});
});
}
}
24 changes: 21 additions & 3 deletions src/ui/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function resize(zoom: number) {
}
}

function openHelp() {
async function openHelp() {
let url =
'https://github.com/Authenticator-Extension/Authenticator/wiki/Chrome-Issues';

Expand All @@ -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;
Expand All @@ -81,7 +97,9 @@ async function menu(_ui: UI) {
zoom,
useAutofill,
useHighContrast,
newStorageLocation: localStorage.storageLocation
newStorageLocation: localStorage.storageLocation,
backupDisabled,
storageArea
},
methods: {
openLink: (url: string) => {
Expand Down
8 changes: 4 additions & 4 deletions view/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@
<!-- Storage Settings -->
<div class="text">{{ i18n.storage_location_info }}</div>
<label class="combo-label">{{ i18n.storage_location }}</label>
<select v-model="newStorageLocation" v-on:change="migrateStorage()">
<select v-model="newStorageLocation" :disabled="storageArea" v-on:change="migrateStorage()">
<option value="sync">sync</option>
<option value="local">local</option>
</select>
<!-- 3rd Party Backup Services -->
<div class="text">{{ i18n.storage_sync_info }}</div>
<div v-show="!backupDisabled" class="text">{{ i18n.storage_sync_info }}</div>
<p></p>
<div class="button" v-on:click="showInfo('drive')">Google Drive</div>
<div class="button" v-on:click="showInfo('dropbox')">Dropbox</div>
<div class="button" v-show="!backupDisabled" v-on:click="showInfo('drive')">Google Drive</div>
<div class="button" v-show="!backupDisabled" v-on:click="showInfo('dropbox')">Dropbox</div>
</div>
<!-- POPUP PAGE SETTINGS -->
<div v-show="info === 'resize'">
Expand Down