Give lock, PIN, WiFi and dialog windows keyboard focus when they open
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013wi3ZQveYdjfcrEsyazq32
This commit is contained in:
@@ -282,6 +282,7 @@ function showLockoutScreen(mode){
|
|||||||
// The boot screen takes the separate boot code when one is set.
|
// The boot screen takes the separate boot code when one is set.
|
||||||
const codeType=(lockoutMode==='boot'&&bootPassword)?bootCodeType:lockoutCodeType;
|
const codeType=(lockoutMode==='boot'&&bootPassword)?bootCodeType:lockoutCodeType;
|
||||||
lockoutWindow.loadFile(path.join(__dirname,'lockscreen.html'),{query:{type:codeType,mode:lockoutMode}});
|
lockoutWindow.loadFile(path.join(__dirname,'lockscreen.html'),{query:{type:codeType,mode:lockoutMode}});
|
||||||
|
grabKeyboardFocus(lockoutWindow);
|
||||||
|
|
||||||
lockoutWindow.on('closed',()=>{
|
lockoutWindow.on('closed',()=>{
|
||||||
lockoutWindow=null;
|
lockoutWindow=null;
|
||||||
@@ -880,6 +881,27 @@ function returnToHome(){
|
|||||||
markActivity();
|
markActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make a freshly opened dialog/lock window take the physical keyboard.
|
||||||
|
// Without this, under a bare window manager (openbox) the new window can
|
||||||
|
// show up but keyboard focus stays on the page behind it, so a PIN or
|
||||||
|
// password could only be entered by touch / the on-screen keyboard.
|
||||||
|
function grabKeyboardFocus(win){
|
||||||
|
const take=()=>{
|
||||||
|
if(!win||win.isDestroyed())return;
|
||||||
|
try{
|
||||||
|
win.show();
|
||||||
|
win.focus();
|
||||||
|
win.webContents.focus();
|
||||||
|
}catch(e){
|
||||||
|
console.log('[FOCUS] Could not focus window:',e.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
win.once('ready-to-show',take);
|
||||||
|
win.webContents.once('did-finish-load',take);
|
||||||
|
// Window managers can hand focus elsewhere just after mapping the window.
|
||||||
|
setTimeout(take,300);
|
||||||
|
}
|
||||||
|
|
||||||
function showInactivityPrompt(){
|
function showInactivityPrompt(){
|
||||||
if(promptWindow&&!promptWindow.isDestroyed())return;
|
if(promptWindow&&!promptWindow.isDestroyed())return;
|
||||||
|
|
||||||
@@ -894,6 +916,7 @@ function showInactivityPrompt(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
promptWindow.loadFile(path.join(__dirname,'inactivity-prompt-extended.html'));
|
promptWindow.loadFile(path.join(__dirname,'inactivity-prompt-extended.html'));
|
||||||
|
grabKeyboardFocus(promptWindow);
|
||||||
|
|
||||||
promptWindow.on('closed',()=>{
|
promptWindow.on('closed',()=>{
|
||||||
promptWindow=null;
|
promptWindow=null;
|
||||||
@@ -961,6 +984,7 @@ function showPauseDialog(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
pauseWindow.loadFile(path.join(__dirname,'pause-dialog.html'));
|
pauseWindow.loadFile(path.join(__dirname,'pause-dialog.html'));
|
||||||
|
grabKeyboardFocus(pauseWindow);
|
||||||
|
|
||||||
pauseWindow.on('closed',()=>{
|
pauseWindow.on('closed',()=>{
|
||||||
if(pauseWindowTimer){clearTimeout(pauseWindowTimer);pauseWindowTimer=null;}
|
if(pauseWindowTimer){clearTimeout(pauseWindowTimer);pauseWindowTimer=null;}
|
||||||
@@ -1161,6 +1185,7 @@ function showPinEntry(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
pinWindow.loadFile(path.join(__dirname,'pin-entry.html'));
|
pinWindow.loadFile(path.join(__dirname,'pin-entry.html'));
|
||||||
|
grabKeyboardFocus(pinWindow);
|
||||||
pinWindow.on('closed',()=>{
|
pinWindow.on('closed',()=>{
|
||||||
if(pinWindowTimer){clearTimeout(pinWindowTimer);pinWindowTimer=null;}
|
if(pinWindowTimer){clearTimeout(pinWindowTimer);pinWindowTimer=null;}
|
||||||
pinWindow=null;
|
pinWindow=null;
|
||||||
@@ -1282,6 +1307,7 @@ function showWifiWindow(){
|
|||||||
});
|
});
|
||||||
wifiWindow.setMenu(null);
|
wifiWindow.setMenu(null);
|
||||||
wifiWindow.loadFile(path.join(__dirname,'wifi.html'));
|
wifiWindow.loadFile(path.join(__dirname,'wifi.html'));
|
||||||
|
grabKeyboardFocus(wifiWindow);
|
||||||
wifiWindow.on('closed',()=>{
|
wifiWindow.on('closed',()=>{
|
||||||
if(wifiIdleTimer){clearTimeout(wifiIdleTimer);wifiIdleTimer=null;}
|
if(wifiIdleTimer){clearTimeout(wifiIdleTimer);wifiIdleTimer=null;}
|
||||||
wifiWindow=null;
|
wifiWindow=null;
|
||||||
|
|||||||
Reference in New Issue
Block a user