Home button between back and forward; Alt+Home

The on-screen buttons are now back / home / forward. Home (and Alt+Home)
loads the site on screen from the address it was set up with under Sites &
Page Timing, hidden sites included. A shared buildTabUrl() builds that
address for both the first load and the home button.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013wi3ZQveYdjfcrEsyazq32
This commit is contained in:
Claude
2026-11-06 18:31:38 +00:00
parent b836fd6771
commit 9c1f22382e
5 changed files with 72 additions and 25 deletions
+58 -13
View File
@@ -772,6 +772,23 @@ function rotateToNextSite(){
}
}
// The address a site is loaded from: its configured URL, with the site's
// own login filled in (if it has one) and local files/folders turned into
// the kiosk's viewer addresses. Used when a site's view is first created
// and by the home button, so both always agree.
function buildTabUrl(t){
let url=t.url;
if(t.username&&t.password){
try{
const u=new URL(t.url);
u.username=t.username;
u.password=t.password;
url=u.toString();
}catch(e){}
}
return resolveLocalSite(url);
}
function attachView(i){
closeHTMLKeyboard();
@@ -1157,11 +1174,16 @@ function returnToTabs(){
// mouse's side buttons, and the optional on-screen buttons). Not while the
// screen is locked or a dialog (PIN, WiFi, power...) is open on top - the
// keys would silently navigate the page hidden behind it.
function historyGo(direction){
if(isLockedOut)return;
function historyBlocked(){
if(isLockedOut)return true;
for(const w of [pinWindow,wifiWindow,promptWindow,pauseWindow]){
if(w&&!w.isDestroyed())return;
if(w&&!w.isDestroyed())return true;
}
return false;
}
function historyGo(direction){
if(historyBlocked())return;
const view=showingHidden?hiddenViews[currentHiddenIndex]:views[currentIndex];
if(!view||!view.webContents||view.webContents.isDestroyed())return;
const wc=view.webContents;
@@ -1174,6 +1196,36 @@ function historyGo(direction){
markActivity();
}
// The tab (index into tabs) behind the n-th hidden view: hidden sites are the
// ones with duration -1, in order.
function hiddenViewIndexToTabIndex(h){
let n=0;
for(let i=0;i<tabs.length;i++){
if(parseInt(tabs[i].duration)===-1){
if(n===h)return i;
n++;
}
}
return -1;
}
// Home button / Alt+Home: back to the address this site was set up with
// (Core Settings -> Sites & Page Timing), whatever page the user has
// browsed to since. Acts on the site that's on screen, so with several
// sites each one goes to its own address.
function historyHome(){
if(historyBlocked())return;
const view=showingHidden?hiddenViews[currentHiddenIndex]:views[currentIndex];
if(!view||!view.webContents||view.webContents.isDestroyed())return;
const tabIdx=showingHidden?hiddenViewIndexToTabIndex(currentHiddenIndex):viewIndexToTabIndex(currentIndex);
if(tabIdx<0||!tabs[tabIdx])return;
const target=buildTabUrl(tabs[tabIdx]);
if(view.webContents.getURL()!==target){
view.webContents.loadURL(target).catch(()=>{});
}
markActivity();
}
function showPinEntry(){
if(pinWindow&&!pinWindow.isDestroyed()){
pinWindow.focus();
@@ -1579,16 +1631,7 @@ async function createWindow(){
mainWindow.addBrowserView(view);
let url=t.url;
if(t.username&&t.password){
try{
const u=new URL(t.url);
u.username=t.username;
u.password=t.password;
url=u.toString();
}catch(e){}
}
url=resolveLocalSite(url);
const url=buildTabUrl(t);
const initialOrigin=new URL(t.url).origin;
@@ -1691,6 +1734,7 @@ async function createWindow(){
ipcMain.on('toggle-hidden',toggleHidden);
ipcMain.on('history-nav',(event,direction)=>{
if(direction==='back'||direction==='forward')historyGo(direction);
else if(direction==='home')historyHome();
});
ipcMain.on('return-to-tabs',forceReturnToTabs);
ipcMain.on('user-activity',markActivity);
@@ -1890,6 +1934,7 @@ async function createWindow(){
// Standard browser keys for page back/forward.
globalShortcut.register('Alt+Left',()=>{historyGo('back');});
globalShortcut.register('Alt+Right',()=>{historyGo('forward');});
globalShortcut.register('Alt+Home',()=>{historyHome();});
globalShortcut.register('F10',toggleHidden);
globalShortcut.register('Control+H',toggleHidden);
+3 -2
View File
@@ -115,7 +115,7 @@ ipcRenderer.on('keyboard-button-enabled',(event,enabled)=>{
}
});
// On-screen back/forward buttons (top middle, half transparent) - an
// On-screen back / home / forward buttons (top middle, half transparent) - an
// option for screens with no keyboard or mouse side buttons.
let historyButtonsEnabled=false;
let historyBar=null;
@@ -280,7 +280,7 @@ window.addEventListener('DOMContentLoaded',()=>{
historyBar.id='electron-history-bar';
historyBar.style.cssText=`
position:fixed;top:12px;left:50%;transform:translateX(-50%);
display:none;gap:14px;z-index:999999;opacity:${historyOpacity};
display:none;gap:18px;z-index:999999;opacity:${historyOpacity};
transition:opacity 0.15s;user-select:none;
`;
const makeButton=(label,direction,path)=>{
@@ -302,6 +302,7 @@ window.addEventListener('DOMContentLoaded',()=>{
};
historyBar.append(
makeButton('Back','back','M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z'),
makeButton('Home (this site\'s start page)','home','M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z'),
makeButton('Forward','forward','M8.59 16.59L10 18l6-6-6-6-1.41 1.41L13.17 12z')
);
historyBar.addEventListener('mouseenter',()=>{historyBar.style.opacity=String(historyHoverOpacity());});