mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-27 01:36:30 +02:00
open quick-ask as mini window at cursor position
This commit is contained in:
parent
8750462637
commit
d033e1cb48
1 changed files with 45 additions and 8 deletions
|
|
@ -1,20 +1,57 @@
|
|||
import { clipboard, globalShortcut } from 'electron';
|
||||
import { BrowserWindow, clipboard, globalShortcut, screen } from 'electron';
|
||||
import path from 'path';
|
||||
import { IPC_CHANNELS } from '../ipc/channels';
|
||||
import { getMainWindow } from './window';
|
||||
import { getServerPort } from './server';
|
||||
|
||||
const SHORTCUT = 'CommandOrControl+Option+S';
|
||||
let quickAskWindow: BrowserWindow | null = null;
|
||||
|
||||
function createQuickAskWindow(x: number, y: number): BrowserWindow {
|
||||
if (quickAskWindow && !quickAskWindow.isDestroyed()) {
|
||||
quickAskWindow.setPosition(x, y);
|
||||
quickAskWindow.show();
|
||||
quickAskWindow.focus();
|
||||
return quickAskWindow;
|
||||
}
|
||||
|
||||
quickAskWindow = new BrowserWindow({
|
||||
width: 450,
|
||||
height: 550,
|
||||
x,
|
||||
y,
|
||||
alwaysOnTop: true,
|
||||
resizable: true,
|
||||
frame: false,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'preload.js'),
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
sandbox: true,
|
||||
},
|
||||
show: false,
|
||||
skipTaskbar: true,
|
||||
});
|
||||
|
||||
quickAskWindow.loadURL(`http://localhost:${getServerPort()}/dashboard`);
|
||||
|
||||
quickAskWindow.once('ready-to-show', () => {
|
||||
quickAskWindow?.show();
|
||||
});
|
||||
|
||||
quickAskWindow.on('closed', () => {
|
||||
quickAskWindow = null;
|
||||
});
|
||||
|
||||
return quickAskWindow;
|
||||
}
|
||||
|
||||
export function registerQuickAsk(): void {
|
||||
const ok = globalShortcut.register(SHORTCUT, () => {
|
||||
const win = getMainWindow();
|
||||
if (!win) return;
|
||||
|
||||
const text = clipboard.readText().trim();
|
||||
if (!text) return;
|
||||
|
||||
if (win.isMinimized()) win.restore();
|
||||
win.show();
|
||||
win.focus();
|
||||
const cursor = screen.getCursorScreenPoint();
|
||||
const win = createQuickAskWindow(cursor.x, cursor.y);
|
||||
|
||||
win.webContents.send(IPC_CHANNELS.QUICK_ASK_TEXT, text);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue