Skip to content

Commit

Permalink
fix(focusable): disable focusable on prompt creation
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlindquist committed May 19, 2024
1 parent c259b6f commit bfc61de
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"super-silly": "cross-env ELECTRON_ENABLE_STACK_DUMPING=true ELECTRON_ENABLE_LOGGING=true LOG_LEVEL=silly yarn start",
"start": "cross-env NODE_ENV=development yarn start-$(node -e \"console.log(process.platform === 'darwin' ? 'mac' : process.platform === 'win32' ? 'windows' : 'linux')\")",
"start-mac": "./vite-dev.sh",
"start-windows": "eletron-vite dev",
"start-linux": "electron-vite dev",
"start-windows": "eletron-vite preview",
"start-linux": "electron-vite preview",
"sponsor": "KIT_SPONSOR=development yarn start",
"tiktok": "KIT_SPONSOR=development KIT_TIKTOK=development yarn start",
"splash": "KIT_SPLASH=true yarn start",
Expand Down
32 changes: 32 additions & 0 deletions src/main/prompt.options.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import log from 'electron-log';
import { fileURLToPath } from 'url';
import { getAssetPath } from '../shared/assets';
import { getCurrentScreen } from './screen';
Expand Down Expand Up @@ -35,6 +36,11 @@ export const getPromptOptions = () => {
transparent = true;
}

let focusable = false;
if (kitState?.kenvEnv?.KIT_FORCE_FOCUSABLE === 'true') {
focusable = true;
}

let x = Math.round(screenWidth / 2 - width / 2 + workX);
if (kitState.isWindows) {
x = -10000;
Expand Down Expand Up @@ -62,7 +68,31 @@ export const getPromptOptions = () => {
show = true;
}

let backgroundColor = '#00000000';
if (kitState?.kenvEnv?.KIT_BACKGROUND_COLOR) {
backgroundColor = kitState.kenvEnv.KIT_BACKGROUND_COLOR;
}

let backgroundMaterial = 'mica';
if (kitState?.kenvEnv?.KIT_BACKGROUND_MATERIAL) {
backgroundMaterial = kitState.kenvEnv.KIT_BACKGROUND_MATERIAL;
}

// Log all of the conditional options:
log.info('Prompt Options:', {
backgroundThrottling,
hasShadow,
frame,
transparent,
x,
y,
show,
backgroundColor,
backgroundMaterial,
});

const options = {
focusable,
useContentSize: true,
frame,
hasShadow,
Expand Down Expand Up @@ -90,6 +120,8 @@ export const getPromptOptions = () => {
transparent,
x,
y,
backgroundColor,
backgroundMaterial,
} as BrowserWindowConstructorOptions;

if (kitState.isMac) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,14 +641,18 @@ export class KitPrompt {
const options = getPromptOptions();
this.window = new BrowserWindow(options);

let timeout = 2000;
if (kitState?.kenvEnv?.KIT_PROMPT_INITIAL_HIDE_TIMEOUT) {
timeout = parseInt(kitState?.kenvEnv?.KIT_PROMPT_INITIAL_HIDE_TIMEOUT);
}
if (kitState.isWindows) {
setInterval(() => {
this.window?.hide();
log.info(
'Hiding prompt window. Current position',
this.window?.getPosition(),
);
}, 2000);
}, timeout);
}

this.sendToPrompt = (channel: Channel | AppChannel, data) => {
Expand Down Expand Up @@ -2146,6 +2150,7 @@ export class KitPrompt {
!this.window.isDestroyed() &&
!this.window?.isFocused()
) {
this?.window?.setFocusable(true);
try {
if (kitState.isMac) {
// REMOVE-MAC
Expand Down
15 changes: 15 additions & 0 deletions src/main/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ const buildRunningScriptsSubmenu = async (): Promise<
const runningScripts: MenuItemConstructorOptions[] = [];

if (processes.find((p) => p?.scriptPath)) {
// Terminate all running scripts

runningScripts.push({
type: 'separator',
});

runningScripts.push({
label: 'Terminate All Running Scripts',
click: () => {
for (const { pid } of processes) {
processes.removeByPid(pid);
}
},
});

runningScripts.push({
type: 'separator',
});
Expand Down

0 comments on commit bfc61de

Please sign in to comment.