mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-31 19:45:15 +02:00
escape to hide, clamp panel to screen bounds, disable maximize
This commit is contained in:
parent
2ae83e8b28
commit
743172785d
1 changed files with 16 additions and 1 deletions
|
|
@ -13,6 +13,15 @@ function hideQuickAsk(): void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clampToScreen(x: number, y: number, w: number, h: number): { x: number; y: number } {
|
||||||
|
const display = screen.getDisplayNearestPoint({ x, y });
|
||||||
|
const { x: dx, y: dy, width: dw, height: dh } = display.workArea;
|
||||||
|
return {
|
||||||
|
x: Math.max(dx, Math.min(x, dx + dw - w)),
|
||||||
|
y: Math.max(dy, Math.min(y, dy + dh - h)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function createQuickAskWindow(x: number, y: number): BrowserWindow {
|
function createQuickAskWindow(x: number, y: number): BrowserWindow {
|
||||||
if (quickAskWindow && !quickAskWindow.isDestroyed()) {
|
if (quickAskWindow && !quickAskWindow.isDestroyed()) {
|
||||||
quickAskWindow.setPosition(x, y);
|
quickAskWindow.setPosition(x, y);
|
||||||
|
|
@ -29,6 +38,7 @@ function createQuickAskWindow(x: number, y: number): BrowserWindow {
|
||||||
type: 'panel',
|
type: 'panel',
|
||||||
resizable: true,
|
resizable: true,
|
||||||
fullscreenable: false,
|
fullscreenable: false,
|
||||||
|
maximizable: false,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: path.join(__dirname, 'preload.js'),
|
preload: path.join(__dirname, 'preload.js'),
|
||||||
contextIsolation: true,
|
contextIsolation: true,
|
||||||
|
|
@ -45,6 +55,10 @@ function createQuickAskWindow(x: number, y: number): BrowserWindow {
|
||||||
quickAskWindow?.show();
|
quickAskWindow?.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
quickAskWindow.webContents.on('before-input-event', (_event, input) => {
|
||||||
|
if (input.key === 'Escape') hideQuickAsk();
|
||||||
|
});
|
||||||
|
|
||||||
quickAskWindow.webContents.setWindowOpenHandler(({ url }) => {
|
quickAskWindow.webContents.setWindowOpenHandler(({ url }) => {
|
||||||
if (url.startsWith('http://localhost')) {
|
if (url.startsWith('http://localhost')) {
|
||||||
return { action: 'allow' };
|
return { action: 'allow' };
|
||||||
|
|
@ -72,7 +86,8 @@ export function registerQuickAsk(): void {
|
||||||
|
|
||||||
pendingText = text;
|
pendingText = text;
|
||||||
const cursor = screen.getCursorScreenPoint();
|
const cursor = screen.getCursorScreenPoint();
|
||||||
createQuickAskWindow(cursor.x, cursor.y);
|
const pos = clampToScreen(cursor.x, cursor.y, 450, 550);
|
||||||
|
createQuickAskWindow(pos.x, pos.y);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue