mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-17 18:35:19 +02:00
destroy panel on dismiss, remove activate to preserve selection
This commit is contained in:
parent
bc16c0362d
commit
2f08d401fa
1 changed files with 9 additions and 14 deletions
|
|
@ -21,10 +21,11 @@ function getFrontmostApp(): string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideQuickAsk(): void {
|
function destroyQuickAsk(): void {
|
||||||
if (quickAskWindow && !quickAskWindow.isDestroyed()) {
|
if (quickAskWindow && !quickAskWindow.isDestroyed()) {
|
||||||
quickAskWindow.hide();
|
quickAskWindow.close();
|
||||||
}
|
}
|
||||||
|
quickAskWindow = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function clampToScreen(x: number, y: number, w: number, h: number): { x: number; y: number } {
|
function clampToScreen(x: number, y: number, w: number, h: number): { x: number; y: number } {
|
||||||
|
|
@ -37,12 +38,7 @@ function clampToScreen(x: number, y: number, w: number, h: number): { x: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createQuickAskWindow(x: number, y: number): BrowserWindow {
|
function createQuickAskWindow(x: number, y: number): BrowserWindow {
|
||||||
if (quickAskWindow && !quickAskWindow.isDestroyed()) {
|
destroyQuickAsk();
|
||||||
quickAskWindow.setPosition(x, y);
|
|
||||||
quickAskWindow.show();
|
|
||||||
quickAskWindow.focus();
|
|
||||||
return quickAskWindow;
|
|
||||||
}
|
|
||||||
|
|
||||||
quickAskWindow = new BrowserWindow({
|
quickAskWindow = new BrowserWindow({
|
||||||
width: 450,
|
width: 450,
|
||||||
|
|
@ -72,7 +68,7 @@ function createQuickAskWindow(x: number, y: number): BrowserWindow {
|
||||||
});
|
});
|
||||||
|
|
||||||
quickAskWindow.webContents.on('before-input-event', (_event, input) => {
|
quickAskWindow.webContents.on('before-input-event', (_event, input) => {
|
||||||
if (input.key === 'Escape') hideQuickAsk();
|
if (input.key === 'Escape') destroyQuickAsk();
|
||||||
});
|
});
|
||||||
|
|
||||||
quickAskWindow.webContents.setWindowOpenHandler(({ url }) => {
|
quickAskWindow.webContents.setWindowOpenHandler(({ url }) => {
|
||||||
|
|
@ -92,8 +88,8 @@ function createQuickAskWindow(x: number, y: number): BrowserWindow {
|
||||||
|
|
||||||
export function registerQuickAsk(): void {
|
export function registerQuickAsk(): void {
|
||||||
const ok = globalShortcut.register(SHORTCUT, () => {
|
const ok = globalShortcut.register(SHORTCUT, () => {
|
||||||
if (quickAskWindow && !quickAskWindow.isDestroyed() && quickAskWindow.isVisible()) {
|
if (quickAskWindow && !quickAskWindow.isDestroyed()) {
|
||||||
hideQuickAsk();
|
destroyQuickAsk();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,11 +121,10 @@ export function registerQuickAsk(): void {
|
||||||
if (!systemPreferences.isTrustedAccessibilityClient(true)) return;
|
if (!systemPreferences.isTrustedAccessibilityClient(true)) return;
|
||||||
|
|
||||||
clipboard.writeText(text);
|
clipboard.writeText(text);
|
||||||
hideQuickAsk();
|
destroyQuickAsk();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
execSync(`osascript -e 'tell application "${sourceApp}" to activate'`);
|
await new Promise((r) => setTimeout(r, 50));
|
||||||
await new Promise((r) => setTimeout(r, 100));
|
|
||||||
execSync('osascript -e \'tell application "System Events" to keystroke "v" using command down\'');
|
execSync('osascript -e \'tell application "System Events" to keystroke "v" using command down\'');
|
||||||
await new Promise((r) => setTimeout(r, 100));
|
await new Promise((r) => setTimeout(r, 100));
|
||||||
clipboard.writeText(savedClipboard);
|
clipboard.writeText(savedClipboard);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue