Skip to content

Commit

Permalink
Improvements in preparation for Flatpak support
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjadev64 committed Oct 13, 2024
1 parent ce2e534 commit 94da792
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 49 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- release
workflow_dispatch:

jobs:
publish-tauri:
Expand Down
13 changes: 10 additions & 3 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,24 @@ async fn main() {
.filter(|v| {
!matches!(
v.target(),
"tungstenite::handshake::server" | "tungstenite::protocol" | "tracing::span" | "zbus::object_server" | "zbus::handshake" | "zbus::connection"
"tungstenite::handshake::server" | "tungstenite::protocol" | "tracing::span" | "zbus::object_server" | "zbus::handshake" | "zbus::connection" | "os_info::imp::lsb_release"
)
})
.build(),
)
.plugin(tauri_plugin_autostart::init(tauri_plugin_autostart::MacosLauncher::LaunchAgent, Some(vec!["--hide"])))
.plugin(tauri_plugin_single_instance::init(|app, _, _| app.get_webview_window("main").unwrap().show().unwrap()))
.on_window_event(|window, event| {
if window.label() != "main" {
return;
}
if let WindowEvent::CloseRequested { api, .. } = event {
window.hide().unwrap();
api.prevent_close();
if let Ok(true) = store::get_settings().map(|store| store.value.background) {
window.hide().unwrap();
api.prevent_close();
} else {
window.app_handle().exit(0);
}
}
})
.run(tauri::generate_context!())
Expand Down
67 changes: 21 additions & 46 deletions src-tauri/src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub async fn initialise_plugin(path: &path::PathBuf) -> anyhow::Result<()> {
}

let code_path = code_path.unwrap();
let args = ["-port", "57116", "-pluginUUID", plugin_uuid, "-registerEvent", "registerPlugin", "-info"];

if code_path.to_lowercase().ends_with(".html") || code_path.to_lowercase().ends_with(".htm") || code_path.to_lowercase().ends_with(".xhtml") {
// Create a webview window for the plugin and call its registration function.
Expand Down Expand Up @@ -177,53 +178,43 @@ pub async fn initialise_plugin(path: &path::PathBuf) -> anyhow::Result<()> {
INSTANCES.lock().await.insert(plugin_uuid.to_owned(), PluginInstance::Webview);
} else if code_path.to_lowercase().ends_with(".js") || code_path.to_lowercase().ends_with(".mjs") || code_path.to_lowercase().ends_with(".cjs") {
// Check for Node.js installation and version in one go.
let version_output = Command::new("node").arg("--version").output();
let command = if std::env::var("container").is_ok() { "flatpak-spawn" } else { "node" };
let extra_args = if std::env::var("container").is_ok() { vec!["--host", "node"] } else { vec![] };
let version_output = Command::new(command).args(&extra_args).arg("--version").output();
if version_output.is_err() || String::from_utf8(version_output.unwrap().stdout).unwrap().trim() < "v20.0.0" {
return Err(anyhow!("Node version 20.0.0 or higher is required, or Node is not installed"));
}

let info = info_param::make_info(plugin_uuid.to_owned(), manifest.version, true).await;
let log_file = fs::File::create(path.parent().unwrap().parent().unwrap().join("logs").join("plugins").join(format!("{plugin_uuid}.log")))?;
// Start Node with the appropriate arguments.
let child = Command::new("node")
let child = Command::new(command)
.current_dir(path)
.args([
code_path,
String::from("-port"),
57116.to_string(),
String::from("-pluginUUID"),
plugin_uuid.to_owned(),
String::from("-registerEvent"),
String::from("registerPlugin"),
String::from("-info"),
serde_json::to_string(&info)?,
])
.args(extra_args)
.arg(code_path)
.args(args)
.arg(serde_json::to_string(&info)?)
.stdout(Stdio::from(log_file.try_clone()?))
.stderr(Stdio::from(log_file))
.spawn()?;

INSTANCES.lock().await.insert(plugin_uuid.to_owned(), PluginInstance::Node(child));
} else if use_wine {
if Command::new("wine").stdout(Stdio::null()).stderr(Stdio::null()).spawn().is_err() {
let command = if std::env::var("container").is_ok() { "flatpak-spawn" } else { "wine" };
let extra_args = if std::env::var("container").is_ok() { vec!["--host", "wine"] } else { vec![] };
if Command::new(command).stdout(Stdio::null()).stderr(Stdio::null()).spawn().is_err() {
return Err(anyhow!("failed to detect an installation of Wine"));
}

let info = info_param::make_info(plugin_uuid.to_owned(), manifest.version, true).await;
let log_file = fs::File::create(path.parent().unwrap().parent().unwrap().join("logs").join("plugins").join(format!("{plugin_uuid}.log")))?;
// Start Wine with the appropriate arguments.
let child = Command::new("wine")
let child = Command::new(command)
.current_dir(path)
.args([
&code_path,
"-port",
"57116",
"-pluginUUID",
plugin_uuid,
"-registerEvent",
"registerPlugin",
"-info",
&serde_json::to_string(&info)?,
])
.args(extra_args)
.arg(code_path)
.args(args)
.arg(serde_json::to_string(&info)?)
.stdout(Stdio::from(log_file.try_clone()?))
.stderr(Stdio::from(log_file))
.spawn()?;
Expand All @@ -236,33 +227,17 @@ pub async fn initialise_plugin(path: &path::PathBuf) -> anyhow::Result<()> {
#[cfg(target_os = "windows")]
let child = Command::new(path.join(code_path))
.current_dir(path)
.args([
"-port",
"57116",
"-pluginUUID",
plugin_uuid,
"-registerEvent",
"registerPlugin",
"-info",
&serde_json::to_string(&info)?,
])
.args(args)
.arg(serde_json::to_string(&info)?)
.stdout(Stdio::from(log_file.try_clone()?))
.stderr(Stdio::from(log_file))
.creation_flags(0x08000000)
.spawn()?;
#[cfg(not(target_os = "windows"))]
let child = Command::new(path.join(code_path))
.current_dir(path)
.args([
"-port",
"57116",
"-pluginUUID",
plugin_uuid,
"-registerEvent",
"registerPlugin",
"-info",
&serde_json::to_string(&info)?,
])
.args(args)
.arg(serde_json::to_string(&info)?)
.stdout(Stdio::from(log_file.try_clone()?))
.stderr(Stdio::from(log_file))
.spawn()?;
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ where
#[serde(default)]
pub struct Settings {
pub language: String,
pub background: bool,
pub autolaunch: bool,
pub darktheme: bool,
pub brightness: u8,
Expand All @@ -78,6 +79,7 @@ impl Default for Settings {
fn default() -> Self {
Self {
language: "en".to_owned(),
background: std::env::var("container").is_err(),
autolaunch: false,
darktheme: true,
brightness: 50,
Expand Down
6 changes: 6 additions & 0 deletions src/components/SettingsView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
</Tooltip>
</div>

<div class="flex flex-row items-center m-2 space-x-2">
<span class="dark:text-neutral-400"> Run in background: </span>
<input type="checkbox" bind:checked={$settings.background} />
<Tooltip> If this option is enabled, OpenDeck will minimise to the tray and run in the background. </Tooltip>
</div>

<div class="flex flex-row items-center m-2 space-x-2">
<span class="dark:text-neutral-400"> Autolaunch: </span>
<input type="checkbox" bind:checked={$settings.autolaunch} />
Expand Down
1 change: 1 addition & 0 deletions src/lib/settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export type Settings = {
language: string;
background: boolean;
autolaunch: boolean;
darktheme: boolean;
brightness: number;
Expand Down

0 comments on commit 94da792

Please sign in to comment.