Skip to content

Commit

Permalink
fix: Only show keyboard shortcut to reopen browser when it's usable
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Dec 8, 2024
1 parent 0fd5c38 commit c249d58
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
7 changes: 5 additions & 2 deletions packages/wxt/src/core/create-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async function createServerInternal(): Promise<WxtDevServer> {

// Register content scripts for the first time after the background starts
// up since they're not listed in the manifest.
// Add listener before opening the browser to guarentee it is present when
// Add listener before opening the browser to guarantee it is present when
// the extension sends back the initialization message.
server.ws.on('wxt:background-initialized', () => {
if (server.currentOutput == null) return;
Expand All @@ -112,7 +112,10 @@ async function createServerInternal(): Promise<WxtDevServer> {
const reloadOnChange = createFileReloader(server);
server.watcher.on('all', reloadOnChange);
keyboardShortcuts.start();
keyboardShortcuts.printHelp();
keyboardShortcuts.printHelp({
canReopenBrowser:
!wxt.config.runnerConfig.config.disabled && !!runner.canOpen?.(),
});
},

async stop() {
Expand Down
6 changes: 3 additions & 3 deletions packages/wxt/src/core/keyboard-shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import pc from 'picocolors';
export interface KeyboardShortcutWatcher {
start(): void;
stop(): void;
printHelp(): void;
printHelp(flags: { canReopenBrowser: boolean }): void;
}

/**
Expand Down Expand Up @@ -49,8 +49,8 @@ export function createKeyboardShortcuts(
isWatching = false;
},

printHelp() {
if (!wxt.config.runnerConfig.config.disabled) {
printHelp(flags) {
if (flags.canReopenBrowser) {
wxt.logger.info(
`${pc.dim('Press')} ${pc.bold('o + enter')} ${pc.dim('to reopen the browser')}`,
);
Expand Down
3 changes: 3 additions & 0 deletions packages/wxt/src/core/runners/web-ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export function createWebExtRunner(): ExtensionRunner {
let runner: WebExtRunInstance | undefined;

return {
canOpen() {
return true;
},

Check warning on line 16 in packages/wxt/src/core/runners/web-ext.ts

View check run for this annotation

Codecov / codecov/patch

packages/wxt/src/core/runners/web-ext.ts#L14-L16

Added lines #L14 - L16 were not covered by tests
async openBrowser() {
const startTime = Date.now();

Expand Down
2 changes: 2 additions & 0 deletions packages/wxt/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,8 @@ export interface FsCache {
export interface ExtensionRunner {
openBrowser(): Promise<void>;
closeBrowser(): Promise<void>;
/** Whether or not this runner actually opens the browser. */
canOpen?(): boolean;
}

export type EslintGlobalsPropValue =
Expand Down

0 comments on commit c249d58

Please sign in to comment.