Skip to content

Commit

Permalink
Integrate new plugin directory, refs #74
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Sep 11, 2021
1 parent 7e9b93d commit f83a929
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
53 changes: 24 additions & 29 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const SQLITE_HEADER = Buffer.from("53514c69746520666f726d6174203300", "hex");

const minPackageVersions = {
datasette: "0.59a2",
"datasette-app-support": "0.7",
"datasette-app-support": "0.8",
"datasette-vega": "0.6.2",
"datasette-cluster-map": "0.17.1",
"datasette-pretty-json": "0.2.1",
Expand Down Expand Up @@ -477,6 +477,25 @@ async function initializeApp() {
datasette.shutdown();
});

ipcMain.on("install-plugin", async (event, pluginName) => {
try {
await datasette.installPlugin(pluginName);
await datasette.startOrRestart();
dialog.showMessageBoxSync({
type: "info",
message: "Plugin installed",
detail: `${pluginName} is now ready to use`,
});
event.reply("plugin-installed", pluginName);
} catch (error) {
dialog.showMessageBoxSync({
type: "error",
message: "Plugin installation error",
detail: error.toString(),
});
}
});

ipcMain.on("import-csv", async (event, database) => {
let selectedFiles = dialog.showOpenDialogSync({
properties: ["openFile"],
Expand Down Expand Up @@ -794,35 +813,11 @@ function buildMenu() {
label: "Plugins",
submenu: [
{
label: "Install Plugin…",
label: "Install Plugins…",
click() {
prompt({
title: "Install Plugin",
label: "Plugin name:",
value: "datasette-vega",
type: "input",
alwaysOnTop: true,
})
.then(async (pluginName) => {
if (pluginName !== null) {
try {
await datasette.installPlugin(pluginName);
await datasette.startOrRestart();
dialog.showMessageBoxSync({
type: "info",
message: "Plugin installed",
detail: `${pluginName} is now ready to use`,
});
} catch (error) {
dialog.showMessageBoxSync({
type: "error",
message: "Plugin installation error",
detail: error.toString(),
});
}
}
})
.catch(console.error);
datasette.openPath(
"/plugin_directory/plugins?_sort_desc=stargazers_count&_facet=installed"
);
},
},
{
Expand Down
11 changes: 11 additions & 0 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ contextBridge.exposeInMainWorld("datasetteApp", {
importCsv: (database) => {
ipcRenderer.send("import-csv", database);
},
installPlugin: (plugin, link) => {
ipcRenderer.send("install-plugin", plugin);
if (link) {
link.style.opacity = 0.5;
link.setAttribute("href", "#");
link.innerHTML = `Installing ${plugin}…`;
}
},
onServerLog: (callback) => {
ipcRenderer.on("serverLog", callback);
},
Expand All @@ -15,3 +23,6 @@ contextBridge.exposeInMainWorld("datasetteApp", {
ipcRenderer.on("csv-imported", () => {
location.reload();
});
ipcRenderer.on("plugin-installed", () => {
location.reload();
});

0 comments on commit f83a929

Please sign in to comment.