diff --git a/public/res/constants.js b/public/res/constants.js index 6e3e353d..0788b031 100644 --- a/public/res/constants.js +++ b/public/res/constants.js @@ -43,8 +43,7 @@ define([], function() { constants.GATEKEEPER_URL = "https://stackedit-io-gatekeeper.herokuapp.com/"; constants.TUMBLR_PROXY_URL = "https://stackedit-io-tumblr-proxy.herokuapp.com/"; } - - if(location.hostname.indexOf("benweet.github.io") === 0) { + else if(location.hostname.indexOf("benweet.github.io") === 0) { constants.BASE_URL = 'http://benweet.github.io/stackedit/'; constants.GOOGLE_CLIENT_ID = '241271498917-jpto9lls9fqnem1e4h6ppds9uob8rpvu.apps.googleusercontent.com'; constants.GITHUB_CLIENT_ID = 'fa0d09514da8377ee32e'; @@ -53,8 +52,7 @@ define([], function() { constants.WORDPRESS_CLIENT_ID = '3185'; constants.WORDPRESS_PROXY_URL = "https://stackedit-wordpress-proxy.herokuapp.com/"; } - - if(location.hostname.indexOf("benweet.insomnia247.nl") === 0) { + else if(location.hostname.indexOf("benweet.insomnia247.nl") === 0) { constants.BASE_URL = "http://benweet.insomnia247.nl/stackedit/"; constants.GOOGLE_CLIENT_ID = '241271498917-52hae7a08hv7ltenv7km8h7lghno9sk3.apps.googleusercontent.com'; constants.GITHUB_CLIENT_ID = 'd2943d6074b2d9c4a830'; diff --git a/public/res/extensions/documentTitle.js b/public/res/extensions/documentTitle.js index 9f60e76f..8b473e18 100644 --- a/public/res/extensions/documentTitle.js +++ b/public/res/extensions/documentTitle.js @@ -13,7 +13,7 @@ define([ var fileDesc; var $fileTitleNavbar; - var updateTitle = function(fileDescParameter) { + var updateTitle = _.debounce(function(fileDescParameter) { if(fileDescParameter !== fileDesc) { return; } @@ -24,11 +24,8 @@ define([ $(".file-title").text(title); $(".input-file-title").val(title); - if(layout !== undefined) { - // Use defer to make sure UI has been updated - _.defer(layout.resizeAll); - } - }; + layout && layout.resizeAll(); + }, 50); documentTitle.onFileSelected = function(fileDescParameter) { fileDesc = fileDescParameter; @@ -40,6 +37,7 @@ define([ documentTitle.onSyncRemoved = updateTitle; documentTitle.onNewPublishSuccess = updateTitle; documentTitle.onPublishRemoved = updateTitle; + documentTitle.onReady = updateTitle; documentTitle.onReady = function() { $fileTitleNavbar = $(".file-title-navbar"); diff --git a/public/res/helpers/googleHelper.js b/public/res/helpers/googleHelper.js index 12192de5..c461e9c4 100644 --- a/public/res/helpers/googleHelper.js +++ b/public/res/helpers/googleHelper.js @@ -16,20 +16,20 @@ define([ var authorizationMgrMap = {}; function AuthorizationMgr(accountId) { var permissionList = {}; - var isAuthorized = false; + var refreshFlag = true; _.each((storage[accountId + '.permissions'] || '').split(';'), function(permission) { permission && (permissionList[permission] = true); }); - this.reset = function() { - isAuthorized = false; + this.setRefreshFlag = function() { + refreshFlag = true; }; this.isAuthorized = function(permission) { - return isAuthorized && _.has(permissionList, permission); + return refreshFlag === false && _.has(permissionList, permission); }; this.add = function(permission) { permissionList[permission] = true; storage[accountId + '.permissions'] = _.keys(permissionList).join(';'); - isAuthorized = true; + refreshFlag = false; }; this.getListWithNew = function(permission) { var result = _.keys(permissionList); @@ -103,7 +103,7 @@ define([ 'https://picasaweb.google.com/data/' ] }; - function authenticate(task, permission, accountId, refresh) { + function authenticate(task, permission, accountId) { accountId = accountId || 'google.0'; var authorizationMgr = authorizationMgrMap[accountId]; if(!authorizationMgr) { @@ -116,7 +116,7 @@ define([ if(token.access_token) { immediate = true; gapi.auth.setToken(token); - if(!refresh && authorizationMgr.isAuthorized(permission)) { + if(authorizationMgr.isAuthorized(permission)) { task.chain(); return; } @@ -138,9 +138,10 @@ define([ } var scopeList = _.chain(scopeMap).pick(authorizationMgr.getListWithNew(permission)).flatten().value(); gapi.auth.authorize({ - 'client_id': constants.GOOGLE_CLIENT_ID, - 'scope': scopeList, - 'immediate': immediate + client_id: constants.GOOGLE_CLIENT_ID, + scope: scopeList, + immediate: immediate, + authuser: immediate ? undefined : '' }, function(authResult) { gapi.client.load('drive', 'v2', function() { if(!authResult || authResult.error) { @@ -157,7 +158,7 @@ define([ } // Success authorizationMgr.add(permission); - authorizationMgr.saveToken(); + immediate === false && authorizationMgr.saveToken(); task.chain(); }); }); @@ -168,7 +169,9 @@ define([ googleHelper.refreshGdriveToken = function(accountId) { var task = new AsyncTask(); connect(task); - authenticate(task, 'gdrive', accountId, true); + var authorizationMgr = authorizationMgrMap[accountId]; + authorizationMgr && authorizationMgr.setRefreshFlag(); + authenticate(task, 'gdrive', accountId); task.enqueue(); }; @@ -626,7 +629,7 @@ define([ } else if(error.code === 401 || error.code === 403 || error.code == "token_refresh_required") { _.each(authorizationMgrMap, function(authorizationMgr) { - authorizationMgr.reset(); + authorizationMgr.setRefreshFlag(); }); errorMsg = "Access to Google account is not authorized."; task.retry(new Error(errorMsg), 1); @@ -635,7 +638,7 @@ define([ else if(error.code === 0 || error.code === -1) { connected = false; _.each(authorizationMgrMap, function(authorizationMgr) { - authorizationMgr.reset(); + authorizationMgr.setRefreshFlag(); }); core.setOffline(); errorMsg = "|stopPublish"; @@ -709,7 +712,7 @@ define([ pickerBuilder.enableFeature(google.picker.Feature.NAV_HIDDEN); pickerBuilder.enableFeature(google.picker.Feature.MULTISELECT_ENABLED); pickerBuilder.addView(view); - pickerBuilder.setOAuthToken(gapi.auth.getToken()); + pickerBuilder.setOAuthToken(gapi.auth.getToken().access_token); } else if(pickerType == 'folder') { view = new google.picker.DocsView(google.picker.ViewId.FOLDERS); @@ -718,7 +721,7 @@ define([ view.setMimeTypes('application/vnd.google-apps.folder'); pickerBuilder.enableFeature(google.picker.Feature.NAV_HIDDEN); pickerBuilder.addView(view); - pickerBuilder.setOAuthToken(gapi.auth.getToken()); + pickerBuilder.setOAuthToken(gapi.auth.getToken().access_token); } else if(pickerType == 'img') { view = new google.picker.PhotosView(); diff --git a/public/res/html/bodyIndex.html b/public/res/html/bodyIndex.html index bf6871b1..2c96911e 100644 --- a/public/res/html/bodyIndex.html +++ b/public/res/html/bodyIndex.html @@ -117,6 +117,11 @@ Google Drive
  • Export to Google Drive
  • +
  • Import from + Google Drive (secondary)
  • +
  • Export + to Google Drive (secondary)
  • - + + diff --git a/public/res/publisher.js b/public/res/publisher.js index 368911e8..cd1ba169 100644 --- a/public/res/publisher.js +++ b/public/res/publisher.js @@ -16,6 +16,7 @@ define([ "providers/gistProvider", "providers/githubProvider", "providers/gdriveProvider", + "providers/gdrivesecProvider", "providers/sshProvider", "providers/tumblrProvider", "providers/wordpressProvider" diff --git a/public/res/styles/base.less b/public/res/styles/base.less index 8da64c51..b26a96d5 100644 --- a/public/res/styles/base.less +++ b/public/res/styles/base.less @@ -325,7 +325,7 @@ kbd { background-position: 0 0; } -.icon-provider-gdrive { +.icon-provider-gdrive, .icon-provider-gdrivesec { background-position: -18px 0; &.realtime { background-position: -162px 0; diff --git a/public/res/synchronizer.js b/public/res/synchronizer.js index 5232e4c2..a957f54a 100644 --- a/public/res/synchronizer.js +++ b/public/res/synchronizer.js @@ -8,7 +8,8 @@ define([ "fileMgr", "classes/Provider", "providers/dropboxProvider", - "providers/gdriveProvider" + "providers/gdriveProvider", + "providers/gdrivesecProvider" ], function($, _, utils, storage, eventMgr, fileSystem, fileMgr, Provider) { var synchronizer = {};