From 0cf6011e0208700b7ac208b084f9163a27d09c98 Mon Sep 17 00:00:00 2001 From: Bar Hatsor <34835685+barhatsor@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:17:00 +0300 Subject: [PATCH 01/15] Update gitauth.js --- git/gitauth.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/git/gitauth.js b/git/gitauth.js index efb4ed8777..9c0802b161 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'); + + } }) From 54d28e22f43f1f5ae1779f666e8e4edbf0cb95c1 Mon Sep 17 00:00:00 2001 From: Bar Hatsor <34835685+barhatsor@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:19:09 +0300 Subject: [PATCH 02/15] Update login.html --- git/login.html | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/git/login.html b/git/login.html index 4f0bab12d3..704b30f60b 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?gitToken=' + code; } From a5922a12fc1defb344fc3e3bc6d82bb608d564ab Mon Sep 17 00:00:00 2001 From: Bar Hatsor <34835685+barhatsor@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:24:53 +0300 Subject: [PATCH 03/15] Update links.js --- links.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/links.js b/links.js index 9a52eb55e5..7e92eb403d 100644 --- a/links.js +++ b/links.js @@ -111,6 +111,12 @@ function decodeLink(url) { } + if (link.get('gitToken')) { + + linkData.gitToken = link.get('gitToken'); + + } + // legacy link type From e8798a2897c96db90533719ea5a26e1747c00734 Mon Sep 17 00:00:00 2001 From: Bar Hatsor <34835685+barhatsor@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:26:52 +0300 Subject: [PATCH 04/15] Update links.js --- links.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/links.js b/links.js index 7e92eb403d..970504c5e6 100644 --- a/links.js +++ b/links.js @@ -111,9 +111,9 @@ function decodeLink(url) { } - if (link.get('gitToken')) { + if (link.get('gitCode')) { - linkData.gitToken = link.get('gitToken'); + linkData.gitCode = link.get('gitCode'); } From 283696a70a640af035f0b48f5a675c76b2b33ce8 Mon Sep 17 00:00:00 2001 From: Bar Hatsor <34835685+barhatsor@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:27:00 +0300 Subject: [PATCH 05/15] Update login.html --- git/login.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/login.html b/git/login.html index 704b30f60b..491f4f9a92 100644 --- a/git/login.html +++ b/git/login.html @@ -33,7 +33,7 @@ } else { - window.location.href = '/full?gitToken=' + code; + window.location.href = '/full?gitCode=' + code; } From d80e6eca433b4800267bc7a09f83eee0f724338a Mon Sep 17 00:00:00 2001 From: Bar Hatsor <34835685+barhatsor@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:27:45 +0300 Subject: [PATCH 06/15] Update gitauth.js --- git/gitauth.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/git/gitauth.js b/git/gitauth.js index 9c0802b161..219393c0cc 100644 --- a/git/gitauth.js +++ b/git/gitauth.js @@ -17,7 +17,7 @@ window.onload = async () => { linkData = decodeLink(window.location.href); // clear URL - window.history.pushState(window.location.origin, 'Codeit', window.location.origin + '/full'); + window.history.replaceState(window.location.origin, 'Codeit', window.location.origin + '/full'); // if treeLoc is in local storage @@ -109,6 +109,35 @@ window.onload = async () => { } }) + + // if git code exists in link + if (linkData.gitCode) { + + // hide intro screen + sidebar.classList.remove('intro'); + + // if on safari, refresh header color + if (isSafari) { + + 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); + + } loadLS(); From 0f3324813c52fe16b6d5584e3767f10dfd0a0fe4 Mon Sep 17 00:00:00 2001 From: Bar Hatsor <34835685+barhatsor@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:28:01 +0300 Subject: [PATCH 07/15] Update client-channel.js --- worker/client-channel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 96a20ff7a18365e000a81dfb03fcf8b0eb2b7b0a Mon Sep 17 00:00:00 2001 From: Bar Hatsor <34835685+barhatsor@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:34:42 +0300 Subject: [PATCH 08/15] Update gitauth.js --- git/gitauth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/gitauth.js b/git/gitauth.js index 219393c0cc..d40b6256a1 100644 --- a/git/gitauth.js +++ b/git/gitauth.js @@ -17,7 +17,7 @@ window.onload = async () => { linkData = decodeLink(window.location.href); // clear URL - window.history.replaceState(window.location.origin, 'Codeit', window.location.origin + '/full'); + window.history.pushState(window.location.origin, 'Codeit', window.location.origin + '/full'); // if treeLoc is in local storage From 99faf49a1774d4f0498049cf236fc8f6d3cad6fb Mon Sep 17 00:00:00 2001 From: Bar Hatsor <34835685+barhatsor@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:37:49 +0300 Subject: [PATCH 09/15] Update gitauth.js --- git/gitauth.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/git/gitauth.js b/git/gitauth.js index d40b6256a1..7c6cc8b439 100644 --- a/git/gitauth.js +++ b/git/gitauth.js @@ -109,6 +109,10 @@ window.onload = async () => { } }) + + + loadLS(); + // if git code exists in link if (linkData.gitCode) { @@ -139,9 +143,6 @@ window.onload = async () => { } - - loadLS(); - } async function getGithubToken(gitCode) { From dfa2335009b88cc3505889a8e183f7e4aeeaa60f Mon Sep 17 00:00:00 2001 From: Bar Hatsor <34835685+barhatsor@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:39:04 +0300 Subject: [PATCH 10/15] Update gitauth.js --- git/gitauth.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/git/gitauth.js b/git/gitauth.js index 7c6cc8b439..8221920ada 100644 --- a/git/gitauth.js +++ b/git/gitauth.js @@ -111,9 +111,6 @@ window.onload = async () => { }) - loadLS(); - - // if git code exists in link if (linkData.gitCode) { @@ -139,9 +136,12 @@ window.onload = async () => { const gitCode = linkData.gitCode; // get git token from Github - getGithubToken(gitCode); + await getGithubToken(gitCode); } + + + loadLS(); } From 95923ebc2d9b12e176b5ce33a9997a7702bc611f Mon Sep 17 00:00:00 2001 From: Bar Hatsor <34835685+barhatsor@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:40:20 +0300 Subject: [PATCH 11/15] Update gitauth.js --- git/gitauth.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/git/gitauth.js b/git/gitauth.js index 8221920ada..498862d19e 100644 --- a/git/gitauth.js +++ b/git/gitauth.js @@ -109,7 +109,10 @@ window.onload = async () => { } }) - + + + loadLS(); + // if git code exists in link if (linkData.gitCode) { @@ -136,12 +139,9 @@ window.onload = async () => { const gitCode = linkData.gitCode; // get git token from Github - await getGithubToken(gitCode); + getGithubToken(gitCode); } - - - loadLS(); } From 1e167c2dd4e7db40f78a09fa7fbad459baa34287 Mon Sep 17 00:00:00 2001 From: Bar Hatsor <34835685+barhatsor@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:41:49 +0300 Subject: [PATCH 12/15] Update filebrowser.js --- filebrowser.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/filebrowser.js b/filebrowser.js index f44da42274..beded8c289 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 @@ -338,6 +338,8 @@ async function renderSidebarHTML() { return; } + + if (resp.message) return; // render modified files From 01652225d3178ba1591ce01fdcd441268a8519a7 Mon Sep 17 00:00:00 2001 From: Bar Hatsor <34835685+barhatsor@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:46:07 +0300 Subject: [PATCH 13/15] Update filebrowser.js --- filebrowser.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/filebrowser.js b/filebrowser.js index beded8c289..112dfd15b3 100644 --- a/filebrowser.js +++ b/filebrowser.js @@ -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 @@ -338,8 +338,6 @@ async function renderSidebarHTML() { return; } - - if (resp.message) return; // render modified files From 6c371947eb0948e171253e659c5b8681c6a17fdb Mon Sep 17 00:00:00 2001 From: Bar Hatsor <34835685+barhatsor@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:48:12 +0300 Subject: [PATCH 14/15] Update login.html --- git/login.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/git/login.html b/git/login.html index 491f4f9a92..8194536e9a 100644 --- a/git/login.html +++ b/git/login.html @@ -14,6 +14,7 @@ if (!isMobile) { + /* try { // check for cross-origin frame @@ -29,7 +30,7 @@ // 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; - } + }*/ } else { From 3d1a46cc351dd353960f1824d46e7a1c55b349e7 Mon Sep 17 00:00:00 2001 From: Bar Hatsor <34835685+barhatsor@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:48:55 +0300 Subject: [PATCH 15/15] Update login.html --- git/login.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/git/login.html b/git/login.html index 8194536e9a..491f4f9a92 100644 --- a/git/login.html +++ b/git/login.html @@ -14,7 +14,6 @@ if (!isMobile) { - /* try { // check for cross-origin frame @@ -30,7 +29,7 @@ // 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; - }*/ + } } else {