Skip to content

Commit

Permalink
Wait before loading a page at the first time (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi authored Sep 10, 2023
1 parent 43adf28 commit f5b1e7a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ jobs:
with:
node-version: ${{ matrix.node }}
check-latest: true

- name: Rebuild native modules
run: npm rebuild

- name: Tests on macOS, Windows
env:
Expand Down
4 changes: 2 additions & 2 deletions src/main/webview/webviewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export class WebviewManager implements ExtensionComponent {
this.webviewSidebar.loadPage(await this.createLoginPage());
}

public loadWebviewTab(page: WebviewPage) {
this.webviewTab.resolveWebviewView();
public async loadWebviewTab(page: WebviewPage) {
await this.webviewTab.resolveWebviewView();
this.webviewTab.loadPage(page);
}

Expand Down
8 changes: 7 additions & 1 deletion src/main/webview/webviewTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { LogManager } from '../log/logManager';
import { EventManager } from './event/eventManager';
import { WebView } from './webview';
import { ConnectionManager } from '../connect/connectionManager';
import { RunUtils } from '../utils/runUtils';

/**
* Show a webview panel with details about objects in the project
*/
export class WebviewTab extends WebView {
private static readonly WEBVIEW_DELAY_MILLISECS: number = 2000;
private panel: vscode.WebviewPanel | undefined;

constructor(logManager: LogManager, private connectionManager: ConnectionManager, private context: vscode.ExtensionContext) {
Expand All @@ -20,10 +22,14 @@ export class WebviewTab extends WebView {
* @param data - the data of the page to be update and show in the webpage
* @param context - context of the extension
*/
public resolveWebviewView() {
public async resolveWebviewView() {
if (!this.panel) {
this.panel = this.createWebview();
this.eventManager = this.createEventManager(this.panel);
// Workaround: Delay the initial page load to ensure proper message delivery in the Webview.
// This is necessary because in the Webview, messages are only delivered when the webview is alive.
// This workaround applies specifically to VS-Code remote development environments.
await RunUtils.delay(WebviewTab.WEBVIEW_DELAY_MILLISECS);
} else {
this.panel.reveal();
}
Expand Down

0 comments on commit f5b1e7a

Please sign in to comment.