Skip to content

Commit

Permalink
fix: Prevent multiple webview panel instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinho1011 authored and ytaek committed Oct 5, 2023
1 parent 301cfeb commit 0a6c5b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@ function normalizeFsPath(fsPath: string) {
export async function activate(context: vscode.ExtensionContext) {
const { subscriptions, extensionPath, secrets } = context;
const credentials = new Credentials();
let currentPanel: vscode.WebviewPanel | undefined = undefined;

await credentials.initialize(context);

console.log('Congratulations, your extension "githru" is now active!');

const disposable = vscode.commands.registerCommand(COMMAND_LAUNCH, async () => {
try {
console.debug(currentPanel);
if (currentPanel) {
currentPanel.reveal();
return;
}
const gitPath = (await findGit()).path;

const currentWorkspaceUri = vscode.workspace.workspaceFolders?.[0].uri;
Expand Down Expand Up @@ -81,6 +88,7 @@ export async function activate(context: vscode.ExtensionContext) {
fetchBranches,
fetchCurrentBranch,
});
currentPanel = webLoader.getPanel();

subscriptions.push(webLoader);
vscode.window.showInformationMessage("Hello Githru");
Expand Down
4 changes: 4 additions & 0 deletions packages/vscode/src/webview-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export default class WebviewLoader implements vscode.Disposable {
this._panel?.dispose();
}

getPanel() {
return this._panel;
}

private async respondToMessage(message: { command: string; payload: unknown }) {
this._panel?.webview.postMessage({
command: message.command,
Expand Down

0 comments on commit 0a6c5b7

Please sign in to comment.