diff --git a/options/options.js b/options/options.js index f5ce139..891f39e 100644 --- a/options/options.js +++ b/options/options.js @@ -77,6 +77,9 @@ $(() => { $('#login-user').text(`${user}${domain}`).attr('href', userLink); $('#token').attr('href', tokenLink); }) + .then(() => { + auth(); + }) .catch(err => { //not logged in }) @@ -412,7 +415,7 @@ function loginGitLabToken(param) { } function logout() { - chrome.storage.sync.remove(['scm', 'token', 'user', 'baseUrl', 'googleApiKey'], () => { + chrome.storage.sync.remove(['scm', 'token', 'user', 'baseUrl', 'gapiToken', 'gapiRefreshToken'], () => { location.reload(); }); chrome.storage.local.get('tab', (item) => { @@ -447,4 +450,22 @@ function addStar(token) { }) .always(resolve); }) +} + +function auth() { + return new Promise((resolve, reject) => { + chrome.runtime.sendMessage({ + cmd: 'login', + interactive: true + }, token => { + if (token == null) { + reject("can not get oauth token, currently only support Chrome"); + } else { + chrome.storage.sync.set({ + "gapiToken": token + }); + resolve(token); + } + }); + }); } \ No newline at end of file diff --git a/src/gas-hub.js b/src/gas-hub.js index 4047c5c..62c771c 100644 --- a/src/gas-hub.js +++ b/src/gas-hub.js @@ -49,6 +49,9 @@ function load() { .then(updateBranch) .then(updateGist) .then(initPageEvent) + .catch((err) => { + showLog(err, LEVEL_ERROR); + }) break; case 'not match': break; @@ -342,8 +345,15 @@ function auth() { cmd: 'login', interactive: true }, token => { - context.gapiToken = token; - resolve(token); + if (token == null) { + reject("can not get oauth token, currently only support Chrome"); + } else { + context.gapiToken = token; + chrome.storage.sync.set({ + "gapiToken": token + }); + resolve(token); + } }); }); }