Skip to content

fix: recreating keyboardShortcuts interface on file changes. #1465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions packages/wxt/src/core/create-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ async function createServerInternal(): Promise<WxtDevServer> {
await buildAndOpenBrowser();

// Listen for file changes and reload different parts of the extension accordingly
const reloadOnChange = createFileReloader(server);
const reloadOnChange = () => {
createFileReloader(server);
keyboardShortcuts.start();
keyboardShortcuts.printHelp({
canReopenBrowser:
!wxt.config.runnerConfig.config.disabled && !!runner.canOpen?.(),
});
};
server.watcher.on('all', reloadOnChange);
keyboardShortcuts.start();
keyboardShortcuts.printHelp({
canReopenBrowser:
!wxt.config.runnerConfig.config.disabled && !!runner.canOpen?.(),
});
},

async stop() {
Expand Down
10 changes: 7 additions & 3 deletions packages/wxt/src/core/keyboard-shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export function createKeyboardShortcuts(

return {
start() {
if (rl) return;
if (rl) {
rl.on('line', handleInput);
return;
}

rl = readline.createInterface({
input: process.stdin,
Expand All @@ -37,8 +40,9 @@ export function createKeyboardShortcuts(
},

stop() {
rl?.close();
rl = undefined;
if (rl) {
rl.removeListener('line', handleInput);
}
},

printHelp(flags) {
Expand Down