Skip to content

Commit 6ea1ce2

Browse files
fix: make device states clearer
#259 (reply in thread)
1 parent 35b30de commit 6ea1ce2

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed

src/Device.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Device {
5656
const { subscribe, set } = writable(this);
5757
this.busy = writable(false, { lazy: true });
5858

59-
/** @type {Writable<import('./utils/blockingProxy').BlockingProxyQueueItem>} */
59+
/** @type {Writable<string|import('./utils/blockingProxy').BlockingProxyQueueItem>} */
6060
this.action = writable(null, { lazy: true });
6161
this.online = writable(false, { lazy: true });
6262
this.connected = writable(false, { lazy: true });
@@ -192,10 +192,12 @@ class Device {
192192
if (!this.connected.get()) throw new DeviceOfflineError();
193193

194194
this.log.info("safe booting...");
195+
this.action.set("safeboot");
195196
this.busy.set(true);
196197
this.busy.subscribe((isBusy, unsub) => {
197198
if (!isBusy) {
198199
unsub();
200+
this.action.set(null);
199201
this.log.info("safe booting complete!", isBusy);
200202
resolve();
201203
}

src/providers/DevicesProvider.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,9 @@ class DeviceTreeItem extends vscode.TreeItem {
4646
this.device = device;
4747
const state = device.connected.get() ? (device.busy.get() ? "busy" : "idle") : "offline";
4848
this.contextValue = `${state}#none#device`;
49-
const filename = device.connected.get() ? "lightning.svg" : "lightning-muted.svg";
5049

51-
this.tooltip = device.pymakr.vscodeHelpers.deviceSummary(device)
52-
53-
this.iconPath = device.busy.get()
54-
? new vscode.ThemeIcon("sync~spin")
55-
: {
56-
dark: path.join(__dirname + "..", "..", "..", "media", "dark", filename),
57-
light: path.join(__dirname + "..", "..", "..", "media", "light", filename),
58-
};
59-
device.busy.subscribe((isBusy) =>
60-
setTimeout(() => {
61-
if (device.busy.get() === isBusy) tree.refresh();
62-
}, 100)
63-
);
50+
this.tooltip = device.pymakr.vscodeHelpers.deviceSummary(device);
51+
this.iconPath = device.pymakr.vscodeHelpers.deviceStateIcon(device);
6452
}
6553
}
6654

src/providers/ProjectsProvider.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,9 @@ class ProjectDeviceTreeItem extends vscode.TreeItem {
8686
this.device = device;
8787
const state = device.connected.get() ? (device.busy.get() ? "busy" : "idle") : "offline";
8888
this.contextValue = `${state}#project#device`;
89-
const filename = device.connected.get() ? "lightning.svg" : "lightning-muted.svg";
89+
9090
this.tooltip = device.pymakr.vscodeHelpers.deviceSummary(device);
91-
this.iconPath = device.busy.get()
92-
? new vscode.ThemeIcon("sync~spin")
93-
: {
94-
dark: path.join(__dirname + "..", "..", "..", "media", "dark", filename),
95-
light: path.join(__dirname + "..", "..", "..", "media", "light", filename),
96-
};
97-
device.busy.subscribe((isBusy) =>
98-
setTimeout(() => {
99-
if (device.busy.get() === isBusy) tree.refresh();
100-
}, 100)
101-
);
91+
this.iconPath = device.pymakr.vscodeHelpers.deviceStateIcon(device);
10292
}
10393
}
10494

src/utils/vscodeHelpers.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const path = require("path");
12
const vscode = require("vscode");
23
const { Project } = require("../Project.js");
34
const { ProjectDeviceTreeItem, ProjectTreeItem } = require("../providers/ProjectsProvider.js");
@@ -134,6 +135,26 @@ const createVSCodeHelpers = (pymakr) => {
134135
else if (typeof device.info === "string") mdString.appendMarkdown(device.info);
135136
return mdString;
136137
},
138+
139+
/**
140+
* @param {Device} device
141+
*/
142+
deviceStateIcon: (device) => {
143+
const icons = {
144+
offline: new vscode.ThemeIcon("debug-disconnect", { id: "disabledForeground" }),
145+
disconnected: {
146+
dark: path.join(__dirname + "..", "..", "..", "media", "dark", "lightning-muted.svg"),
147+
light: path.join(__dirname + "..", "..", "..", "media", "light", "lightning-muted.svg"),
148+
},
149+
idle: {
150+
dark: path.join(__dirname + "..", "..", "..", "media", "dark", "lightning.svg"),
151+
light: path.join(__dirname + "..", "..", "..", "media", "light", "lightning.svg"),
152+
},
153+
script: new vscode.ThemeIcon("github-action"), // or pulse
154+
action: new vscode.ThemeIcon("sync~spin"),
155+
};
156+
return icons[device.state.main.get()];
157+
},
137158
};
138159
return helpers;
139160
};

0 commit comments

Comments
 (0)