Build and include builtin plugins with OpenDeck

This commit is contained in:
ninjadev64 committed 2024-12-11 18:23:05 +00:00
1 parent 8115dbb5dd
commit 83321e1622
8 files changed
+78 -13

No files matched your search

+5 -2
View File
@@ -26,7 +26,10 @@ jobs:
env:
DENO_DIR: deno_cache
steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: install Rust stable
uses: dtolnay/rust-toolchain@stable
@@ -63,7 +66,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tauriScript: deno task tauri
tagName: v__VERSION__
tagName: tv__VERSION__
releaseName: "OpenDeck v__VERSION__"
releaseBody: "See the assets to download this version. See the README for installation instructions."
releaseDraft: true
+3
View File
@@ -0,0 +1,3 @@
[submodule "plugins/com.amansprojects.starterpack.sdPlugin"]
path = plugins/com.amansprojects.starterpack.sdPlugin
url = https://github.com/ninjadev64/opendeck-starterpack.git
+21
View File
@@ -1,4 +1,25 @@
use std::fs;
fn main() {
println!("cargo:rerun-if-changed=../plugins");
if let Err(error) = || -> Result<(), std::io::Error> {
for entry in fs::read_dir("../plugins")?.flatten() {
let out_dir = std::path::Path::new("target").join("plugins").join(entry.file_name());
fs::create_dir_all(&out_dir)?;
let status = std::process::Command::new("deno")
.args(["run", "--lock=target/deno.lock", "--allow-all", "build.ts", fs::canonicalize(out_dir)?.to_string_lossy().as_ref()])
.current_dir(entry.path())
.status()?;
if !status.success() {
panic!("Failed to build plugin {}: status code {}", entry.file_name().to_string_lossy(), status.code().unwrap());
}
}
Ok(())
}() {
panic!("Failed to build builtin plugins: {error}");
}
built::write_built_file().expect("failed to acquire build-time information");
tauri_build::build();
}
+30
View File
@@ -275,6 +275,36 @@ pub fn initialise_plugins() {
let _ = fs::create_dir_all(&plugin_dir);
let _ = fs::create_dir_all(log_dir().join("plugins"));
if let Ok(Ok(entries)) = APP_HANDLE.get().unwrap().path().resolve("plugins", tauri::path::BaseDirectory::Resource).map(fs::read_dir) {
for entry in entries.flatten() {
if let Err(error) = (|| -> Result<(), anyhow::Error> {
let builtin_version = semver::Version::parse(&serde_json::from_slice::<manifest::PluginManifest>(&fs::read(entry.path().join("manifest.json"))?)?.version)?;
let existing_path = plugin_dir.join(entry.file_name());
if (|| -> Result<(), anyhow::Error> {
let existing_version = semver::Version::parse(&serde_json::from_slice::<manifest::PluginManifest>(&fs::read(existing_path.join("manifest.json"))?)?.version)?;
if existing_version < builtin_version {
Err(anyhow::anyhow!("builtin version is newer than existing version"))
} else {
Ok(())
}
})()
.is_err()
{
if existing_path.exists() {
fs::rename(&existing_path, existing_path.with_extension("old"))?;
}
if crate::shared::copy_dir(entry.path(), &existing_path).is_err() && existing_path.with_extension("old").exists() {
fs::rename(existing_path.with_extension("old"), &existing_path)?;
}
let _ = fs::remove_dir_all(existing_path.with_extension("old"));
}
Ok(())
})() {
error!("Failed to upgrade builtin plugin {}: {}", entry.file_name().to_string_lossy(), error);
}
}
}
let entries = match fs::read_dir(&plugin_dir) {
Ok(p) => p,
Err(error) => {
+13
View File
@@ -8,6 +8,19 @@ use once_cell::sync::Lazy;
use tauri::Manager;
use tokio::sync::RwLock;
pub fn copy_dir(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<(), std::io::Error> {
use std::fs;
fs::create_dir_all(&dst)?;
for entry in fs::read_dir(src)?.flatten() {
if entry.file_type()?.is_dir() {
copy_dir(entry.path(), dst.as_ref().join(entry.file_name()))?;
} else {
fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?;
}
}
Ok(())
}
/// Metadata of a device.
#[serde_inline_default]
#[derive(Clone, Deserialize, Serialize)]
+4 -2
View File
@@ -8,6 +8,7 @@
"bundle": {
"active": true,
"targets": "all",
"resources": { "target/plugins/": "plugins/" },
"linux": {
"deb": {
"desktopTemplate": "bundle/opendeck.desktop",
@@ -44,7 +45,7 @@
"plugins": {
"deep-link": {
"desktop": {
"schemes": [ "opendeck" ]
"schemes": ["opendeck"]
}
}
},
@@ -58,7 +59,8 @@
"height": 600,
"minWidth": 800,
"minHeight": 600,
"center": true
"center": true,
"dragDropEnabled": false
}
],
"security": {
+1 -9
View File
@@ -97,15 +97,7 @@
}
let installed: any[] = [];
(async () => {
installed = await invoke("list_plugins");
if (!installed.some((v) => v.id == "com.amansprojects.starterpack.sdPlugin")) {
await installPluginGitHub(
"com.amansprojects.starterpack",
{ name: "OpenDeck Starter Pack", repository: "https://github.com/ninjadev64/opendeck-starterpack" } as GitHubPlugin,
);
}
})();
(async () => installed = await invoke("list_plugins"))();
let plugins: { [id: string]: GitHubPlugin };
(async () => plugins = await (await fetch("https://ninjadev64.github.io/openaction-plugins/catalogue.json")).json())();