Skip to content

Commit

Permalink
fix(hide): fixing hideInstant with global debounce
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlindquist committed Dec 20, 2024
1 parent f805b6c commit eba4d0f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 43 deletions.
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@
"bugs": {
"url": "https://github.com/script-kit/kitapp/issues"
},
"keywords": ["electron", "react", "typescript", "ts"],
"keywords": [
"electron",
"react",
"typescript",
"ts"
],
"homepage": "https://github.com/script-kit/kitapp#readme",
"devDependencies": {
"@biomejs/biome": "^1.9.4",
Expand Down Expand Up @@ -81,7 +86,7 @@
"date-fns": "^4.1.0",
"detect-port": "^2.1.0",
"dompurify": "^3.2.3",
"electron": "34.0.0-beta.12",
"electron": "34.0.0-beta.13",
"electron-builder": "26.0.0-alpha.7",
"electron-mocks": "^1.6.0",
"electron-vite": "^2.3.0",
Expand Down Expand Up @@ -196,8 +201,12 @@
},
"browserslist": [],
"renovate": {
"extends": ["bliss"],
"baseBranches": ["next"]
"extends": [
"bliss"
],
"baseBranches": [
"next"
]
},
"jest": {
"preset": "ts-jest",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/main/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import { showLogWindow } from './window';
import { createLogger } from '../shared/log-utils';
import { osTmpPath } from './tmp';
import { displayError } from './error';
import { hideInstant } from './prompt/hide';

const log = createLogger('messages.ts');

Expand Down Expand Up @@ -838,7 +839,7 @@ export const createMessageMap = (processInfo: ProcessAndPrompt) => {
}
exiting = true;
log.info(`${pid}: 🚪 Before exit`);
prompt?.hideInstant();
hideInstant(prompt?.window);
processes.stampPid(pid);
processes.removeByPid(pid);
}),
Expand Down
37 changes: 5 additions & 32 deletions src/main/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { Choice, PromptBounds, PromptData, Script, Scriptlet } from '@johnl

import { snapshot } from 'valtio';
import { subscribeKey } from 'valtio/utils';
import shims from './shims';

import { readFile } from 'node:fs/promises';
import os from 'node:os';
Expand Down Expand Up @@ -65,6 +64,7 @@ import { getVersion } from './version';
import { makeKeyWindow, makePanel, makeWindow, prepForClose, setAppearance } from './window/utils';

import { createLogger } from '../shared/log-utils';
import { hideInstant } from './prompt/hide';

const log = createLogger('prompt.ts');

Expand Down Expand Up @@ -2077,7 +2077,7 @@ export class KitPrompt {

log.info('🙈 Hiding prompt window');

this.hideInstant();
hideInstant(this.window);
};

isVisible = () => {
Expand Down Expand Up @@ -2375,7 +2375,7 @@ export class KitPrompt {
log.info(`${this.pid} ${this.window.id} 👋 Close prompt`);
try {
if (kitState.isMac) {
this.hideInstant();
hideInstant(this.window);
}

this.sendToPrompt = () => {};
Expand Down Expand Up @@ -2571,33 +2571,6 @@ export class KitPrompt {
},
);

hideInstant = (type: 'close' | 'hide' = 'hide') => {
if (!this.window.isVisible()) {
return;
}
if (kitState.isWindows) {
// REMOVE-NODE-WINDOW-MANAGER
shims['@johnlindquist/node-window-manager'].windowManager.hideInstantly(this.window?.getNativeWindowHandle());
if (this.window.isFocused()) {
this.window?.emit('blur');
this.window?.emit('hide');
}

// END-REMOVE-NODE-WINDOW-MANAGER
}

if (kitState.isMac) {
log.info(`${this.pid}: 📌 Hiding instant`);
shims['@johnlindquist/mac-panel-window'].hideInstant(this.window);
}

if (kitState.isLinux) {
this.window?.hide();
}

kitState.shortcutsPaused = false;
};

// Extracted and combined escape key handling into handleEscapePress
private escapePressCount = 0;
private lastEscapePressTime = 0;
Expand Down Expand Up @@ -2630,7 +2603,7 @@ export class KitPrompt {
};

private hideAndRemoveProcess = () => {
this.hideInstant();
hideInstant(this.window);
processes.removeByPid(this.pid);
};

Expand Down Expand Up @@ -2678,5 +2651,5 @@ export const makeSplashWindow = (window?: BrowserWindow) => {
return;
}

shims['@johnlindquist/mac-panel-window'].prepForClose(window);
prepForClose(window);
};
28 changes: 28 additions & 0 deletions src/main/prompt/hide.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { BrowserWindow } from 'electron';
import { kitState } from '../state';
import shims from '../shims';

export const hideInstant = debounce(
(window: BrowserWindow) => {
if (!window || window.isDestroyed() || !window.isVisible()) {
return;
}

if (kitState.isWindows) {
// Windows-specific hide logic
shims['@johnlindquist/node-window-manager'].windowManager.hideInstantly(window.getNativeWindowHandle());
if (window.isFocused()) {
window.emit('blur');
window.emit('hide');
}
} else if (kitState.isMac) {
// macOS-specific hide logic
shims['@johnlindquist/mac-panel-window'].hideInstant(window);
} else if (kitState.isLinux) {
// Linux logic
window.hide();
}
},
100,
{ leading: true, trailing: false },
);
2 changes: 1 addition & 1 deletion src/main/window/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type{ BrowserWindow } from 'electron';
import type { BrowserWindow } from 'electron';
import { kitState } from '../state';
import shims from '../shims';
import { prompts } from '../prompts';
Expand Down

0 comments on commit eba4d0f

Please sign in to comment.