Skip to content

Commit 9bc38a3

Browse files
Added don't show again button
1 parent 04639c0 commit 9bc38a3

File tree

3 files changed

+61
-31
lines changed

3 files changed

+61
-31
lines changed

packages/cursorless-vscode/resources/installation.js renamed to packages/cursorless-vscode/resources/installationDependencies.js

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
1+
const vscode = acquireVsCodeApi();
2+
13
const root = document.getElementById("root");
24

35
const header = document.createElement("h2");
46
header.textContent = "Cursorless extension is now running!";
57

68
const description = document.createElement("p");
7-
description.innerHTML =
8-
"<a href='https://www.cursorless.org/docs/user/installation'>Click here to learn how to install Cursorless</a>";
9+
const aDocs = link(
10+
"https://www.cursorless.org/docs/user/installation",
11+
"Click here to learn how to install Cursorless",
12+
);
13+
description.innerHTML = `<p>Lets check if all dependencies are installed.</p>${aDocs}`;
914

10-
const div = document.createElement("div");
15+
const messages = document.createElement("div");
1116

12-
root.append(header, description, div);
17+
root.append(header, description, messages);
1318

1419
const keyboardUserMessage =
1520
"<p><i>If you're using Cursorless by keyboard you can ignore this message.</i></p>";
1621

1722
window.addEventListener("message", (event) => {
18-
const { data } = event;
23+
const { dontShow, dependencies } = event.data;
1924
const children = [];
2025

21-
if (!data.talon) {
26+
if (!dependencies.talon) {
2227
const a = link("https://talonvoice.com", "talonvoice.com");
2328
children.push(
2429
getChild(
2530
"Talon not installed",
2631
`Cursorless requires Talon to function by voice.</br>You can download Talon from ${a}.${keyboardUserMessage}`,
2732
),
2833
);
29-
} else if (!data.cursorlessTalon) {
34+
} else if (!dependencies.cursorlessTalon) {
3035
const a = link(
3136
"https://github.com/cursorless-dev/cursorless-talon",
3237
"github.com/cursorless-dev/cursorless-talon",
@@ -39,7 +44,7 @@ window.addEventListener("message", (event) => {
3944
);
4045
}
4146

42-
if (!data.commandServer) {
47+
if (!dependencies.commandServer) {
4348
const a = link(
4449
"https://marketplace.visualstudio.com/items?itemName=pokey.command-server",
4550
"vscode marketplace",
@@ -56,7 +61,9 @@ window.addEventListener("message", (event) => {
5661
children.push(getChild("All dependencies are installed!"));
5762
}
5863

59-
div.replaceChildren(...children);
64+
const dontShowCheckbox = getDontShowCheckbox(dontShow);
65+
66+
messages.replaceChildren(...children, dontShowCheckbox);
6067
});
6168

6269
function link(href, text) {
@@ -75,3 +82,18 @@ function getChild(title, body) {
7582
}
7683
return child;
7784
}
85+
86+
function getDontShowCheckbox(dontShow) {
87+
const checkbox = document.createElement("input");
88+
checkbox.type = "checkbox";
89+
checkbox.checked = dontShow;
90+
checkbox.onchange = () => {
91+
const command = { type: "dontShow", checked: checkbox.checked };
92+
vscode.postMessage(command);
93+
};
94+
const label = document.createElement("label");
95+
label.style.marginTop = "1rem";
96+
const text = document.createTextNode("Don't show again");
97+
label.append(checkbox, text);
98+
return label;
99+
}

packages/cursorless-vscode/src/InstallationDependencies.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ export class InstallationDependencies {
2626
* Shows the installation dependencies webview if there are missing dependencies.
2727
*/
2828
maybeShow() {
29-
if (!this.dontShow() && stateHasMissingDependencies()) {
29+
const state = this.getState();
30+
if (!state.dontShow && hasMissingDependencies(state.dependencies)) {
3031
this.createWebview();
3132
}
3233
}
3334

34-
private dontShow() {
35-
return this.extensionContext.globalState.get<boolean>(STATE_KEY) ?? false;
35+
private getState() {
36+
return {
37+
dontShow: !!this.extensionContext.globalState.get<boolean>(STATE_KEY),
38+
dependencies: getDependencies(),
39+
};
3640
}
3741

3842
private createWebview() {
@@ -42,7 +46,7 @@ export class InstallationDependencies {
4246
}
4347

4448
this.panel = vscode.window.createWebviewPanel(
45-
"cursorless.dependencies",
49+
"cursorless.installationDependencies",
4650
"Cursorless dependencies",
4751
{
4852
viewColumn: vscode.ViewColumn.Active,
@@ -56,44 +60,48 @@ export class InstallationDependencies {
5660
vscode.Uri.joinPath(
5761
this.extensionContext.extensionUri,
5862
"resources",
59-
"installation.js",
63+
"installationDependencies.js",
6064
),
6165
);
6266

6367
this.panel.webview.html = getWebviewContent(this.panel.webview, jsUri);
6468

6569
const updateWebview = () => {
66-
this.panel?.webview.postMessage(getState());
70+
this.panel?.webview.postMessage(this.getState());
6771
};
6872

6973
this.panel.onDidChangeViewState(updateWebview);
7074

75+
this.panel.webview.onDidReceiveMessage((message) => {
76+
if (message.type === "dontShow") {
77+
const checked = message.checked;
78+
this.extensionContext.globalState.update(STATE_KEY, checked);
79+
} else {
80+
console.error(`Unknown message: ${message}`);
81+
}
82+
});
83+
7184
const interval = setInterval(updateWebview, 5000);
7285

7386
this.panel.onDidDispose(() => {
7487
clearInterval(interval);
7588
this.panel = undefined;
7689
});
7790

78-
this.panel.webview.postMessage(getState());
91+
this.panel.webview.postMessage(this.getState());
7992
}
8093
}
8194

82-
function stateHasMissingDependencies() {
83-
return Object.values(getState()).some((value) => !value);
84-
}
85-
86-
function getState() {
95+
function getDependencies(): Record<string, boolean> {
8796
return {
88-
talon: false,
89-
cursorlessTalon: false,
90-
commandServer: false,
97+
talon: talonHomeExists(),
98+
cursorlessTalon: cursorlessTalonExists(),
99+
commandServer: commandServerInstalled(),
91100
};
92-
// return {
93-
// talon: talonHomeExists(),
94-
// cursorlessTalon: cursorlessTalonExists(),
95-
// commandServer: commandServerInstalled(),
96-
// };
101+
}
102+
103+
function hasMissingDependencies(dependencies: Record<string, boolean>) {
104+
return Object.values(dependencies).some((value) => !value);
97105
}
98106

99107
function talonHomeExists() {

packages/cursorless-vscode/src/scripts/populateDist/assets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export const assets: Asset[] = [
4343
destination: "resources/font_measurements.js",
4444
},
4545
{
46-
source: "resources/installation.js",
47-
destination: "resources/installation.js",
46+
source: "resources/installationDependencies.js",
47+
destination: "resources/installationDependencies.js",
4848
},
4949
{ source: "../../schemas", destination: "schemas" },
5050
{

0 commit comments

Comments
 (0)