Skip to content

Commit

Permalink
WIP loading in chrome
Browse files Browse the repository at this point in the history
  • Loading branch information
nxmatic committed Feb 29, 2024
1 parent 6e7b081 commit dff3a41
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 143 deletions.
6 changes: 3 additions & 3 deletions app/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
<title>About - Nuxeo Dev Tools</title>
<link href="libs/bootstrap.min.css" rel="stylesheet">
<link href="styles/main.css" rel="stylesheet">
<script src="libs/jquery.js"></script>
<script src="scripts/browser.js"></script>
<script src="scripts/about.js"></script>
<script type="application/javascript" src="libs/jquery.min.js"></script>
<script type="application/javascript" src="scripts/browser.js"></script>
<script type="application/javascript"src="scripts/about.js"></script>
</head>
<body>
<div class="nxcontainer">
Expand Down
12 changes: 6 additions & 6 deletions app/es-reindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

<link href="libs/bootstrap.min.css" rel="stylesheet">
<link href="styles/main.css" rel="stylesheet">
<script src="libs/jquery.js"></script>
<script src="libs/bootstrap.js"></script>
<script src="libs/jquery.confirm.js"></script>
<script src="libs/purify.min.js"></script>
<script src="scripts/browser.js"></script>
<script src="scripts/popup.js"></script>
<script type="application/javascript" src="libs/jquery.min.js"></script>
<script type="application/javascript" src="libs/bootstrap.min.js"></script>
<script type="application/javascript" src="libs/jquery-confirm.min.js"></script>
<script type="application/javascript" src="libs/purify.min.js"></script>
<script type="application/javascript" src="scripts/browser.js"></script>
<script type="application/javascript" src="scripts/popup.js"></script>
</head>
<body>
<div class="nxcontainer" id="reindex-page">
Expand Down
11 changes: 5 additions & 6 deletions app/json.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
<pre><code class="json" id="json-string">

</code></pre>
<script src="libs/jquery.js"></script>
<script src="libs/bootstrap.js"></script>
<script src="libs/jquery.confirm.js"></script>
<script src="scripts/browser.js"></script>
<script src="scripts/json.js"></script>

<script type="application/javascript" src="libs/jquery.min.js"></script>
<script type="application/javascript" src="libs/bootstrap.min.js"></script>
<script type="application/javascript" src="libs/jquery-confirm.min.js"></script>
<script type="application/javascript" src="scripts/browser.js"></script>
<script type="application/javascript"src="scripts/json.js"></script>
</body>
</html>
15 changes: 7 additions & 8 deletions app/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
<title>Nuxeo Dev Tools</title>
<link rel=stylesheet href=libs/bootstrap.min.css>
<link rel=stylesheet href=styles/main.css>
<script src="libs/jquery.js"></script>
<script src="libs/bootstrap.js"></script>
<script src="libs/jquery.confirm.js"></script>
<script src="libs/purify.min.js"></script>
<script src=scripts/browser.js></script>
<script src=scripts/popup.js></script>

<script type="application/javascript" src="libs/bootstrap.min.js"></script>
<script type="application/javascript" src="libs/jquery.min.js"></script>
<script type="application/javascript" src="libs/jquery-confirm.min.js"></script>
<script type="application/javascript" src="libs/purify.min.js"></script>
<script type="application/javascript" src=scripts/browser.js></script>
<script type="application/javascript" src=scripts/popup.js></script>
</head>
<body>
<div class="shade">
Expand Down Expand Up @@ -76,7 +75,7 @@
<li><div class="server-name-url"></div></li>
<li id="connect-url">
<form class="search-container" id="options">
<input type="text" id="connect-url-input" class="form" placeholder="connect.nuxeo.com" results="5" />
<input type="text" id="connect-url-input" class="form" placeholder="https://connect.nuxeo.com" results="5" />
<div class="highlight-option">
<input type="checkbox" id="highlight-input" class="form" name="highlight">
<p id='highlight-label'>Highlight JSON</p>
Expand Down
36 changes: 23 additions & 13 deletions app/scripts/bkg/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ const studioExt = window.studioExt = window.studioExt || {};

let dependencies;

let CONNECT_DOMAIN = 'connect.nuxeo.com';
let CONNECT_URL = `https://${CONNECT_DOMAIN}`;
let CONNECT_URL = new URL('https://connect.nuxeo.com');

// Use the new Promise-based functions
getFromStorage('org.nuxeo.connect.url').then((res) => {
if (!res.value || res.value.length === 0) {
getFromStorage('org.nuxeo.connect.url').then((value) => {
if (!value || value.length === 0) {
return;
}
CONNECT_DOMAIN = new URL(res.value).hostname;
CONNECT_URL = res.value
CONNECT_URL = new URL(value);
}).catch((error) => {
console.error(error);
});

const setStudioUrl = window.setStudioUrl = (domain) => setToStorage({ value: domain }).then(() => {
CONNECT_DOMAIN = domain;
CONNECT_URL = `https://${CONNECT_DOMAIN}`;
}).catch((error) => {
console.error(error);
});
const setConnectUrl = window.setConnectUrl = (url) =>
setToStorage({
'org.nuxeo.connect.url': url.toString()
}).then(() => {
CONNECT_URL = url;
}).catch((error) => {
console.error(error);
});

const notification = window.notification = (idP, titleP, messageP, img, interaction, clickHandler) => {
const click = clickHandler;
Expand Down Expand Up @@ -123,6 +123,17 @@ const defaultServerError = {
};

const getCurrentTabUrl = window.getCurrentTabUrl = (callback) => {
// Check if tabUrl is available in the query parameters
const urlParams = new URLSearchParams(window.location.search);
const tabUrl = urlParams.get('tabUrl');

if (tabUrl) {
// If tabUrl is available, call the callback with tabUrl and return
callback(tabUrl);
return;
}

// If tabUrl is not available, continue with the original logic
const queryInfo = {
active: true,
currentWindow: true,
Expand Down Expand Up @@ -151,7 +162,6 @@ const getCurrentTabUrl = window.getCurrentTabUrl = (callback) => {
console.error(error);
});
};

function newDefaultNuxeo() { return newNuxeo({ baseURL: window.studioExt.server.url }); }

function handleErrors(error, serverError) {
Expand Down
12 changes: 7 additions & 5 deletions app/scripts/bkg/designer-live-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ const enable = (projectName, nuxeoInstanceBaseUrl) => {
// URL's port is not allowed in urlPattern, thus had to be removed.
nuxeoBaseUrl = nuxeoInstanceBaseUrl;
const urlPattern = `${nuxeoInstanceBaseUrl.replace(/:\d+/, '')}*`;
const connectLocation = CONNECT_URL.toString();
const workspaceLocation = new URL('/nuxeo/site/studio/v2/project/${projectName}/workspace/ws.resources', CONNECT_URL).toString();

browser.cookies
.getAll({ domain: CONNECT_DOMAIN })
.getAll({ domain: CONNECT_URL.hostname })
.then((cookies) => {
const cookieHeader = cookies
.map(x => x.name + '=' + x.value)
Expand All @@ -136,7 +138,7 @@ const enable = (projectName, nuxeoInstanceBaseUrl) => {
}, ['blocking']);

browser.webRequest.onBeforeRequest.addListener(addNewResources, {
urls: [`${CONNECT_URL}/nuxeo/site/studio/v2/project/${projectName}/workspace/ws.resources`],
urls: [workspaceLocation],
}, ['requestBody']);

let extraInfoSpec = ['blocking', 'requestHeaders']
Expand All @@ -145,15 +147,15 @@ const enable = (projectName, nuxeoInstanceBaseUrl) => {
}
// https://groups.google.com/a/chromium.org/g/chromium-extensions/c/vYIaeezZwfQ
browser.webRequest.onBeforeSendHeaders.addListener(addCookieHeaderForConnectRequest, {
urls: [`${CONNECT_URL}/*`],
urls: [`${connectLocation}/*`],
}, extraInfoSpec);

browser.webRequest.onCompleted.addListener(revertToDefault, {
urls: [`${CONNECT_URL}/*`],
urls: [`${connectLocation}/*`],
}, ['responseHeaders']);

// fetch available resources from Studio Project
return fetch(`${CONNECT_URL}/nuxeo/site/studio/v2/project/${projectName}/workspace/ws.resources`, {
return fetch(workspaceLocation, {
credentials: 'include',
}).then((response) => {
if (response.ok) {
Expand Down
41 changes: 41 additions & 0 deletions app/scripts/bkg/execute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright 2016-2022 Nuxeo
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

window.executeScript = (script, stopSearch, callback) => {
const blob = new Nuxeo.Blob({
content: new Blob([script], {
type: 'text/plain',
}),
name: 'readPackage.groovy',
mymeType: 'text/plain',
});

newDefaultNuxeo()
.operation('RunInputScript')
.params({
type: 'groovy',
})
.input(blob)
.execute()
.then(res => res.text())
.then(callback)
.catch((e) => {
if (stopSearch) {
stopSearch();
}
console.error(e);
});
};
28 changes: 14 additions & 14 deletions app/scripts/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ limitations under the License.
println JsonOutput.toJson([installed: addons]);`;

chrome.runtime.getBackgroundPage((bkg) => {
console.log('bkg is of type ' + typeof bkg);
console.log('bkg is of type ' + bkg.constructor.name);
function handleBackgroundPage(bkg) {
function debounce(fn, delay) {
let timer = null;
return function (...args) {
Expand Down Expand Up @@ -114,10 +112,10 @@ limitations under the License.
$('#designer-live-preview-button').removeClass('enabled');
}

const studioUrl = `${bkg.CONNECT_URL}/nuxeo/site/studio/ide?project=${packageName}`;
$('#log-into-studio').attr('href', studioUrl);
const packageLocation = new URL(`/nuxeo/site/studio/ide?project=${packageName}`, bkg.CONNECT_URL).toString();
$('#log-into-studio').attr('href', new URL('/nuxeo', bkg.CONNECT_URL).toString());
$('#studio').click(() => {
app.browser.createTabs(`${bkg.CONNECT_URL}/nuxeo/site/studio/ide?project=${packageName}`, bkg.studioExt.server.tabId);
app.browser.createTabs(packageLocation, bkg.studioExt.server.tabId);
});
$('#hot-reload-button').click(() => {
bkg.bkgHotReload(startLoadingHR, stopLoading, true, showDependencyError);
Expand Down Expand Up @@ -223,8 +221,8 @@ limitations under the License.
$('#connect-url').toggle();
});

if (bkg.CONNECT_DOMAIN !== 'connect.nuxeo.com') {
$('#connect-url-input').val(bkg.CONNECT_DOMAIN);
if (bkg.CONNECT_URL.hostname !== 'connect.nuxeo.com') {
$('#connect-url-input').val(bkg.CONNECT_URL.toString());
}

chrome.storage.sync.get('highlight', (res) => {
Expand All @@ -245,7 +243,7 @@ limitations under the License.
const input = $('#connect-url-input').val();
const highlight = $('#highlight-input').prop('checked');
if (input.length > 0) {
bkg.setStudioUrl(input, () => {
bkg.setConnectUrl(input, () => {
$('#connect-url').hide();
});
}
Expand All @@ -261,7 +259,7 @@ limitations under the License.
confirmButton: 'Reset',
cancelButton: 'Cancel',
confirm: () => {
bkg.setStudioUrl('connect.nuxeo.com', () => {
bkg.setConnectUrl('https://connect.nuxeo.com', () => {
$('#connect-url-input').val('');
$('#connect-url').hide();
});
Expand Down Expand Up @@ -331,8 +329,6 @@ limitations under the License.
}
});
}
console.log('from current TAB URL');

bkg.getCurrentTabUrl((url) => {
nuxeo = bkg.newNuxeo({
baseURL: url,
Expand All @@ -346,7 +342,7 @@ limitations under the License.
}).catch((e) => {
console.log(e);
});
chrome.tabs.executeScript(checkStudioPkg, noStudioPackageFound, (text) => {
bkg.executeScript(checkStudioPkg, noStudioPackageFound, (text) => {
const pkgName = JSON.parse(text).studio;
if (pkgName) {
studioPackageFound(pkgName);
Expand Down Expand Up @@ -731,5 +727,9 @@ limitations under the License.
console.log('O Canada!');
});
});
});
}

window.handleBackgroundPage = handleBackgroundPage;

app.browser.getBackgroundPage(handleBackgroundPage);
})(window);
48 changes: 0 additions & 48 deletions app/vendor.babel/chrome/manifest.json

This file was deleted.

Loading

0 comments on commit dff3a41

Please sign in to comment.