From c6b50d04f6c8af3099c47ed203cef3f492ec773c Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Wed, 22 Oct 2014 18:17:40 +0200 Subject: [PATCH] Use manifest config for webmail --- .jshintrc | 1 + src/js/app-config.js | 60 ++++++++++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/.jshintrc b/.jshintrc index 6c4c255..9e10c16 100644 --- a/.jshintrc +++ b/.jshintrc @@ -18,6 +18,7 @@ "unused": true, "predef": [ + "$", "self", "importScripts", "console", diff --git a/src/js/app-config.js b/src/js/app-config.js index 1fa6650..41271ad 100644 --- a/src/js/app-config.js +++ b/src/js/app-config.js @@ -1,34 +1,11 @@ 'use strict'; -var appVersion, cloudUrl, keychainUrl, clientId; - -// parse manifest to get configurations for current runtime -try { - var manifest = chrome.runtime.getManifest(); - // get key server base url - cloudUrl = _.find(manifest.permissions, function(permission) { - return typeof permission === 'string' && permission.indexOf('https://keys') === 0; - }); - // remove last '/' from url due to required syntax in manifest - cloudUrl = cloudUrl.substring(0, cloudUrl.length - 1); - // get keychain server base url - keychainUrl = _.find(manifest.permissions, function(permission) { - return typeof permission === 'string' && permission.indexOf('https://keychain') === 0; - }); - // remove last '/' from url due to required syntax in manifest - keychainUrl = keychainUrl.substring(0, keychainUrl.length - 1); - // get client ID for OAuth requests - clientId = manifest.oauth2.client_id; - // get the app version - appVersion = manifest.version; -} catch (e) {} - /** * Global app configurations */ exports.config = { - cloudUrl: cloudUrl || 'https://keys.whiteout.io', - privkeyServerUrl: keychainUrl || 'https://keychain.whiteout.io', + cloudUrl: 'https://keys.whiteout.io', + privkeyServerUrl: 'https://keychain.whiteout.io', adminUrl: 'https://admin-node.whiteout.io', wmailDomain: 'wmail.io', serverPrivateKeyId: 'EE342F0DDBB0F3BE', @@ -57,7 +34,7 @@ exports.config = { } }, gmail: { - clientId: clientId || '440907777130.apps.googleusercontent.com', + clientId: '440907777130.apps.googleusercontent.com', imap: { host: 'imap.gmail.com', port: 993, @@ -171,7 +148,7 @@ exports.config = { verificationUrl: '/verify/', verificationUuidLength: 36, dbVersion: 5, - appVersion: appVersion, + appVersion: undefined, outboxMailboxPath: 'OUTBOX', outboxMailboxName: 'Outbox', outboxMailboxType: 'Outbox', @@ -179,6 +156,35 @@ exports.config = { imapUpdateBatchSize: 25 }; +// parse manifest to get configurations for current runtime +if (typeof chrome !== 'undefined' && chrome.runtime && chrome.runtime.getManifest) { + setConfigParams(chrome.runtime.getManifest()); +} else if (typeof $ !== 'undefined' && $.get) { + $.get('/manifest.json', setConfigParams, 'json'); +} + +function setConfigParams(manifest) { + var cfg = exports.config, + cloudUrl, keychainUrl; + + // get key server base url + cloudUrl = _.find(manifest.permissions, function(permission) { + return typeof permission === 'string' && permission.indexOf('https://keys') === 0; + }); + // remove last '/' from url due to required syntax in manifest + cfg.cloudUrl = cloudUrl.substring(0, cloudUrl.length - 1); + // get keychain server base url + keychainUrl = _.find(manifest.permissions, function(permission) { + return typeof permission === 'string' && permission.indexOf('https://keychain') === 0; + }); + // remove last '/' from url due to required syntax in manifest + cfg.privkeyServerUrl = keychainUrl.substring(0, keychainUrl.length - 1); + // get client ID for OAuth requests + cfg.gmail.clientId = manifest.oauth2.client_id; + // get the app version + cfg.appVersion = manifest.version; +} + /** * Strings are maintained here */