Skip to content

Commit 5aec3cb

Browse files
committed
add the plugin installer code in 'np.installer' NotePlan uses as core plugin internally
1 parent 51bc1ae commit 5aec3cb

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

‎np.installer/plugin.json‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"noteplan.minAppVersion": "3.3",
3+
"plugin.id": "np.installer",
4+
"plugin.name": "⬇️ Plugin Installer",
5+
"plugin.description": "Install plugins right from the command bar. This is a core plugin and can't be deleted.",
6+
"plugin.icon": "",
7+
"plugin.author": "",
8+
"plugin.repoUrl": "CorePlugins",
9+
"plugin.version": "0.1",
10+
"plugin.dependencies": [],
11+
"plugin.script": "script.js",
12+
"plugin.isRemote": "false",
13+
"plugin.hidden": true,
14+
"plugin.commands": [
15+
{
16+
"name": "install plugin",
17+
"description": "Load a list of plugins and lets you install one",
18+
"jsFunction": "installPlugins"
19+
},
20+
{
21+
"name": "development install",
22+
"description": "Load a list of plugins and lets you install one, including hidden ones",
23+
"jsFunction": "installPluginsIncludingHidden"
24+
},
25+
],
26+
"plugin.preferences": []
27+
}

‎np.installer/script.js‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
async function installPluginsIncludingHidden() {
3+
_installPlugins(true)
4+
}
5+
6+
async function installPlugins() {
7+
_installPlugins(false)
8+
}
9+
10+
async function _installPlugins(showHidden) {
11+
let plugins = await DataStore.listPlugins(true, showHidden)
12+
13+
let list = plugins.map(p => pluginToDescription(p))
14+
list.push("❌ Cancel")
15+
16+
let selection = await CommandBar.showOptions(list, "Select a plugin to install/update:")
17+
18+
if(selection.index < plugins.length) {
19+
let plugin = plugins[selection.index]
20+
try {
21+
let result = await DataStore.installPlugin(plugin, true)
22+
23+
let list = ["✅ OK", "📖 Open Readme", "", "Commands:"]
24+
plugin.commands.forEach((item, i) => {
25+
list.push("/" + item.name + " - " + item.desc)
26+
});
27+
28+
let selection = await CommandBar.showOptions(list, "Successfully installed '" + plugin.name + "'")
29+
if(selection.index == 1) {
30+
CommandBar.openURL(plugin.repoUrl)
31+
}
32+
} catch(err) {
33+
await CommandBar.showOptions(["✅ OK"], "Error: " + err)
34+
}
35+
}
36+
}
37+
38+
function pluginToDescription(p) {
39+
let installed = p.isOnline ? "" : ", installed: 🆗"
40+
41+
if(p.availableUpdate) {
42+
installed += ", update: v" + p.availableUpdate.version + " 🆕"
43+
}
44+
45+
return p.name + " (v" + p.version + installed + ")"
46+
}

0 commit comments

Comments
 (0)