Skip to content

Commit

Permalink
Copied recent changes from head: mousein/out from sidepanel, better d…
Browse files Browse the repository at this point in the history
…ark mode bookmarker, source url from manifest and ony use major.minor, typo in manifest: sidePanel.html
  • Loading branch information
tconfrey committed Dec 16, 2024
1 parent 88ca26f commit 178b028
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 15 deletions.
1 change: 1 addition & 0 deletions versions/1.2/app/BTAppNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,7 @@ const Handlers = {
"tabGroupCreated": tabGroupCreated,
"tabGroupUpdated": tabGroupUpdated,
"noSuchNode": noSuchNode, // bg is letting us know we requested action on a non-existent tab or tg
"mouseOut": sidePanelMouseOut, // sidepanel tells us mouse is out, undo hover states etc
};

// Set handler for extension messaging
Expand Down
19 changes: 19 additions & 0 deletions versions/1.2/app/bt.js
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,7 @@ function updateTabIndices(indices) {
function buttonShow(e) {
// Show buttons to perform row operations, triggered on hover
$(this).addClass("hovered");
sidePanelMouseIn(); // undo mouse out from containing sidepanel, see below
const td = $(this).find(".left");

if ($("#buttonRow").index() < 0) {
Expand Down Expand Up @@ -1426,6 +1427,24 @@ function buttonHide() {
$("#buttonRow").detach().appendTo($("#dialog"));
}

function sidePanelMouseOut() {
// Message from containing sidepanel, remove tooltips, hovers etc
$("#buttonRow").hide();
if (window.mouseOutStyle) return; // already set
const newStyle = '[data-wenk]:hover:after {visibility: hidden;}'
const style = document.createElement('style');
style.textContent = newStyle;
document.head.appendChild(style);
window.mouseOutStyle = style;
}
function sidePanelMouseIn() {
// undo mouse out from above
if (window.mouseOutStyle) {
document.head.removeChild(window.mouseOutStyle);
window.mouseOutStyle = null;
}
}

function toggleMoreButtons(e) {
// show/hide non essential buttons
$("#otherButtons").toggle(100, 'easeInCirc', () => {
Expand Down
12 changes: 10 additions & 2 deletions versions/1.2/extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const storageKeys = ["BTFileText", // golden source of BT .org
"newInstall", // true/false, for popup display choice
"newVersion", // used for popup to indicate an update to user
"permissions", // perms granted
"BTManagerHome", // open in Window, browser Side Panel or Tab
"Config", // General config values
"BTManagerLocation", // {top, left, width, height} of panel
"topics"]; // used for popup display

Expand All @@ -150,7 +150,15 @@ chrome.runtime.onInstalled.addListener(deets => {
chrome.storage.local.remove(key);
});
});
UpdateInstall = deets.previousVersion;

// Set updateInstall only if not a point release. ie 1->2 or 1.1 -> 1.2 are upgrades, 1.2 -> 1.2.1 is not
const newVersion = chrome.runtime.getManifest().version;
const prevVersion = deets.previousVersion;
const [newMajor, newMinor] = newVersion.split('.').map(Number);
const [prevMajor, prevMinor] = prevVersion.split('.').map(Number);
if (newMajor !== prevMajor || newMinor !== prevMinor) {
UpdateInstall = prevVersion;
}
}
});

Expand Down
4 changes: 2 additions & 2 deletions versions/1.2/extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "__MSG_appName__",
"description": "__MSG_appDesc__",
"default_locale": "en",
"version": "1.2",
"version": "1.2.1",
"permissions": ["tabs", "storage", "tabGroups", "webNavigation", "bookmarks", "sidePanel"],

"background": {
Expand Down Expand Up @@ -40,6 +40,6 @@
}
},
"side_panel": {
"default_path": "sidepanel.html"
"default_path": "sidePanel.html"
}
}
12 changes: 7 additions & 5 deletions versions/1.2/extension/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
--btHeaderBackground: linear-gradient(180deg, #F1F1F1 0%, #C3CBCB 52.6%, #C8CFD0 100%);
--btBodyBackground: linear-gradient(180deg, rgba(196, 196, 196, 0.28) 0%, rgba(196, 196, 196, 0.3) 14.58%, rgba(196, 196, 196, 0.1) 100%);
--btTextColor: #0C4F6B;
--btBackground: #bed8be;
--btBackground: white;

--btHighlightColor: #cec;
--btSelected: #7bb07b;
Expand All @@ -46,8 +46,7 @@
--btInputForeground: white;
--awesompleteBackground: #566564; /*linear-gradient(to bottom, black, hsla(0,0%,0%,.6));*/

--btBackground: #bed8be;

--btBackground: #c3cac3;
}


Expand All @@ -58,7 +57,7 @@ body {
padding-bottom: 30px;
overflow: hidden;
margin: 0px;
background: white;
background: var(--btBackground);

font-family: var(--btFont);
font-style: normal;
Expand Down Expand Up @@ -99,12 +98,14 @@ h2 {
font-weight: 700;
font-size: 12px;
line-height: 14px;
color: #0C4F6B;
}
h3 {
font-weight: 400;
font-size: 12px;
line-height: 14px;
margin-bottom: 6px;
color: #0C4F6B;
}
.tgPages {
display: none;
Expand All @@ -119,6 +120,7 @@ hr {
label {
position: relative;
top: -3px;
color: #0C4F6B;
}
#saveSpan {
float:left;
Expand Down Expand Up @@ -188,7 +190,7 @@ input[type=text], textarea {
margin-bottom: -5px;
margin-right: 15px;
font-style: italic;
color: var(--btTextColor);
color: #0C4F6B;
display: none;
}
.awesomplete {
Expand Down
2 changes: 1 addition & 1 deletion versions/1.2/extension/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Opening the BrainTool Topic Manager at its previously saved location...
</p>
<p id="upgradeMessage">
<b>Upgrading to BrainTool <span id="upgradeVersion"></span>. <br/>Restart is required. <br/>Release Notes will open with details after restart.</b>
<b>Upgrading to BrainTool <span id="upgradeVersion"></span>. <br/>Please re-open the Topic Manager. <br/>Release Notes will open if necessary, after restart.</b>
</p>
<p id="sidepanelMessage">
<b>Open BrainTool in the sidepanel?</b>
Expand Down
13 changes: 9 additions & 4 deletions versions/1.2/extension/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ chrome.storage.local.get(contextVariables, async val => {
const window = await chrome.windows.getCurrent();
chrome.sidePanel.open({windowId: window.id});
});
// if (confirm('BrainTool is not currently open. Click OK to open it now.')) { chrome.sidePanel.open({}); }
val['BTTab'] && chrome.tabs.remove(val['BTTab']); // close tab if its open
return;
}
}
Expand Down Expand Up @@ -146,12 +146,17 @@ function openTopicManager(home = 'WINDOW', location) {
(tabs => {if (tabs.length) chrome.tabs.remove(tabs.map(tab => tab.id));})
);

// Get server url from the manifest object. nb manifest needs app/* so need to strip *
// Get server url from the manifest object, add '${version}/app' unless local. nb manifest needs app/* so need to strip *
const manifest = chrome.runtime.getManifest();
const contentScripts = manifest.content_scripts;
const match = contentScripts[0].matches[0];
const version = manifest.version;
const url = match.replace(/\*+$/, '') + version + '/app';
const localhost = match.includes('localhost');
let version = manifest.version;
// version is x.y.z or x.y, need to strip off the .z if present
const parts = version.split('.');
if (parts.length > 2) version = parts.slice(0, 2).join('.');

const url = match.replace(/\*+$/, '') + (localhost ? '' : (version + '/app'));

console.log('loading from ', url);

Expand Down
24 changes: 23 additions & 1 deletion versions/1.2/extension/sidePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
- open a port so extension knows when sidepanel is closed
- set iframe src to the server url in manifest
- wait for iframe to load before initializing, then send window.id to extension to set BTWin
- add listeners for mouseleave/out events, let the app know
- set background color based on theme
- listen for reconnect request from worker or popup
*/
const SIDEPANEL=true;
Expand All @@ -15,8 +17,9 @@ let BTPort;
const manifest = chrome.runtime.getManifest();
const contentScripts = manifest.content_scripts;
const match = contentScripts[0].matches[0];
const localhost = match.includes('localhost');
const version = manifest.version;
const url = match.replace(/\*+$/, '') + version + '/app';
const url = match.replace(/\*+$/, '') + (localhost ? '' : (version + '/app'));
const iframe = document.getElementById('BTTopicManager');
iframe.src = url;
})();
Expand All @@ -29,6 +32,25 @@ document.addEventListener('DOMContentLoaded', function() {
iframe.addEventListener('load', () => chrome.runtime.sendMessage({'from': 'btwindow', 'function': 'initializeExtension', 'BTWin': window.id }));
iframe.focus();
});

// add listeners on mouse leave/out. its hard to capture these from inside the iframe
iframe.addEventListener('mouseleave', () => sendMessage({function: 'mouseOut'}) );
window.addEventListener('mouseout', () => sendMessage({function: 'mouseOut'}) );

// set backgrond color base on dark/light mode
chrome.storage.local.get(['Theme'], async val => {
if (val['Theme'] === 'DARK') {
document.body.style.backgroundColor = '#2D2D2D';
} else {
document.body.style.backgroundColor = '#whitesmoke';
}
});
});

// add listener on mouse out
window.addEventListener('mouseout', (e) => {
console.log('--SP --mouse out');
sendMessage({function: 'mouseOut'});
});

chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
Expand Down

0 comments on commit 178b028

Please sign in to comment.