diff --git a/filebrowser.js b/filebrowser.js index f44da42274..112dfd15b3 100644 --- a/filebrowser.js +++ b/filebrowser.js @@ -193,7 +193,7 @@ async function renderSidebarHTML() { resp = await git.getItems(treeLoc); - if (resp.message == 'Not Found') { + if (resp.message && resp.message == 'Not Found') { // if couldn't find repository, show not found screen @@ -323,7 +323,7 @@ async function renderSidebarHTML() { } - if (resp.message == 'Bad credentials') { + if (resp.message && resp.message == 'Bad credentials') { // if failed to get items, // show login screen diff --git a/git/gitauth.js b/git/gitauth.js index efb4ed8777..498862d19e 100644 --- a/git/gitauth.js +++ b/git/gitauth.js @@ -63,8 +63,16 @@ window.onload = async () => { loginButton.addEventListener('click', () => { - - window.open('https://github.com/login/oauth/authorize?client_id=7ede3eed3185e59c042d&scope=repo,user,write:org', 'Login with Github', 'height=575,width=575'); + + if (isMobile) { + + window.location.href = 'https://github.com/login/oauth/authorize?client_id=7ede3eed3185e59c042d&scope=repo,user,write:org'; + + } else { + + window.open('https://github.com/login/oauth/authorize?client_id=7ede3eed3185e59c042d&scope=repo,user,write:org', 'Login with Github', 'height=575,width=575'); + + } }) @@ -101,9 +109,39 @@ window.onload = async () => { } }) + + + loadLS(); + + + // if git code exists in link + if (linkData.gitCode) { + + // hide intro screen + sidebar.classList.remove('intro'); + // if on safari, refresh header color + if (isSafari) { - loadLS(); + document.querySelector('meta[name="theme-color"]').content = '#313744'; + + onNextFrame(() => { + + document.querySelector('meta[name="theme-color"]').content = '#1a1c24'; + + }); + + } + + // start loading + startLoading(); + + const gitCode = linkData.gitCode; + + // get git token from Github + getGithubToken(gitCode); + + } } diff --git a/git/login.html b/git/login.html index 4f0bab12d3..491f4f9a92 100644 --- a/git/login.html +++ b/git/login.html @@ -3,20 +3,37 @@ const code = window.location.toString().replace(/.+code=/, ''); -try { - - // check for cross-origin frame - console.log(window.opener.location.href); +let isMobile = false; + +if (navigator.userAgentData + && navigator.userAgentData.mobile) isMobile = true; + +if (navigator.userAgent + && navigator.userAgent.includes('Mobile')) isMobile = true; + + +if (!isMobile) { - // post login token to opening window - window.opener.postMessage(code, window.location); - window.close(); + try { + + // check for cross-origin frame + console.log(window.opener.location.href); + + // post login token to opening window + window.opener.postMessage(code, window.location); + window.close(); + + } catch(e) { + + // if cannot access opening window (window is cross-origin) + // redirect to dev version and try posting login token from there + window.location.href = window.location.protocol + '//' + 'dev.' + window.location.host + window.location.pathname + window.location.search; + + } -} catch(e) { +} else { - // if cannot access opening window (window is cross-origin) - // redirect to dev version and try posting login token from there - window.location.href = window.location.protocol + '//' + 'dev.' + window.location.host + window.location.pathname + window.location.search; + window.location.href = '/full?gitCode=' + code; } diff --git a/links.js b/links.js index 9a52eb55e5..970504c5e6 100644 --- a/links.js +++ b/links.js @@ -111,6 +111,12 @@ function decodeLink(url) { } + if (link.get('gitCode')) { + + linkData.gitCode = link.get('gitCode'); + + } + // legacy link type diff --git a/worker/client-channel.js b/worker/client-channel.js index 27723fff81..3755efdf78 100644 --- a/worker/client-channel.js +++ b/worker/client-channel.js @@ -4,7 +4,7 @@ // update worker name when updating worker -const WORKER_NAME = 'codeit-worker-v525'; +const WORKER_NAME = 'codeit-worker-v526'; // internal paths