Skip to content

Commit

Permalink
fix(install): rm kitPath, windows kenvPath, choice, clipboard fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlindquist committed Apr 27, 2024
1 parent b1ae2ea commit 2eb4938
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 37 deletions.
51 changes: 28 additions & 23 deletions src/main/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,29 +379,34 @@ export const downloadKenv = async () => {

export const cleanKit = async () => {
log.info(`🧹 Cleaning ${kitPath()}`);
const pathToClean = kitPath();

const keep = (file: string) =>
file === 'db' || file === 'node_modules' || file === 'assets';

// eslint-disable-next-line no-restricted-syntax
for await (const file of await readdir(pathToClean)) {
if (keep(file)) {
log.info(`👍 Keeping ${file}`);
// eslint-disable-next-line no-continue
continue;
}

const filePath = path.resolve(pathToClean, file);
const stat = await lstat(filePath);
if (stat.isDirectory()) {
await rm(filePath, { recursive: true, force: true });
log.info(`🧹 Cleaning dir ${filePath}`);
} else {
await rm(filePath);
log.info(`🧹 Cleaning file ${filePath}`);
}
}
// Remove the entire kit directory
await rm(kitPath(), {
recursive: true,
force: true,
});
// const pathToClean = kitPath();

// const keep = (file: string) =>
// file === 'db' || file === 'node_modules' || file === 'assets';

// // eslint-disable-next-line no-restricted-syntax
// for await (const file of await readdir(pathToClean)) {
// if (keep(file)) {
// log.info(`👍 Keeping ${file}`);
// // eslint-disable-next-line no-continue
// continue;
// }

// const filePath = path.resolve(pathToClean, file);
// const stat = await lstat(filePath);
// if (stat.isDirectory()) {
// await rm(filePath, { recursive: true, force: true });
// log.info(`🧹 Cleaning dir ${filePath}`);
// } else {
// await rm(filePath);
// log.info(`🧹 Cleaning file ${filePath}`);
// }
// }
};

export const extractKitTar = async (file: string) => {
Expand Down
6 changes: 5 additions & 1 deletion src/main/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ import { Choice, ProcessInfo, Script } from '@johnlindquist/kit/types/core';

import { ChannelMap, SendData } from '@johnlindquist/kit/types/kitapp';

import { kitPath, getMainScriptPath } from '@johnlindquist/kit/core/utils';
import {
kitPath,
kenvPath,
getMainScriptPath,
} from '@johnlindquist/kit/core/utils';

// const { pathExistsSync, readJson } = fsExtra;
import { getTimestamps } from '@johnlindquist/kit/core/db';
Expand Down
28 changes: 18 additions & 10 deletions src/main/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ export class KitPrompt {
},
);

this.window.once('ready-to-show', () => {
this.window.once('ready-to-show', async () => {
log.info(`${this.pid}: 👍 Ready to show`);
updateTheme();

Expand All @@ -758,16 +758,25 @@ export class KitPrompt {
};

const { topMost, leftMost } = getTopMostAndLeftMost();
const kitShowInactiveTimeout = kitState.kenvEnv
?.KIT_WINDOWS_PRERENDER_SHOW_INACTIVE_TIMEOUT
? parseInt(
kitState.kenvEnv?.KIT_WINDOWS_PRERENDER_SHOW_INACTIVE_TIMEOUT,
)
: 100;
const kitWindowsPrerenderTimeout = kitState.kenvEnv
?.KIT_WINDOWS_PRERENDER_TIMEOUT
? parseInt(kitState.kenvEnv?.KIT_WINDOWS_PRERENDER_TIMEOUT)
: 300;
this.window.setPosition(leftMost - 1000, topMost - 1000);
await new Promise((resolve) =>
setTimeout(resolve, kitShowInactiveTimeout),
);
this.window.showInactive();
setTimeout(
() => {
this.window.hide();
},
kitState.kenvEnv?.KIT_WINDOWS_PRERENDER_TIMEOUT
? parseInt(kitState.kenvEnv?.KIT_WINDOWS_PRERENDER_TIMEOUT)
: 500,
await new Promise((resolve) =>
setTimeout(resolve, kitWindowsPrerenderTimeout),
);
this.window.hide();

// Show window inactive super far offscreen just to force a paint, then im
} catch (error) {
Expand Down Expand Up @@ -2178,9 +2187,8 @@ export class KitPrompt {
makeKeyWindow(this.window);
// END-REMOVE-MAC
} else {
this.window?.show();
this.window?.showInactive();
this.window?.focus();
this.window?.webContents.focus();
}
} catch (error) {
log.error(error);
Expand Down
6 changes: 4 additions & 2 deletions src/main/tick.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable import/prefer-default-export */
import clipboardEventListener from '@johnlindquist/clipboard';
import { Clipboard } from '@johnlindquist/clipboard';
import { Observable, Subscription } from 'rxjs';
import { debounceTime, filter, share, switchMap } from 'rxjs/operators';
import log from 'electron-log';
Expand Down Expand Up @@ -197,6 +197,7 @@ const isTransient = () => {
});
};

let clipboardEventListener: Clipboard | null = null;
export const startKeyboardMonitor = async () => {
if (kitState.kenvEnv?.KIT_KEYBOARD === 'false') {
log.info(`🔇 Keyboard monitor disabled`);
Expand Down Expand Up @@ -268,6 +269,7 @@ export const startClipboardMonitor = async () => {
try {
log.info(`Attempting to start clipboard...`);
if (!kitState.isMac) {
clipboardEventListener = new Clipboard();
clipboardEventListener.on('text', (text) => {
try {
log.info(`Clipboard text changed...`);
Expand Down Expand Up @@ -343,7 +345,7 @@ export const startClipboardMonitor = async () => {

return () => {
log.info(`🛑 Attempting to stop clipboard watcher`);
clipboardEventListener.close();
clipboardEventListener?.close();
log.info(`🛑 Successfully stopped clipboard watcher`);
};
}).pipe(
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/src/components/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ function ChoiceButton({
if (flaggedValue) {
setFlagValue('');
} else {
setFlagValue(choice?.value);
// log.info(`Setting flag value:`, choice);
// TODO: On mac, a script has a ".value". On windows, it doesn't. WHY?
setFlagValue(choice?.value ? choice?.value : choice);
}
},
[choice, setFlagValue, flaggedValue],
Expand Down

0 comments on commit 2eb4938

Please sign in to comment.