Skip to content

Commit f84909c

Browse files
authored
Merge pull request #175 from Open-STEM/FranksDev
fixed installing blocks for a driver
2 parents b840cb5 + 9f682d7 commit f84909c

4 files changed

Lines changed: 14 additions & 23 deletions

File tree

File renamed without changes.
File renamed without changes.

public/drivers/qwiic_alphanumeric/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
"deps": [
66
["qwiic_i2c", "/drivers/qwiic_i2c/package.json"]
77
],
8+
"blocks": [
9+
{"friendly_name": "sf_alphanumeric", "blocks_url": "/drivers/qwiic_alphanumeric/blocks.json", "script_url": "/drivers/qwiic_alphanumeric/blocks.js"}
10+
],
811
"version": "2.0.0"
9-
}
12+
}

src/components/dialogs/driver-installs.tsx

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,19 @@ function XRPDriverInstallDlg({toggleDialog}: XRPDriverInstallsProps) {
6868
* updatePlugins - Update the blockly plugins.json in the /lib/plugins directory
6969
* @param json
7070
*/
71-
const updatePlugins = async (json: string) => {
71+
const updatePlugins = async (plugin: Plugin) => {
7272
// create the plugins.json if it doesn't exist
7373
// or append additional information if it does
7474
const pluginJsonPath = Constants.LIBDIR + 'plugins/plugins.json';
7575
await CommandToXRPMgr.getInstance().getFileContents(pluginJsonPath).then(async (content) => {
7676
const fileData: string = new TextDecoder().decode(new Uint8Array(content));
77-
const jsonData = JSON.parse(json);
7877
const pluginConfig: PluginConfig = { plugins: [] };
7978
if (fileData.includes('Traceback')) {
8079
// create the plugins.json
81-
const plugin: Plugin = {
82-
friendly_name: jsonData.friendly_name,
83-
blocks_url: jsonData.urls[0][1],
84-
script_url: jsonData.urls[1][1]
85-
};
8680
pluginConfig.plugins.push(plugin);
8781
} else {
8882
// append to plugins.json
8983
pluginConfig.plugins = JSON.parse(fileData).plugins;
90-
const plugin: Plugin = {
91-
friendly_name: jsonData.friendly_name,
92-
blocks_url: jsonData.urls[0][1],
93-
script_url: jsonData.urls[1][1]
94-
}
9584
pluginConfig.plugins.push(plugin);
9685
}
9786
await CommandToXRPMgr.getInstance().uploadFile(pluginJsonPath, JSON.stringify(pluginConfig), true);
@@ -145,7 +134,6 @@ function XRPDriverInstallDlg({toggleDialog}: XRPDriverInstallsProps) {
145134
if (packageData.deps) {
146135
for (const dep in packageData.deps) {
147136
const depUrl = packageData.deps[dep];
148-
let isPlugin: boolean = false;
149137
// check if the dependency is already installed
150138
if (drivers.find(d => d.name === depUrl[0] && d.hasInstalled))
151139
continue;
@@ -154,9 +142,6 @@ function XRPDriverInstallDlg({toggleDialog}: XRPDriverInstallsProps) {
154142
// create the dependency folder if it doesn't exist
155143
const depFolder = Constants.LIBDIR + depUrl[0];
156144
await CommandToXRPMgr.getInstance().buildPath(depFolder);
157-
if (depUrl[0].includes('plugins')) {
158-
isPlugin = true;
159-
}
160145
}
161146
}
162147
await fetch(depUrl[1])
@@ -168,18 +153,21 @@ function XRPDriverInstallDlg({toggleDialog}: XRPDriverInstallsProps) {
168153
})
169154
.then(async (json) => {
170155
await installDriver(json);
171-
if (isPlugin) {
172-
updatePlugins(json);
173-
setTimeout(async () => {
174-
await PluginMgr.getInstance().pluginCheck();
175-
}, 2000);
176-
}
177156
})
178157
.catch((error) => {
179158
console.error('Failed to download dependency:', error);
180159
});
181160
}
182161
}
162+
if(packageData.blocks) {
163+
for (const block in packageData.blocks) {
164+
const blockUrl = packageData.blocks[block];
165+
await updatePlugins(blockUrl);
166+
setTimeout(async () => {
167+
await PluginMgr.getInstance().pluginCheck();
168+
}, 2000);
169+
}
170+
}
183171
}
184172

185173
/**

0 commit comments

Comments
 (0)