Skip to content
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

Auto Builds whenever the user changes something and then Dep Manager loses visibility or focus #709

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions vscode-wpilib/media/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
document.getElementById('refresh-action')?.addEventListener('click', () => {
vscode.postMessage({ type: 'refresh' })
});

// Listen for focus events
window.addEventListener('blur', () => {
vscode.postMessage({ type: 'blur' });
});
}

function addDropdownListeners() {
Expand Down
45 changes: 42 additions & 3 deletions vscode-wpilib/src/dependencyView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class DependencyViewProvider implements vscode.WebviewViewProvider {
private externalApi: IExternalAPI;
private ghURL = `https://raw.githubusercontent.com/wpilibsuite/vendor-json-repo/master/`;
private wp: vscode.WorkspaceFolder | undefined;
private changed = 0;

private _view?: vscode.WebviewView;

Expand Down Expand Up @@ -80,7 +81,16 @@ export class DependencyViewProvider implements vscode.WebviewViewProvider {
void this.refresh(this.wp);
webviewView.onDidChangeVisibility(() => {
if (this.wp) {
void this.refresh(this.wp);
// If the webview becomes visible refresh it, invisible then check for changes
if (webviewView.visible) {
void this.refresh(this.wp);
} else {
if (this.changed > this.vendorLibraries.getLastBuild()) {
//this.vendorLibraries.offerBuild(this.wp, true);
this.externalApi.getBuildTestAPI().buildCode(this.wp, undefined);
this.changed = 0;
}
}
}
});

Expand Down Expand Up @@ -118,6 +128,17 @@ export class DependencyViewProvider implements vscode.WebviewViewProvider {
}
break;
}
case 'blur':
{
if (this.wp) {
if (this.changed > this.vendorLibraries.getLastBuild()) {
//this.vendorLibraries.offerBuild(this.wp, true);
this.externalApi.getBuildTestAPI().buildCode(this.wp, undefined);
this.changed = 0;
}
}
break;
}
default:
{
break;
Expand Down Expand Up @@ -175,9 +196,13 @@ export class DependencyViewProvider implements vscode.WebviewViewProvider {
}

private async uninstall(index: string) {
this.sortInstalledDeps();
const uninstall = [this.installedDeps[parseInt(index, 10)]];
if (this.wp) {
await this.vendorLibraries.uninstallVendorLibraries(uninstall, this.wp);
const success = await this.vendorLibraries.uninstallVendorLibraries(uninstall, this.wp);
if (success) {
this.changed = Date.now();
}
await this.refresh(this.wp);
}
}
Expand All @@ -200,7 +225,8 @@ export class DependencyViewProvider implements vscode.WebviewViewProvider {
const success = await this.vendorLibraries.installDependency(dep, this.vendorLibraries.getWpVendorFolder(this.wp), true);

if (success) {
this.vendorLibraries.offerBuild(this.wp);
// this.vendorLibraries.offerBuild(this.wp);
this.changed = Date.now();
}
}
}
Expand Down Expand Up @@ -305,6 +331,19 @@ export class DependencyViewProvider implements vscode.WebviewViewProvider {
});
}

private sortInstalledDeps() {
this.installedDeps.sort((a, b) => {
if (a.name.toLowerCase() > b.name.toLowerCase()) {
return 1;
}
else if (a.name.toLowerCase() === b.name.toLowerCase()) {
return 0;
} else {
return -1;
}
});
}

private sortAvailable() {
this.availableDepsList.sort((a, b) => {
if (a.name.toLowerCase() > b.name.toLowerCase()) {
Expand Down
27 changes: 18 additions & 9 deletions vscode-wpilib/src/vendorlibraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class LibraryQuickPick implements vscode.QuickPickItem {
export class VendorLibraries extends VendorLibrariesBase {
private disposables: vscode.Disposable[] = [];
private externalApi: IExternalAPI;
private lastBuildTime = 1;

constructor(externalApi: IExternalAPI) {
super(externalApi.getUtilitiesAPI());
Expand Down Expand Up @@ -127,9 +128,9 @@ export class VendorLibraries extends VendorLibrariesBase {
}
}

public async uninstallVendorLibraries(toRemove: IJsonDependency[] | undefined, workspace: vscode.WorkspaceFolder) {
public async uninstallVendorLibraries(toRemove: IJsonDependency[] | undefined, workspace: vscode.WorkspaceFolder): Promise<boolean> {
let anySucceeded = false;
if (toRemove !== undefined) {
let anySucceeded = false;
const url = this.getWpVendorFolder(workspace);
const files = await readdirAsync(url);
for (const file of files) {
Expand All @@ -146,9 +147,10 @@ export class VendorLibraries extends VendorLibrariesBase {
}

if (anySucceeded) {
this.offerBuild(workspace);
// this.offerBuild(workspace);
}
}
return anySucceeded;
}

private async offlineUpdates(workspace: vscode.WorkspaceFolder): Promise<void> {
Expand Down Expand Up @@ -185,7 +187,7 @@ export class VendorLibraries extends VendorLibrariesBase {
}
}
if (anySucceeded) {
this.offerBuild(workspace);
this.offerBuild(workspace, true);
}
}
} else {
Expand Down Expand Up @@ -241,7 +243,7 @@ export class VendorLibraries extends VendorLibrariesBase {
}
}
if (anySucceeded) {
this.offerBuild(workspace);
this.offerBuild(workspace, true);
}
}
} else {
Expand Down Expand Up @@ -287,7 +289,7 @@ export class VendorLibraries extends VendorLibrariesBase {
}
}
if (anySucceeded) {
this.offerBuild(workspace);
this.offerBuild(workspace, true);
}
}
} else {
Expand Down Expand Up @@ -316,7 +318,7 @@ export class VendorLibraries extends VendorLibrariesBase {

const success = await this.installDependency(file, this.getWpVendorFolder(workspace), true);
if (success) {
this.offerBuild(workspace);
this.offerBuild(workspace, true);
} else {
vscode.window.showErrorMessage(i18n('message', 'Failed to install {0}', file.name));
}
Expand All @@ -331,15 +333,22 @@ export class VendorLibraries extends VendorLibrariesBase {
return this.getDependencies(this.getWpVendorFolder(workspace));
}

public async offerBuild(workspace: vscode.WorkspaceFolder) {
public async offerBuild(workspace: vscode.WorkspaceFolder, modal = false): Promise<boolean> {
const buildRes = await vscode.window.showInformationMessage(i18n('message',
'It is recommended to run a "Build" after a vendor update. ' +
'Would you like to do this now?'), {
modal: false,
modal: modal
}, {title: i18n('ui', 'Yes')}, {title: i18n('ui', 'No'), isCloseAffordance: true});
if (buildRes?.title === i18n('ui', 'Yes')) {
await this.externalApi.getBuildTestAPI().buildCode(workspace, undefined);
this.lastBuildTime = Date.now();
return true;
}
return false;
}

public getLastBuild(): number {
return this.lastBuildTime;
}
}

Expand Down