From 321a41798284e4a1da8fb7182c99fdb0c24c0c99 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Tue, 11 Jun 2024 18:25:13 -0600 Subject: [PATCH 01/53] cleanup: trim deps in kinode_lib --- Cargo.lock | 3 --- lib/Cargo.toml | 2 -- lib/build.rs | 14 ++++++-------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02a8497dc..f7f5fc9bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3373,11 +3373,9 @@ version = "0.8.1" dependencies = [ "alloy-json-rpc 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=05f8162)", "alloy-rpc-types 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=05f8162)", - "anyhow", "kit", "lazy_static", "rand 0.8.5", - "reqwest 0.12.4", "ring", "rusqlite", "serde", @@ -4621,7 +4619,6 @@ dependencies = [ "base64 0.22.0", "bytes", "encoding_rs", - "futures-channel", "futures-core", "futures-util", "h2 0.4.4", diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 83726a7a4..e8a4e0875 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -11,9 +11,7 @@ license = "Apache-2.0" [lib] [build-dependencies] -anyhow = "1.0.71" kit = { git = "https://github.com/kinode-dao/kit", rev = "d319c5b" } -reqwest = { version = "0.12.4", features = ["blocking"] } tokio = "1.28" [dependencies] diff --git a/lib/build.rs b/lib/build.rs index 3662a3463..9f62fd1c0 100644 --- a/lib/build.rs +++ b/lib/build.rs @@ -4,13 +4,13 @@ const KINODE_WIT_0_7_0_URL: &str = const KINODE_WIT_0_8_0_URL: &str = "https://raw.githubusercontent.com/kinode-dao/kinode-wit/v0.8/kinode.wit"; -fn main() -> anyhow::Result<()> { +fn main() { if std::env::var("SKIP_BUILD_SCRIPT").is_ok() { println!("Skipping build script"); - return Ok(()); + return; } - let pwd = std::env::current_dir()?; + let pwd = std::env::current_dir().expect("Failed to get current directory"); let wit_file = pwd.join("wit-v0.7.0").join("kinode.wit"); @@ -18,9 +18,8 @@ fn main() -> anyhow::Result<()> { rt.block_on(async { kit::build::download_file(KINODE_WIT_0_7_0_URL, &wit_file) .await - .map_err(|e| anyhow::anyhow!("{:?}", e))?; - Ok::<(), anyhow::Error>(()) - })?; + .expect("Failed to download WIT 0.7"); + }); let wit_file = pwd.join("wit-v0.8.0").join("kinode.wit"); @@ -28,7 +27,6 @@ fn main() -> anyhow::Result<()> { rt.block_on(async { kit::build::download_file(KINODE_WIT_0_8_0_URL, &wit_file) .await - .map_err(|e| anyhow::anyhow!("{:?}", e))?; - Ok(()) + .expect("Failed to download WIT 0.8"); }) } From b907b7d0e69c8387c298b34dbb7e1d0e59a35d97 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Tue, 11 Jun 2024 17:44:22 -0700 Subject: [PATCH 02/53] update helptext --- kinode/src/main.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kinode/src/main.rs b/kinode/src/main.rs index ff73c8721..9d7cfa2a0 100644 --- a/kinode/src/main.rs +++ b/kinode/src/main.rs @@ -37,6 +37,9 @@ const CAP_CHANNEL_CAPACITY: usize = 1_000; const KV_CHANNEL_CAPACITY: usize = 1_000; const SQLITE_CHANNEL_CAPACITY: usize = 1_000; const VERSION: &str = env!("CARGO_PKG_VERSION"); +const WS_MIN_PORT: u16 = 9_000; +const TCP_MIN_PORT: u16 = 10_000; +const MAX_PORT: u16 = 65_535; /// default routers as a eth-provider fallback const DEFAULT_ETH_PROVIDERS: &str = include_str!("eth/default_providers_mainnet.json"); #[cfg(not(feature = "simulation-mode"))] @@ -517,8 +520,8 @@ async fn setup_networking( (Some(listener), true) } None => { - let min_port = if protocol == "ws" { 9000 } else { 10000 }; - let listener = http::utils::find_open_port(min_port, 65535) + let min_port = if protocol == "ws" { WS_MIN_PORT } else { TCP_MIN_PORT }; + let listener = http::utils::find_open_port(min_port, MAX_PORT) .await .expect("no ports found in range 9000-65535 for kinode networking"); (Some(listener), false) @@ -648,7 +651,7 @@ fn build_command() -> Command { .value_parser(value_parser!(u16)), ) .arg( - arg!(--"tcp-port" "Kinode internal TCP protocol port [default: first unbound at or above 9000]") + arg!(--"tcp-port" "Kinode internal TCP protocol port [default: first unbound at or above 10000]") .alias("--tcp-port") .value_parser(value_parser!(u16)), ) @@ -663,7 +666,7 @@ fn build_command() -> Command { .value_parser(value_parser!(bool)), ) .arg(arg!(--rpc "Add a WebSockets RPC URL at boot")) - .arg(arg!(--password "Node password")); + .arg(arg!(--password "Node password (in double quotes)")); #[cfg(feature = "simulation-mode")] let app = app From 0592044ec04cf1dfc882fc0cd5f334bcf515171d Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Tue, 11 Jun 2024 21:38:51 -0600 Subject: [PATCH 03/53] cleanup: use features for alloy --- Cargo.lock | 3 +-- kinode/Cargo.toml | 1 - lib/Cargo.toml | 6 ++++-- lib/src/eth.rs | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f7f5fc9bd..645bc8ae4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3371,8 +3371,7 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" name = "lib" version = "0.8.1" dependencies = [ - "alloy-json-rpc 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=05f8162)", - "alloy-rpc-types 0.1.0 (git+https://github.com/alloy-rs/alloy?rev=05f8162)", + "alloy", "kit", "lazy_static", "rand 0.8.5", diff --git a/kinode/Cargo.toml b/kinode/Cargo.toml index c036387f5..3036adb5e 100644 --- a/kinode/Cargo.toml +++ b/kinode/Cargo.toml @@ -41,7 +41,6 @@ alloy = { git = "https://github.com/alloy-rs/alloy", rev = "05f8162", features = "signer-wallet", "signers", ] } - alloy-primitives = "0.7.5" alloy-sol-macro = "0.7.5" alloy-sol-types = "0.7.5" diff --git a/lib/Cargo.toml b/lib/Cargo.toml index e8a4e0875..7d66a4930 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -15,8 +15,10 @@ kit = { git = "https://github.com/kinode-dao/kit", rev = "d319c5b" } tokio = "1.28" [dependencies] -alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "05f8162" } -alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy", rev = "05f8162" } +alloy = { git = "https://github.com/alloy-rs/alloy", rev = "05f8162", features = [ + "json-rpc", + "rpc-types", +] } lazy_static = "1.4.0" rand = "0.8.4" ring = "0.17.8" diff --git a/lib/src/eth.rs b/lib/src/eth.rs index 16ec46601..ba13b8843 100644 --- a/lib/src/eth.rs +++ b/lib/src/eth.rs @@ -1,5 +1,5 @@ -use alloy_json_rpc::ErrorPayload; -use alloy_rpc_types::pubsub::{Params, SubscriptionKind, SubscriptionResult}; +use alloy::rpc::json_rpc::ErrorPayload; +use alloy::rpc::types::eth::pubsub::{Params, SubscriptionKind, SubscriptionResult}; use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; From 926e5744f74544bb94960bbe5993dea1a7149dd5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 12 Jun 2024 03:39:15 +0000 Subject: [PATCH 04/53] Format Rust code using rustfmt --- kinode/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kinode/src/main.rs b/kinode/src/main.rs index 9d7cfa2a0..57cd8cd1e 100644 --- a/kinode/src/main.rs +++ b/kinode/src/main.rs @@ -520,7 +520,11 @@ async fn setup_networking( (Some(listener), true) } None => { - let min_port = if protocol == "ws" { WS_MIN_PORT } else { TCP_MIN_PORT }; + let min_port = if protocol == "ws" { + WS_MIN_PORT + } else { + TCP_MIN_PORT + }; let listener = http::utils::find_open_port(min_port, MAX_PORT) .await .expect("no ports found in range 9000-65535 for kinode networking"); From dac4a2e52625a14b0c275acf376365b7e88a83fe Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Tue, 11 Jun 2024 22:00:43 -0600 Subject: [PATCH 05/53] vfs: use sha256, remove blake3 dep --- Cargo.lock | 20 -------------------- kinode/Cargo.toml | 1 - kinode/src/vfs.rs | 29 +++++++++++++++-------------- 3 files changed, 15 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 645bc8ae4..a5eacb5fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -883,12 +883,6 @@ dependencies = [ "rand 0.8.5", ] -[[package]] -name = "arrayref" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" - [[package]] name = "arrayvec" version = "0.7.4" @@ -1093,19 +1087,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "blake3" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30cca6d3674597c30ddf2c587bf8d9d65c9a84d2326d941cc79c9842dfe0ef52" -dependencies = [ - "arrayref", - "arrayvec", - "cc", - "cfg-if", - "constant_time_eq 0.3.0", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -3190,7 +3171,6 @@ dependencies = [ "async-trait", "base64 0.22.0", "bincode", - "blake3", "bytes", "chacha20poly1305", "chrono", diff --git a/kinode/Cargo.toml b/kinode/Cargo.toml index 3036adb5e..0490da277 100644 --- a/kinode/Cargo.toml +++ b/kinode/Cargo.toml @@ -48,7 +48,6 @@ anyhow = "1.0.71" async-trait = "0.1.71" base64 = "0.22.0" bincode = "1.3.3" -blake3 = "1.4.1" bytes = "1.4.0" chacha20poly1305 = "0.10.1" chrono = "0.4.31" diff --git a/kinode/src/vfs.rs b/kinode/src/vfs.rs index e46e08c7d..4312a21cd 100644 --- a/kinode/src/vfs.rs +++ b/kinode/src/vfs.rs @@ -69,7 +69,7 @@ pub async fn vfs( if let Err(e) = handle_request( &our_node, km, - open_files.clone(), + open_files, &send_to_loop, &send_to_terminal, &send_to_caps_oracle, @@ -230,13 +230,13 @@ async fn handle_request( VfsAction::CreateFile => { // create truncates any file that might've existed before open_files.remove(&path); - let _file = open_file(open_files.clone(), path, true, true).await?; + let _file = open_file(open_files, path, true, true).await?; (serde_json::to_vec(&VfsResponse::Ok).unwrap(), None) } VfsAction::OpenFile { create } => { // open file opens an existing file, or creates a new one if create is true - let file = open_file(open_files.clone(), path, create, false).await?; + let file = open_file(open_files, path, create, false).await?; let mut file = file.lock().await; // extra in the case file was just created, todo refactor out. file.seek(SeekFrom::Start(0)).await?; @@ -255,7 +255,7 @@ async fn handle_request( error: "blob needs to exist for WriteAll".into(), }); }; - let file = open_file(open_files.clone(), path, false, false).await?; + let file = open_file(open_files, path, false, false).await?; let mut file = file.lock().await; file.write_all(&blob.bytes).await?; (serde_json::to_vec(&VfsResponse::Ok).unwrap(), None) @@ -275,7 +275,7 @@ async fn handle_request( error: "blob needs to exist for Append".into(), }); }; - let file = open_file(open_files.clone(), path, false, false).await?; + let file = open_file(open_files, path, false, false).await?; let mut file = file.lock().await; file.seek(SeekFrom::End(0)).await?; file.write_all(&blob.bytes).await?; @@ -283,7 +283,7 @@ async fn handle_request( (serde_json::to_vec(&VfsResponse::Ok).unwrap(), None) } VfsAction::SyncAll => { - let file = open_file(open_files.clone(), path, false, false).await?; + let file = open_file(open_files, path, false, false).await?; let file = file.lock().await; file.sync_all().await?; (serde_json::to_vec(&VfsResponse::Ok).unwrap(), None) @@ -297,7 +297,7 @@ async fn handle_request( ) } VfsAction::ReadToEnd => { - let file = open_file(open_files.clone(), path.clone(), false, false).await?; + let file = open_file(open_files, path.clone(), false, false).await?; let mut file = file.lock().await; let mut contents = Vec::new(); @@ -309,7 +309,7 @@ async fn handle_request( ) } VfsAction::ReadExact(length) => { - let file = open_file(open_files.clone(), path, false, false).await?; + let file = open_file(open_files, path, false, false).await?; let mut file = file.lock().await; let mut contents = vec![0; length as usize]; file.read_exact(&mut contents).await?; @@ -339,7 +339,7 @@ async fn handle_request( ) } VfsAction::ReadToString => { - let file = open_file(open_files.clone(), path, false, false).await?; + let file = open_file(open_files, path, false, false).await?; let mut file = file.lock().await; let mut contents = String::new(); file.read_to_string(&mut contents).await?; @@ -349,7 +349,7 @@ async fn handle_request( ) } VfsAction::Seek { seek_from } => { - let file = open_file(open_files.clone(), path, false, false).await?; + let file = open_file(open_files, path, false, false).await?; let mut file = file.lock().await; // same type, rust tingz let seek_from = match seek_from { @@ -401,22 +401,23 @@ async fn handle_request( ) } VfsAction::Len => { - let file = open_file(open_files.clone(), path, false, false).await?; + let file = open_file(open_files, path, false, false).await?; let file = file.lock().await; let len = file.metadata().await?.len(); (serde_json::to_vec(&VfsResponse::Len(len)).unwrap(), None) } VfsAction::SetLen(len) => { - let file = open_file(open_files.clone(), path, false, false).await?; + let file = open_file(open_files, path, false, false).await?; let file = file.lock().await; file.set_len(len).await?; (serde_json::to_vec(&VfsResponse::Ok).unwrap(), None) } VfsAction::Hash => { - let file = open_file(open_files.clone(), path, false, false).await?; + use sha2::{Digest, Sha256}; + let file = open_file(open_files, path, false, false).await?; let mut file = file.lock().await; file.seek(SeekFrom::Start(0)).await?; - let mut hasher = blake3::Hasher::new(); + let mut hasher = Sha256::new(); let mut buffer = [0; 1024]; loop { let bytes_read = file.read(&mut buffer).await?; From 1538f8e90f702aec305c47c3b05a4c923cab3a61 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Tue, 11 Jun 2024 22:43:30 -0600 Subject: [PATCH 06/53] cleanup: get rid of unused deps --- Cargo.lock | 128 ++++++++++++++++++++++++----------------- kinode/Cargo.toml | 21 ++----- kinode/build.rs | 2 +- kinode/src/keygen.rs | 2 +- kinode/src/main.rs | 4 +- kinode/src/register.rs | 50 ++++++---------- lib/Cargo.toml | 2 +- 7 files changed, 103 insertions(+), 106 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a5eacb5fd..f1e313933 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,7 +24,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" dependencies = [ "crypto-common", - "generic-array 0.14.7", + "generic-array", ] [[package]] @@ -1093,7 +1093,7 @@ version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ - "generic-array 0.14.7", + "generic-array", ] [[package]] @@ -1699,7 +1699,7 @@ dependencies = [ "futures-core", "libc", "mio", - "parking_lot", + "parking_lot 0.12.1", "signal-hook", "signal-hook-mio", "winapi", @@ -1726,7 +1726,7 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" dependencies = [ - "generic-array 0.14.7", + "generic-array", "rand_core 0.6.4", "subtle", "zeroize", @@ -1738,7 +1738,7 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ - "generic-array 0.14.7", + "generic-array", "rand_core 0.6.4", "typenum", ] @@ -1824,7 +1824,7 @@ dependencies = [ "hashbrown 0.14.3", "lock_api", "once_cell", - "parking_lot_core", + "parking_lot_core 0.9.9", ] [[package]] @@ -1933,7 +1933,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.7", + "generic-array", ] [[package]] @@ -2080,9 +2080,8 @@ dependencies = [ "crypto-bigint", "digest 0.10.7", "ff", - "generic-array 0.14.7", + "generic-array", "group", - "hkdf", "pkcs8", "rand_core 0.6.4", "sec1", @@ -2425,15 +2424,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "generic-array" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe739944a5406424e080edccb6add95685130b9f160d5407c639c7df0c5836b0" -dependencies = [ - "typenum", -] - [[package]] name = "get_block" version = "0.1.0" @@ -2644,15 +2634,6 @@ dependencies = [ "wit-bindgen", ] -[[package]] -name = "hkdf" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" -dependencies = [ - "hmac", -] - [[package]] name = "hmac" version = "0.12.1" @@ -2971,7 +2952,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" dependencies = [ - "generic-array 0.14.7", + "generic-array", ] [[package]] @@ -2985,6 +2966,15 @@ dependencies = [ "wit-bindgen", ] +[[package]] +name = "instant" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +dependencies = [ + "cfg-if", +] + [[package]] name = "io-extras" version = "0.18.2" @@ -3171,30 +3161,20 @@ dependencies = [ "async-trait", "base64 0.22.0", "bincode", - "bytes", - "chacha20poly1305", "chrono", "clap", "crossterm", - "curve25519-dalek", "dashmap", - "digest 0.10.7", - "elliptic-curve", - "flate2", "futures", - "generic-array 1.0.0", - "getrandom", + "generic-array", "hex", - "hkdf", "hmac", "http 1.1.0", "jwt", "kit", "lazy_static", "lib", - "log", "nohash-hasher", - "num-traits", "open", "public-ip", "rand 0.8.5", @@ -3207,7 +3187,6 @@ dependencies = [ "rusqlite", "serde", "serde_json", - "serde_urlencoded", "sha2", "sha3", "snow", @@ -3217,7 +3196,6 @@ dependencies = [ "tokio", "tokio-tungstenite 0.21.0", "url", - "uuid", "walkdir", "warp", "wasi-common", @@ -3280,8 +3258,8 @@ dependencies = [ [[package]] name = "kit" -version = "0.4.2" -source = "git+https://github.com/kinode-dao/kit?rev=d319c5b#d319c5b573166e54ead9da47d363e65b9cd47c57" +version = "0.6.2" +source = "git+https://github.com/kinode-dao/kit?tag=v0.6.2#59ca74d4952998753bf5e64404d09f31a4424830" dependencies = [ "anyhow", "base64 0.21.7", @@ -3301,15 +3279,17 @@ dependencies = [ "serde", "serde_json", "sha2", + "ssh2", "thiserror", "tokio", - "tokio-tungstenite 0.21.0", + "tokio-tungstenite 0.20.1", "toml", "tracing", "tracing-appender", "tracing-error", "tracing-subscriber", "walkdir", + "wit-bindgen", "zip 0.6.6", ] @@ -3834,9 +3814,9 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "open" -version = "5.1.2" +version = "5.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "449f0ff855d85ddbf1edd5b646d65249ead3f5e422aaa86b7d2d0b049b103e32" +checksum = "b5ca541f22b1c46d4bb9801014f234758ab4297e7870b904b6a8415b980a7388" dependencies = [ "is-wsl", "libc", @@ -3931,6 +3911,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core 0.8.6", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -3938,7 +3929,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core", + "parking_lot_core 0.9.9", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall 0.2.16", + "smallvec", + "winapi", ] [[package]] @@ -3949,7 +3954,7 @@ checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.4.1", "smallvec", "windows-targets 0.48.5", ] @@ -4472,6 +4477,15 @@ dependencies = [ "rand_core 0.3.1", ] +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_syscall" version = "0.4.1" @@ -4918,7 +4932,7 @@ checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" dependencies = [ "base16ct", "der", - "generic-array 0.14.7", + "generic-array", "pkcs8", "subtle", "zeroize", @@ -5244,6 +5258,18 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b9b39299b249ad65f3b7e96443bad61c02ca5cd3589f46cb6d610a0fd6c0d6a" +[[package]] +name = "ssh2" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7fe461910559f6d5604c3731d00d2aafc4a83d1665922e280f42f9a168d5455" +dependencies = [ + "bitflags 1.3.2", + "libc", + "libssh2-sys", + "parking_lot 0.11.2", +] + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -6085,10 +6111,6 @@ name = "uuid" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" -dependencies = [ - "getrandom", - "serde", -] [[package]] name = "valuable" diff --git a/kinode/Cargo.toml b/kinode/Cargo.toml index 0490da277..8638130e9 100644 --- a/kinode/Cargo.toml +++ b/kinode/Cargo.toml @@ -14,9 +14,8 @@ path = "src/main.rs" [build-dependencies] anyhow = "1.0.71" -kit = { git = "https://github.com/kinode-dao/kit", rev = "d319c5b" } +kit = { git = "https://github.com/kinode-dao/kit", tag = "v0.6.2" } rayon = "1.8.1" -sha2 = "0.10" tokio = "1.28" walkdir = "2.4" zip = "0.6" @@ -48,30 +47,20 @@ anyhow = "1.0.71" async-trait = "0.1.71" base64 = "0.22.0" bincode = "1.3.3" -bytes = "1.4.0" -chacha20poly1305 = "0.10.1" chrono = "0.4.31" clap = { version = "4.4", features = ["derive"] } crossterm = { version = "0.27.0", features = ["event-stream", "bracketed-paste"] } -curve25519-dalek = "^4.1.2" dashmap = "5.5.3" -digest = "0.10" -elliptic-curve = { version = "0.13.8", features = ["ecdh"] } -flate2 = "1.0" futures = "0.3" -generic-array = "1.0.0" -getrandom = "0.2.10" +generic-array = "0.14.7" hex = "0.4.3" -hkdf = "0.12.3" hmac = "0.12" http = "1.1.0" jwt = "0.16" lib = { path = "../lib" } lazy_static = "1.4.0" -log = "0.4.20" nohash-hasher = "0.2.0" -num-traits = "0.2" -open = "5.0.0" +open = "5.1.4" public-ip = "0.2.2" rand = "0.8.4" reqwest = "0.12.4" @@ -82,8 +71,7 @@ route-recognizer = "0.3.1" rusqlite = { version = "0.31.0", features = ["bundled"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -serde_urlencoded = "0.7" -sha2 = "0.10" +sha2 = "0.10.8" sha3 = "0.10.8" # snow = { version = "0.9.5", features = ["ring-resolver"] } # unfortunately need to use forked version for async use and in-place encryption @@ -94,7 +82,6 @@ thiserror = "1.0" tokio = { version = "1.28", features = ["fs", "macros", "rt-multi-thread", "signal", "sync"] } tokio-tungstenite = { version = "0.21.0", features = ["native-tls"] } url = "2.4.1" -uuid = { version = "1.1.2", features = ["serde", "v4"] } warp = "0.3.5" wasi-common = "19.0.1" wasmtime = "19.0.1" diff --git a/kinode/build.rs b/kinode/build.rs index 4e416676e..cd9264ac7 100644 --- a/kinode/build.rs +++ b/kinode/build.rs @@ -59,7 +59,7 @@ fn build_and_zip_package( ) -> anyhow::Result<(String, String, Vec)> { let rt = tokio::runtime::Runtime::new().unwrap(); rt.block_on(async { - kit::build::execute(&entry_path, true, false, true, features, None, None) // TODO + kit::build::execute(&entry_path, true, false, true, features, None, None, true) .await .map_err(|e| anyhow::anyhow!("{:?}", e))?; diff --git a/kinode/src/keygen.rs b/kinode/src/keygen.rs index 7b71443cf..945238b0e 100644 --- a/kinode/src/keygen.rs +++ b/kinode/src/keygen.rs @@ -4,7 +4,7 @@ use aes_gcm::{ }; use alloy_primitives::keccak256; use anyhow::Result; -use digest::generic_array::GenericArray; +use generic_array::GenericArray; use hmac::Hmac; use jwt::SignWithKey; use lib::types::core::Keyfile; diff --git a/kinode/src/main.rs b/kinode/src/main.rs index 57cd8cd1e..14a04a6d3 100644 --- a/kinode/src/main.rs +++ b/kinode/src/main.rs @@ -779,13 +779,13 @@ async fn login_with_password( maybe_rpc: Option, password: &str, ) -> (Identity, Vec, Keyfile) { - use {alloy_primitives::Address as EthAddress, digest::Digest, ring::signature::KeyPair}; + use {alloy_primitives::Address as EthAddress, sha2::{Digest, Sha256}, ring::signature::KeyPair}; let disk_keyfile: Vec = tokio::fs::read(format!("{}/.keys", home_directory_path)) .await .expect("could not read keyfile"); - let password_hash = format!("0x{}", hex::encode(sha2::Sha256::digest(password))); + let password_hash = format!("0x{}", hex::encode(Sha256::digest(password))); // KnsRegistrar contract address let kns_address: EthAddress = KNS_ADDRESS.parse().unwrap(); diff --git a/kinode/src/register.rs b/kinode/src/register.rs index 03527ef8d..863a02998 100644 --- a/kinode/src/register.rs +++ b/kinode/src/register.rs @@ -106,26 +106,25 @@ pub async fn register( let static_files = warp::path("assets").and(static_dir!("src/register-ui/build/assets/")); let react_app = warp::path::end() + .or(warp::path("login")) + .or(warp::path("register-name")) + .or(warp::path("claim-invite")) + .or(warp::path("reset")) + .or(warp::path("import-keyfile")) + .or(warp::path("set-password")) .and(warp::get()) - .map(move || warp::reply::html(include_str!("register-ui/build/index.html"))) - .or(warp::path("login") - .and(warp::get()) - .map(move || warp::reply::html(include_str!("register-ui/build/index.html")))) - .or(warp::path("register-name") - .and(warp::get()) - .map(move || warp::reply::html(include_str!("register-ui/build/index.html")))) - .or(warp::path("claim-invite") - .and(warp::get()) - .map(move || warp::reply::html(include_str!("register-ui/build/index.html")))) - .or(warp::path("reset") - .and(warp::get()) - .map(move || warp::reply::html(include_str!("register-ui/build/index.html")))) - .or(warp::path("import-keyfile") - .and(warp::get()) - .map(move || warp::reply::html(include_str!("register-ui/build/index.html")))) - .or(warp::path("set-password") - .and(warp::get()) - .map(move || warp::reply::html(include_str!("register-ui/build/index.html")))) + .map(move |_| warp::reply::html(include_str!("register-ui/build/index.html"))); + + let boot_provider = provider.clone(); + let login_provider = provider.clone(); + let import_provider = provider.clone(); + + let api = warp::path("info") + .and( + warp::get() + .and(keyfile.clone()) + .and_then(get_unencrypted_info), + ) .or(warp::path("current-chain") .and(warp::get()) .map(move || warp::reply::json(&"0xa"))) @@ -146,18 +145,7 @@ pub async fn register( } warp::reply::html(String::new()) }, - )); - - let boot_provider = provider.clone(); - let login_provider = provider.clone(); - let import_provider = provider.clone(); - - let api = warp::path("info") - .and( - warp::get() - .and(keyfile.clone()) - .and_then(get_unencrypted_info), - ) + )) .or(warp::path("generate-networking-info").and( warp::post() .and(our_temp_id.clone()) diff --git a/lib/Cargo.toml b/lib/Cargo.toml index 7d66a4930..2ce33b95c 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -11,7 +11,7 @@ license = "Apache-2.0" [lib] [build-dependencies] -kit = { git = "https://github.com/kinode-dao/kit", rev = "d319c5b" } +kit = { git = "https://github.com/kinode-dao/kit", tag = "v0.6.2" } tokio = "1.28" [dependencies] From 03d4eff379433766dc2ba1b3c05c5ef100d4e22a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 12 Jun 2024 04:43:53 +0000 Subject: [PATCH 07/53] Format Rust code using rustfmt --- kinode/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kinode/src/main.rs b/kinode/src/main.rs index 14a04a6d3..43c8e02f6 100644 --- a/kinode/src/main.rs +++ b/kinode/src/main.rs @@ -779,7 +779,11 @@ async fn login_with_password( maybe_rpc: Option, password: &str, ) -> (Identity, Vec, Keyfile) { - use {alloy_primitives::Address as EthAddress, sha2::{Digest, Sha256}, ring::signature::KeyPair}; + use { + alloy_primitives::Address as EthAddress, + ring::signature::KeyPair, + sha2::{Digest, Sha256}, + }; let disk_keyfile: Vec = tokio::fs::read(format!("{}/.keys", home_directory_path)) .await From ea762d31b2d363fb3f33f9907a7c83af602c37a2 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Wed, 12 Jun 2024 19:29:02 -0600 Subject: [PATCH 08/53] tester_lib remove rust-analyzer warning --- kinode/packages/tester/tester/src/tester_lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/kinode/packages/tester/tester/src/tester_lib.rs b/kinode/packages/tester/tester/src/tester_lib.rs index 171c08c89..8fb7ae19d 100644 --- a/kinode/packages/tester/tester/src/tester_lib.rs +++ b/kinode/packages/tester/tester/src/tester_lib.rs @@ -1,3 +1,4 @@ +#[allow(unused_imports)] use crate::kinode::process::tester::{FailResponse, Response as TesterResponse}; #[macro_export] From 5a0778242489ed926fa485da4e0e88d367ad1960 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Thu, 13 Jun 2024 18:14:05 -0600 Subject: [PATCH 09/53] WIP: refactor terminal for clarity, improve comments, add print to acknowledge exit code, make kernel more efficient by allowing terminal to turn off event-loop-prints --- kinode/src/kernel/mod.rs | 24 +++- kinode/src/main.rs | 13 +-- kinode/src/terminal/mod.rs | 218 +++++++++++++---------------------- kinode/src/terminal/utils.rs | 137 +++++++++++++++++++++- lib/build.rs | 28 ++--- lib/src/core.rs | 3 +- 6 files changed, 252 insertions(+), 171 deletions(-) diff --git a/kinode/src/kernel/mod.rs b/kinode/src/kernel/mod.rs index c7bc759ba..672d25958 100644 --- a/kinode/src/kernel/mod.rs +++ b/kinode/src/kernel/mod.rs @@ -710,6 +710,9 @@ pub async fn kernel( let mut process_handles: ProcessHandles = HashMap::new(); let mut is_debug: bool = false; + // this flag starts as true, and terminal will alert us if we can + // skip sending prints for every event. + let mut print_full_event_loop: bool = true; let mut reboot_processes: Vec<(t::ProcessId, StartProcessMetadata, Vec)> = vec![]; // filter out OnExit::None processes from process_map @@ -870,9 +873,17 @@ pub async fn kernel( loop { tokio::select! { // debug mode toggle: when on, this loop becomes a manual step-through - debug = recv_debug_in_loop.recv() => { - if let Some(t::DebugCommand::Toggle) = debug { - is_debug = !is_debug; + Some(debug_command) = recv_debug_in_loop.recv() => { + match debug_command { + t::DebugCommand::ToggleStepthrough => { + is_debug = !is_debug; + }, + t::DebugCommand::Step => { + // can't step here, must be in stepthrough-mode + }, + t::DebugCommand::ToggleEventLoop => { + print_full_event_loop = !print_full_event_loop; + } } }, // network error message receiver: handle `timeout` and `offline` errors @@ -1042,17 +1053,20 @@ pub async fn kernel( while is_debug { let debug = recv_debug_in_loop.recv().await.expect("event loop: debug channel died"); match debug { - t::DebugCommand::Toggle => is_debug = !is_debug, + t::DebugCommand::ToggleStepthrough => is_debug = !is_debug, t::DebugCommand::Step => break, + t::DebugCommand::ToggleEventLoop => print_full_event_loop = !print_full_event_loop, } } // display every single event when verbose - let _ = send_to_terminal.send( + if print_full_event_loop { + let _ = send_to_terminal.send( t::Printout { verbosity: 3, content: format!("{kernel_message}") } ).await; + } if our.name != kernel_message.target.node { send_to_net.send(kernel_message).await.expect("fatal: net module died"); diff --git a/kinode/src/main.rs b/kinode/src/main.rs index 43c8e02f6..204e4baa9 100644 --- a/kinode/src/main.rs +++ b/kinode/src/main.rs @@ -455,17 +455,8 @@ async fn main() { // abort all remaining tasks tasks.shutdown().await; - let stdout = std::io::stdout(); - let mut stdout = stdout.lock(); - crossterm::execute!( - stdout, - crossterm::event::DisableBracketedPaste, - crossterm::terminal::SetTitle(""), - crossterm::style::SetForegroundColor(crossterm::style::Color::Red), - crossterm::style::Print(format!("\r\n{quit_msg}\r\n")), - crossterm::style::ResetColor, - ) - .expect("failed to clean up terminal visual state! your terminal window might be funky now"); + // reset all modified aspects of terminal -- clean ourselves up + terminal::utils::cleanup(&quit_msg); } async fn set_http_server_port(set_port: Option<&u16>) -> u16 { diff --git a/kinode/src/terminal/mod.rs b/kinode/src/terminal/mod.rs index 4adcb0505..33881ebdf 100644 --- a/kinode/src/terminal/mod.rs +++ b/kinode/src/terminal/mod.rs @@ -1,41 +1,23 @@ -use anyhow::Result; use chrono::{Datelike, Local, Timelike}; use crossterm::{ cursor, - event::{ - DisableBracketedPaste, EnableBracketedPaste, Event, EventStream, KeyCode, KeyEvent, - KeyModifiers, - }, + event::{Event, EventStream, KeyCode, KeyEvent, KeyModifiers}, execute, style, style::Print, - terminal::{self, disable_raw_mode, enable_raw_mode, ClearType}, + terminal::{self, ClearType}, }; use futures::{future::FutureExt, StreamExt}; -use std::fs::{read_to_string, OpenOptions}; -use std::io::{stdout, BufWriter, Write}; +use lib::types::core::{ + Address, DebugCommand, DebugSender, Identity, KernelMessage, Message, MessageSender, + PrintReceiver, PrintSender, Printout, Request, TERMINAL_PROCESS_ID, +}; +use std::{ + fs::{read_to_string, OpenOptions}, + io::{BufWriter, Write}, +}; use tokio::signal::unix::{signal, SignalKind}; -use lib::types::core::*; - -mod utils; - -struct RawMode; -impl RawMode { - fn new() -> anyhow::Result { - enable_raw_mode()?; - Ok(RawMode) - } -} -impl Drop for RawMode { - fn drop(&mut self) { - match disable_raw_mode() { - Ok(_) => {} - Err(e) => { - println!("terminal: failed to disable raw mode: {e:?}\r"); - } - } - } -} +pub mod utils; /* * terminal driver @@ -50,101 +32,27 @@ pub async fn terminal( mut print_rx: PrintReceiver, is_detached: bool, mut verbose_mode: u8, -) -> Result<()> { - let mut stdout = stdout(); - execute!( - stdout, - EnableBracketedPaste, - terminal::SetTitle(format!("{}", our.name)) - )?; - - let (mut win_cols, mut win_rows) = terminal::size().unwrap(); - // print initial splash screen, large if there's room, small otherwise - if win_cols >= 90 { - execute!( - stdout, - style::SetForegroundColor(style::Color::Magenta), - Print(format!( - r#" - .` - `@@,, ,* 888 d8P d8b 888 - `@%@@@, ,~-##` 888 d8P Y8P 888 - ~@@#@%#@@, ##### 888 d8P 888 - ~-%######@@@, ##### 888d88K 888 88888b. .d88b. .d88888 .d88b. - -%%#######@#####, 8888888b 888 888 "88b d88""88b d88" 888 d8P Y8b - ~^^%##########@ 888 Y88b 888 888 888 888 888 888 888 88888888 - >^#########@ 888 Y88b 888 888 888 Y88..88P Y88b 888 Y8b. - `>#######` 888 Y88b 888 888 888 "Y88P" "Y88888 "Y8888 - .>######% - /###%^#% {} ({}) - /##%@# ` runtime version {} - ./######` a general purpose sovereign cloud computer - /.^`.#^#^` - ` ,#`#`#, - ,/ /` ` - .*` - networking public key: {} - "#, - our.name, - if our.is_direct() { - "direct" - } else { - "indirect" - }, - version, - our.networking_key, - )), - style::ResetColor - )?; - } else { - execute!( - stdout, - style::SetForegroundColor(style::Color::Magenta), - Print(format!( - r#" - 888 d8P d8b 888 - 888 d8P Y8P 888 - 888 d8P 888 - 888d88K 888 88888b. .d88b. .d88888 .d88b. - 8888888b 888 888 "88b d88""88b d88" 888 d8P Y8b - 888 Y88b 888 888 888 888 888 888 888 88888888 - 888 Y88b 888 888 888 Y88..88P Y88b 888 Y8b. - 888 Y88b 888 888 888 "Y88P" "Y88888 "Y8888 - - {} ({}) - version {} - a general purpose sovereign cloud computer - net pubkey: {} - "#, - our.name, - if our.is_direct() { - "direct" - } else { - "indirect" - }, - version, - our.networking_key, - )), - style::ResetColor - )?; - } +) -> anyhow::Result<()> { + let (stdout, _maybe_raw_mode) = utils::startup(&our, version, is_detached)?; - let _raw_mode = if is_detached { - None - } else { - Some(RawMode::new()?) - }; + // mutable because we adjust them on window resize events + let (mut win_cols, mut win_rows) = + crossterm::terminal::size().expect("terminal: couldn't fetch size"); - let mut reader = EventStream::new(); let mut current_line = format!("{} > ", our.name); let prompt_len: usize = our.name.len() + 3; - let mut cursor_col: u16 = prompt_len.try_into().unwrap(); + let mut cursor_col: u16 = prompt_len as u16; let mut line_col: usize = cursor_col as usize; + let mut in_step_through: bool = false; + let mut search_mode: bool = false; let mut search_depth: usize = 0; + let mut logging_mode: bool = false; + // the terminal stores the most recent 1000 lines entered by user + // in history. TODO should make history size adjustable. let history_path = std::fs::canonicalize(&home_directory_path) .unwrap() .join(".terminal_history"); @@ -155,9 +63,11 @@ pub async fn terminal( .open(&history_path) .unwrap(); let history_writer = BufWriter::new(history_handle); - // TODO make adjustable max history length let mut command_history = utils::CommandHistory::new(1000, history, history_writer); + // if CTRL+L is used to turn on logging, all prints to terminal + // will also be written with their full timestamp to the .terminal_log file. + // logging mode is always off by default. TODO add a boot flag to change this. let log_path = std::fs::canonicalize(&home_directory_path) .unwrap() .join(".terminal_log"); @@ -186,21 +96,32 @@ pub async fn terminal( let mut sigusr2 = signal(SignalKind::user_defined2()).expect("terminal: failed to set up SIGUSR2 handler"); - loop { - let event = reader.next().fuse(); + // if the verbosity boot flag was **not** set to "full event loop", tell kernel + // the kernel will try and print all events by default so that booting with + // verbosity mode 3 guarantees all events from boot are shown. + if verbose_mode != 3 { + let _ = debug_event_loop.send(DebugCommand::ToggleEventLoop).await; + } + + let mut reader = EventStream::new(); + let mut stdout = stdout.lock(); + loop { tokio::select! { Some(printout) = print_rx.recv() => { let now = Local::now(); + // always write print to log if in logging mode if logging_mode { - let _ = writeln!(log_writer, "[{}] {}", now.to_rfc2822(), printout.content); + writeln!(log_writer, "[{}] {}", now.to_rfc2822(), printout.content)?; } + // skip writing print to terminal if it's of a greater + // verbosity level than our current mode if printout.verbosity > verbose_mode { continue; } - let mut stdout = stdout.lock(); execute!( stdout, + // print goes immediately above the dedicated input line at bottom cursor::MoveTo(0, win_rows - 1), terminal::Clear(ClearType::CurrentLine), Print(format!("{} {:02}:{:02} ", @@ -208,41 +129,45 @@ pub async fn terminal( now.hour(), now.minute(), )), - )?; - let color = match printout.verbosity { + style::SetForegroundColor(match printout.verbosity { 0 => style::Color::Reset, 1 => style::Color::Green, 2 => style::Color::Magenta, _ => style::Color::Red, - }; + }), + )?; for line in printout.content.lines() { execute!( stdout, - style::SetForegroundColor(color), Print(format!("{}\r\n", line)), - style::ResetColor, )?; } + // reset color and re-display the current input line + // re-place cursor where user had it at input line execute!( stdout, + style::ResetColor, cursor::MoveTo(0, win_rows), Print(utils::truncate_in_place(¤t_line, prompt_len, win_cols, (line_col, cursor_col))), cursor::MoveTo(cursor_col, win_rows), )?; } - Some(Ok(event)) = event => { - let mut stdout = stdout.lock(); + Some(Ok(event)) = reader.next().fuse() => { match event { - // resize is super annoying because this event trigger often + // + // RESIZE: resize is super annoying because this event trigger often // comes "too late" to stop terminal from messing with the // already-printed lines. TODO figure out the right way // to compensate for this cross-platform and do this in a // generally stable way. + // Event::Resize(width, height) => { win_cols = width; win_rows = height; }, - // handle pasting of text from outside + // + // PASTE: handle pasting of text from outside + // Event::Paste(pasted) => { // strip out control characters and newlines let pasted = pasted.chars().filter(|c| !c.is_control() && !c.is_ascii_control()).collect::(); @@ -256,7 +181,9 @@ pub async fn terminal( cursor::MoveTo(cursor_col, win_rows), )?; } + // // CTRL+C, CTRL+D: turn off the node + // Event::Key(KeyEvent { code: KeyCode::Char('c'), modifiers: KeyModifiers::CONTROL, @@ -267,10 +194,18 @@ pub async fn terminal( modifiers: KeyModifiers::CONTROL, .. }) => { - execute!(stdout, DisableBracketedPaste, terminal::SetTitle(""))?; + execute!( + stdout, + // print goes immediately above the dedicated input line at bottom + cursor::MoveTo(0, win_rows - 1), + terminal::Clear(ClearType::CurrentLine), + Print("exit code received"), + )?; break; }, + // // CTRL+V: toggle through verbosity modes + // Event::Key(KeyEvent { code: KeyCode::Char('v'), modifiers: KeyModifiers::CONTROL, @@ -294,26 +229,34 @@ pub async fn terminal( } } ).await; + if verbose_mode == 3 { + let _ = debug_event_loop.send(DebugCommand::ToggleEventLoop).await; + } }, + // // CTRL+J: toggle debug mode -- makes system-level event loop step-through - // CTRL+S: step through system-level event loop + // Event::Key(KeyEvent { code: KeyCode::Char('j'), modifiers: KeyModifiers::CONTROL, .. }) => { + let _ = debug_event_loop.send(DebugCommand::ToggleStepthrough).await; + in_step_through = !in_step_through; let _ = print_tx.send( Printout { verbosity: 0, content: match in_step_through { - true => "debug mode off".into(), - false => "debug mode on: use CTRL+S to step through events".into(), + false => "debug mode off".into(), + true => "debug mode on: use CTRL+S to step through events".into(), } } ).await; - let _ = debug_event_loop.send(DebugCommand::Toggle).await; - in_step_through = !in_step_through; + }, + // + // CTRL+S: step through system-level event loop (when in step-through mode) + // Event::Key(KeyEvent { code: KeyCode::Char('s'), modifiers: KeyModifiers::CONTROL, @@ -342,7 +285,6 @@ pub async fn terminal( }, // // UP / CTRL+P: go up one command in history - // DOWN / CTRL+N: go down one command in history // Event::Key(KeyEvent { code: KeyCode::Up, .. }) | Event::Key(KeyEvent { @@ -368,6 +310,9 @@ pub async fn terminal( Print(utils::truncate_rightward(¤t_line, prompt_len, win_cols)), )?; }, + // + // DOWN / CTRL+N: go down one command in history + // Event::Key(KeyEvent { code: KeyCode::Down, .. }) | Event::Key(KeyEvent { code: KeyCode::Char('n'), @@ -485,7 +430,7 @@ pub async fn terminal( )?; }, // - // handle keypress events + // KEY: handle keypress events // Event::Key(k) => { match k.code { @@ -668,6 +613,5 @@ pub async fn terminal( _ = sigusr2.recv() => return Err(anyhow::anyhow!("exiting due to SIGUSR2")), } } - execute!(stdout.lock(), DisableBracketedPaste, terminal::SetTitle(""))?; Ok(()) } diff --git a/kinode/src/terminal/utils.rs b/kinode/src/terminal/utils.rs index 59b4c2527..ba86ee2cb 100644 --- a/kinode/src/terminal/utils.rs +++ b/kinode/src/terminal/utils.rs @@ -1,6 +1,137 @@ -use std::collections::VecDeque; -use std::fs::File; -use std::io::{BufWriter, Write}; +use crossterm::terminal::{disable_raw_mode, enable_raw_mode}; +use lib::types::core::Identity; +use std::{ + collections::VecDeque, + fs::File, + io::{BufWriter, Stdout, Write}, +}; + +pub struct RawMode; +impl RawMode { + fn new() -> std::io::Result { + enable_raw_mode()?; + Ok(RawMode) + } +} +impl Drop for RawMode { + fn drop(&mut self) { + match disable_raw_mode() { + Ok(_) => {} + Err(e) => { + println!("terminal: failed to disable raw mode: {e:?}\r"); + } + } + } +} + +pub fn startup( + our: &Identity, + version: &str, + is_detached: bool, +) -> std::io::Result<(Stdout, Option)> { + let mut stdout = std::io::stdout(); + crossterm::execute!( + stdout, + crossterm::event::EnableBracketedPaste, + crossterm::terminal::SetTitle(format!("kinode {}", our.name)) + )?; + + let (win_cols, _) = crossterm::terminal::size().expect("terminal: couldn't fetch size"); + + // print initial splash screen, large if there's room, small otherwise + if win_cols >= 90 { + crossterm::execute!( + stdout, + crossterm::style::SetForegroundColor(crossterm::style::Color::Magenta), + crossterm::style::Print(format!( + r#" + .` + `@@,, ,* 888 d8P d8b 888 + `@%@@@, ,~-##` 888 d8P Y8P 888 + ~@@#@%#@@, ##### 888 d8P 888 + ~-%######@@@, ##### 888d88K 888 88888b. .d88b. .d88888 .d88b. + -%%#######@#####, 8888888b 888 888 "88b d88""88b d88" 888 d8P Y8b + ~^^%##########@ 888 Y88b 888 888 888 888 888 888 888 88888888 + >^#########@ 888 Y88b 888 888 888 Y88..88P Y88b 888 Y8b. + `>#######` 888 Y88b 888 888 888 "Y88P" "Y88888 "Y8888 + .>######% + /###%^#% {} ({}) + /##%@# ` runtime version {} + ./######` a general purpose sovereign cloud computer + /.^`.#^#^` + ` ,#`#`#, + ,/ /` ` + .*` + networking public key: {} + "#, + our.name, + if our.is_direct() { + "direct" + } else { + "indirect" + }, + version, + our.networking_key, + )), + crossterm::style::ResetColor + ) + .expect("terminal: couldn't print splash"); + } else { + crossterm::execute!( + stdout, + crossterm::style::SetForegroundColor(crossterm::style::Color::Magenta), + crossterm::style::Print(format!( + r#" + 888 d8P d8b 888 + 888 d8P Y8P 888 + 888 d8P 888 + 888d88K 888 88888b. .d88b. .d88888 .d88b. + 8888888b 888 888 "88b d88""88b d88" 888 d8P Y8b + 888 Y88b 888 888 888 888 888 888 888 88888888 + 888 Y88b 888 888 888 Y88..88P Y88b 888 Y8b. + 888 Y88b 888 888 888 "Y88P" "Y88888 "Y8888 + + {} ({}) + version {} + a general purpose sovereign cloud computer + net pubkey: {} + "#, + our.name, + if our.is_direct() { + "direct" + } else { + "indirect" + }, + version, + our.networking_key, + )), + crossterm::style::ResetColor + )?; + } + + Ok(( + stdout, + if is_detached { + None + } else { + Some(RawMode::new()?) + }, + )) +} + +pub fn cleanup(quit_msg: &str) { + let stdout = std::io::stdout(); + let mut stdout = stdout.lock(); + crossterm::execute!( + stdout, + crossterm::event::DisableBracketedPaste, + crossterm::terminal::SetTitle(""), + crossterm::style::SetForegroundColor(crossterm::style::Color::Red), + crossterm::style::Print(format!("\r\n{quit_msg}\r\n")), + crossterm::style::ResetColor, + ) + .expect("failed to clean up terminal visual state! your terminal window might be funky now"); +} #[derive(Debug)] pub struct CommandHistory { diff --git a/lib/build.rs b/lib/build.rs index 9f62fd1c0..5c36ac9bb 100644 --- a/lib/build.rs +++ b/lib/build.rs @@ -12,21 +12,21 @@ fn main() { let pwd = std::env::current_dir().expect("Failed to get current directory"); - let wit_file = pwd.join("wit-v0.7.0").join("kinode.wit"); + // let wit_file = pwd.join("wit-v0.7.0").join("kinode.wit"); - let rt = tokio::runtime::Runtime::new().unwrap(); - rt.block_on(async { - kit::build::download_file(KINODE_WIT_0_7_0_URL, &wit_file) - .await - .expect("Failed to download WIT 0.7"); - }); + // let rt = tokio::runtime::Runtime::new().unwrap(); + // rt.block_on(async { + // kit::build::download_file(KINODE_WIT_0_7_0_URL, &wit_file) + // .await + // .expect("Failed to download WIT 0.7"); + // }); - let wit_file = pwd.join("wit-v0.8.0").join("kinode.wit"); + // let wit_file = pwd.join("wit-v0.8.0").join("kinode.wit"); - let rt = tokio::runtime::Runtime::new().unwrap(); - rt.block_on(async { - kit::build::download_file(KINODE_WIT_0_8_0_URL, &wit_file) - .await - .expect("Failed to download WIT 0.8"); - }) + // let rt = tokio::runtime::Runtime::new().unwrap(); + // rt.block_on(async { + // kit::build::download_file(KINODE_WIT_0_8_0_URL, &wit_file) + // .await + // .expect("Failed to download WIT 0.8"); + // }) } diff --git a/lib/src/core.rs b/lib/src/core.rs index 3f8ce5170..a675e778f 100644 --- a/lib/src/core.rs +++ b/lib/src/core.rs @@ -1180,8 +1180,9 @@ pub type Rsvp = Option
; #[derive(Debug, Serialize, Deserialize)] pub enum DebugCommand { - Toggle, + ToggleStepthrough, Step, + ToggleEventLoop, } /// IPC format for requests sent to kernel runtime module From e0fc429817012fabda2fff466ae22baf61d9045e Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Thu, 13 Jun 2024 18:23:56 -0600 Subject: [PATCH 10/53] WIP: terminal: remove unwraps, more comments --- kinode/src/terminal/mod.rs | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/kinode/src/terminal/mod.rs b/kinode/src/terminal/mod.rs index 33881ebdf..6322a8b17 100644 --- a/kinode/src/terminal/mod.rs +++ b/kinode/src/terminal/mod.rs @@ -54,14 +54,14 @@ pub async fn terminal( // the terminal stores the most recent 1000 lines entered by user // in history. TODO should make history size adjustable. let history_path = std::fs::canonicalize(&home_directory_path) - .unwrap() + .expect("terminal: could not get path for .terminal_history file") .join(".terminal_history"); let history = read_to_string(&history_path).unwrap_or_default(); let history_handle = OpenOptions::new() .append(true) .create(true) .open(&history_path) - .unwrap(); + .expect("terminal: could not open/create .terminal_history"); let history_writer = BufWriter::new(history_handle); let mut command_history = utils::CommandHistory::new(1000, history, history_writer); @@ -69,13 +69,13 @@ pub async fn terminal( // will also be written with their full timestamp to the .terminal_log file. // logging mode is always off by default. TODO add a boot flag to change this. let log_path = std::fs::canonicalize(&home_directory_path) - .unwrap() + .expect("terminal: could not get path for .terminal_log file") .join(".terminal_log"); let log_handle = OpenOptions::new() .append(true) .create(true) .open(&log_path) - .unwrap(); + .expect("terminal: could not open/create .terminal_log"); let mut log_writer = BufWriter::new(log_handle); // use to trigger cleanup if receive signal to kill process @@ -299,6 +299,7 @@ pub async fn terminal( line_col = current_line.len(); }, None => { + // the "no-no" ding print!("\x07"); }, } @@ -326,6 +327,7 @@ pub async fn terminal( line_col = current_line.len(); }, None => { + // the "no-no" ding print!("\x07"); }, } @@ -346,7 +348,7 @@ pub async fn terminal( .. }) => { line_col = prompt_len; - cursor_col = prompt_len.try_into().unwrap(); + cursor_col = prompt_len as u16; execute!( stdout, cursor::MoveTo(0, win_rows), @@ -434,6 +436,9 @@ pub async fn terminal( // Event::Key(k) => { match k.code { + // + // CHAR: write a single character + // KeyCode::Char(c) => { current_line.insert(line_col, c); if cursor_col < win_cols { @@ -466,6 +471,9 @@ pub async fn terminal( cursor::MoveTo(cursor_col, win_rows), )?; }, + // + // BACKSPACE or DELETE: delete a single character at cursor + // KeyCode::Backspace | KeyCode::Delete => { if line_col == prompt_len { continue; @@ -501,6 +509,9 @@ pub async fn terminal( cursor::MoveTo(cursor_col, win_rows), )?; }, + // + // LEFT: move cursor one spot left + // KeyCode::Left => { if cursor_col as usize == prompt_len { if line_col == prompt_len { @@ -526,6 +537,9 @@ pub async fn terminal( line_col -= 1; } }, + // + // RIGHT: move cursor one spot right + // KeyCode::Right => { if line_col == current_line.len() { // at the very end of the current typed line @@ -549,6 +563,9 @@ pub async fn terminal( )?; } }, + // + // ENTER: send current input to terminal process, clearing input line + // KeyCode::Enter => { // if we were in search mode, pull command from that let command = if !search_mode { @@ -572,7 +589,7 @@ pub async fn terminal( search_depth = 0; current_line = next; command_history.add(command.clone()); - cursor_col = prompt_len.try_into().unwrap(); + cursor_col = prompt_len as u16; line_col = prompt_len; event_loop.send( KernelMessage { @@ -597,10 +614,14 @@ pub async fn terminal( } ).await.expect("terminal: couldn't execute command!"); }, - _ => {}, + _ => { + // some keycode we don't care about, yet + }, } }, - _ => {}, + _ => { + // some terminal event we don't care about, yet + }, } } _ = sigalrm.recv() => return Err(anyhow::anyhow!("exiting due to SIGALRM")), From ac49747a52f0f617e0d781f7f395c2293691cb8e Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Fri, 14 Jun 2024 01:22:30 -0400 Subject: [PATCH 11/53] bring back build.rs --- lib/build.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/build.rs b/lib/build.rs index 5c36ac9bb..9f62fd1c0 100644 --- a/lib/build.rs +++ b/lib/build.rs @@ -12,21 +12,21 @@ fn main() { let pwd = std::env::current_dir().expect("Failed to get current directory"); - // let wit_file = pwd.join("wit-v0.7.0").join("kinode.wit"); + let wit_file = pwd.join("wit-v0.7.0").join("kinode.wit"); - // let rt = tokio::runtime::Runtime::new().unwrap(); - // rt.block_on(async { - // kit::build::download_file(KINODE_WIT_0_7_0_URL, &wit_file) - // .await - // .expect("Failed to download WIT 0.7"); - // }); + let rt = tokio::runtime::Runtime::new().unwrap(); + rt.block_on(async { + kit::build::download_file(KINODE_WIT_0_7_0_URL, &wit_file) + .await + .expect("Failed to download WIT 0.7"); + }); - // let wit_file = pwd.join("wit-v0.8.0").join("kinode.wit"); + let wit_file = pwd.join("wit-v0.8.0").join("kinode.wit"); - // let rt = tokio::runtime::Runtime::new().unwrap(); - // rt.block_on(async { - // kit::build::download_file(KINODE_WIT_0_8_0_URL, &wit_file) - // .await - // .expect("Failed to download WIT 0.8"); - // }) + let rt = tokio::runtime::Runtime::new().unwrap(); + rt.block_on(async { + kit::build::download_file(KINODE_WIT_0_8_0_URL, &wit_file) + .await + .expect("Failed to download WIT 0.8"); + }) } From 7c00996b7800b6c889f57fbaa4df65038f6b45a3 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Fri, 14 Jun 2024 01:44:13 -0400 Subject: [PATCH 12/53] FIX: correctly allow indirect node to boot that's been updated onchain to be indirect after having been booted as direct in the past. also fix search in terminal. --- kinode/src/main.rs | 18 ++++++------------ kinode/src/register.rs | 20 ++++++++++++++++++-- kinode/src/terminal/mod.rs | 15 ++++++++++----- kinode/src/terminal/utils.rs | 3 +++ 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/kinode/src/main.rs b/kinode/src/main.rs index 204e4baa9..ac4a4b671 100644 --- a/kinode/src/main.rs +++ b/kinode/src/main.rs @@ -746,12 +746,9 @@ async fn serve_register_fe( } }; - tokio::fs::write( - format!("{}/.keys", home_directory_path), - encoded_keyfile.clone(), - ) - .await - .unwrap(); + tokio::fs::write(format!("{}/.keys", home_directory_path), &encoded_keyfile) + .await + .unwrap(); let _ = kill_tx.send(true); @@ -822,12 +819,9 @@ async fn login_with_password( .await .expect("information used to boot does not match information onchain"); - tokio::fs::write( - format!("{}/.keys", home_directory_path), - disk_keyfile.clone(), - ) - .await - .unwrap(); + tokio::fs::write(format!("{}/.keys", home_directory_path), &disk_keyfile) + .await + .unwrap(); (our, disk_keyfile, k) } diff --git a/kinode/src/register.rs b/kinode/src/register.rs index 863a02998..db512a6e0 100644 --- a/kinode/src/register.rs +++ b/kinode/src/register.rs @@ -36,6 +36,7 @@ sol! { function key(bytes32) external view returns (bytes32); function nodes(bytes32) external view returns (address, uint96); function ip(bytes32) external view returns (uint128, uint16, uint16, uint16, uint16); + function routers(bytes32) external view returns (bytes32[]); } /// Serve the registration page and receive POSTs and PUTs from it @@ -702,6 +703,7 @@ pub async fn assign_routing( let namehash = FixedBytes::<32>::from_slice(&keygen::namehash(&our.name)); let ip_call = ipCall { _0: namehash }.abi_encode(); let key_call = keyCall { _0: namehash }.abi_encode(); + let router_call = routersCall { _0: namehash }.abi_encode(); let tx_input = TransactionInput::new(Bytes::from(ip_call)); let tx = TransactionRequest::default() .to(kns_address) @@ -731,6 +733,18 @@ pub async fn assign_routing( )); } + let router_tx_input = TransactionInput::new(Bytes::from(router_call)); + let router_tx = TransactionRequest::default() + .to(kns_address) + .input(router_tx_input); + + let Ok(routers) = provider.call(&router_tx).await else { + return Err(anyhow::anyhow!("Failed to fetch node routers from PKI")); + }; + let Ok(routers) = >>::abi_decode(&routers, false) else { + return Err(anyhow::anyhow!("Failed to decode node routers from PKI")); + }; + let node_ip = format!( "{}.{}.{}.{}", (ip >> 24) & 0xFF, @@ -739,6 +753,10 @@ pub async fn assign_routing( ip & 0xFF ); + if !routers.is_empty() { + // indirect node + return Ok(()); + } if node_ip != *"0.0.0.0" && (ws != 0 || tcp != 0) { // direct node let mut ports = std::collections::BTreeMap::new(); @@ -763,8 +781,6 @@ pub async fn assign_routing( ports.insert("tcp".to_string(), tcp); } our.routing = NodeRouting::Direct { ip: node_ip, ports }; - } else { - // indirect node } Ok(()) } diff --git a/kinode/src/terminal/mod.rs b/kinode/src/terminal/mod.rs index 6322a8b17..68aeadc4e 100644 --- a/kinode/src/terminal/mod.rs +++ b/kinode/src/terminal/mod.rs @@ -386,9 +386,6 @@ pub async fn terminal( } search_mode = true; let search_query = ¤t_line[prompt_len..]; - if search_query.is_empty() { - continue; - } if let Some(result) = command_history.search(search_query, search_depth) { let result_underlined = utils::underline(result, search_query); execute!( @@ -407,7 +404,11 @@ pub async fn terminal( stdout, cursor::MoveTo(0, win_rows), terminal::Clear(ClearType::CurrentLine), - Print(utils::truncate_in_place(¤t_line, prompt_len, win_cols, (line_col, cursor_col))), + Print(utils::truncate_in_place( + &format!("{} * {}", our.name, ¤t_line[prompt_len..]), + prompt_len, + win_cols, + (line_col, cursor_col))), cursor::MoveTo(cursor_col, win_rows), )?; } @@ -427,7 +428,11 @@ pub async fn terminal( stdout, cursor::MoveTo(0, win_rows), terminal::Clear(ClearType::CurrentLine), - Print(utils::truncate_in_place(¤t_line, prompt_len, win_cols, (line_col, cursor_col))), + Print(utils::truncate_in_place( + &format!("{} > {}", our.name, ¤t_line[prompt_len..]), + prompt_len, + win_cols, + (line_col, cursor_col))), cursor::MoveTo(cursor_col, win_rows), )?; }, diff --git a/kinode/src/terminal/utils.rs b/kinode/src/terminal/utils.rs index ba86ee2cb..9b4de7b80 100644 --- a/kinode/src/terminal/utils.rs +++ b/kinode/src/terminal/utils.rs @@ -201,6 +201,9 @@ impl CommandHistory { /// yes this is O(n) to provide desired ordering, can revisit if slow pub fn search(&mut self, find: &str, depth: usize) -> Option<&str> { let mut skips = 0; + if find.is_empty() { + return None; + } // if there is at least one match, and we've skipped past it, return oldest match let mut last_match: Option<&str> = None; for line in self.lines.iter() { From 82691b3157ecf8315141149c09b4786319ba39ec Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Fri, 14 Jun 2024 01:56:42 -0400 Subject: [PATCH 13/53] WIP: make search better (needs more work!) --- kinode/src/terminal/mod.rs | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/kinode/src/terminal/mod.rs b/kinode/src/terminal/mod.rs index 68aeadc4e..705f4863d 100644 --- a/kinode/src/terminal/mod.rs +++ b/kinode/src/terminal/mod.rs @@ -405,7 +405,7 @@ pub async fn terminal( cursor::MoveTo(0, win_rows), terminal::Clear(ClearType::CurrentLine), Print(utils::truncate_in_place( - &format!("{} * {}", our.name, ¤t_line[prompt_len..]), + &format!("{} * {}: no results", our.name, ¤t_line[prompt_len..]), prompt_len, win_cols, (line_col, cursor_col))), @@ -465,8 +465,20 @@ pub async fn terminal( (line_col, cursor_col))), cursor::MoveTo(cursor_col, win_rows), )?; - continue; + } else { + execute!( + stdout, + cursor::MoveTo(0, win_rows), + terminal::Clear(ClearType::CurrentLine), + Print(utils::truncate_in_place( + &format!("{} * {}: no results", our.name, ¤t_line[prompt_len..]), + prompt_len, + win_cols, + (line_col, cursor_col))), + cursor::MoveTo(cursor_col, win_rows), + )?; } + continue; } execute!( stdout, @@ -503,8 +515,20 @@ pub async fn terminal( (line_col, cursor_col))), cursor::MoveTo(cursor_col, win_rows), )?; - continue; + } else { + execute!( + stdout, + cursor::MoveTo(0, win_rows), + terminal::Clear(ClearType::CurrentLine), + Print(utils::truncate_in_place( + &format!("{} * {}: no results", our.name, ¤t_line[prompt_len..]), + prompt_len, + win_cols, + (line_col, cursor_col))), + cursor::MoveTo(cursor_col, win_rows), + )?; } + continue; } execute!( stdout, @@ -579,7 +603,7 @@ pub async fn terminal( command_history.search( ¤t_line[prompt_len..], search_depth - ).unwrap_or(¤t_line[prompt_len..]).to_string() + ).unwrap_or_default().to_string() }; let next = format!("{} > ", our.name); execute!( From b71ba077370dd74c3e10680d9603f4e5550e17d0 Mon Sep 17 00:00:00 2001 From: Tobias Merkle Date: Fri, 14 Jun 2024 14:33:01 -0400 Subject: [PATCH 14/53] allow wider widgets on smaller screens --- .../pkg/ui/assets/{index-emIdaXB4.js => index-CTL7geHV.js} | 2 +- kinode/packages/homepage/pkg/ui/index.html | 2 +- kinode/packages/homepage/ui/dist/index.html | 2 +- kinode/packages/homepage/ui/src/components/Widget.tsx | 4 +++- 4 files changed, 6 insertions(+), 4 deletions(-) rename kinode/packages/homepage/pkg/ui/assets/{index-emIdaXB4.js => index-CTL7geHV.js} (98%) diff --git a/kinode/packages/homepage/pkg/ui/assets/index-emIdaXB4.js b/kinode/packages/homepage/pkg/ui/assets/index-CTL7geHV.js similarity index 98% rename from kinode/packages/homepage/pkg/ui/assets/index-emIdaXB4.js rename to kinode/packages/homepage/pkg/ui/assets/index-CTL7geHV.js index 1c6aeb6be..6c617b22b 100644 --- a/kinode/packages/homepage/pkg/ui/assets/index-emIdaXB4.js +++ b/kinode/packages/homepage/pkg/ui/assets/index-CTL7geHV.js @@ -124,7 +124,7 @@ Error generating stack: `+o.message+` -moz-user-select: none; -ms-user-select: none; overflow-anchor: none; - `}},l=[n,r,i,o];return{always:Sn(l,"always"),resting:Sn(l,"resting"),dragging:Sn(l,"dragging"),dropAnimating:Sn(l,"dropAnimating"),userCancel:Sn(l,"userCancel")}},_e=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u"?E.useLayoutEffect:E.useEffect,ya=function(){var t=document.querySelector("head");return t||I(),t},Kd=function(t){var r=document.createElement("style");return t&&r.setAttribute("nonce",t),r.type="text/css",r};function w2(e,t){var r=$(function(){return y2(e)},[e]),n=E.useRef(null),i=E.useRef(null),o=A(ce(function(d){var c=i.current;c||I(),c.textContent=d}),[]),l=A(function(d){var c=n.current;c||I(),c.textContent=d},[]);_e(function(){!n.current&&!i.current||I();var d=Kd(t),c=Kd(t);return n.current=d,i.current=c,d.setAttribute(en+"-always",e),c.setAttribute(en+"-dynamic",e),ya().appendChild(d),ya().appendChild(c),l(r.always),o(r.resting),function(){var p=function(y){var w=y.current;w||I(),ya().removeChild(w),y.current=null};p(n),p(i)}},[t,l,o,r.always,r.resting,e]);var a=A(function(){return o(r.dragging)},[o,r.dragging]),u=A(function(d){if(d==="DROP"){o(r.dropAnimating);return}o(r.userCancel)},[o,r.dropAnimating,r.userCancel]),s=A(function(){i.current&&o(r.resting)},[o,r.resting]),f=$(function(){return{dragging:a,dropping:u,resting:s}},[a,u,s]);return f}var jg=function(e){return e&&e.ownerDocument?e.ownerDocument.defaultView:window};function Dl(e){return e instanceof jg(e).HTMLElement}function S2(e,t){var r="["+tn.contextId+'="'+e+'"]',n=lg(document.querySelectorAll(r));if(!n.length)return null;var i=or(n,function(o){return o.getAttribute(tn.draggableId)===t});return!i||!Dl(i)?null:i}function x2(e){var t=E.useRef({}),r=E.useRef(null),n=E.useRef(null),i=E.useRef(!1),o=A(function(c,p){var m={id:c,focus:p};return t.current[c]=m,function(){var w=t.current,g=w[c];g!==m&&delete w[c]}},[]),l=A(function(c){var p=S2(e,c);p&&p!==document.activeElement&&p.focus()},[e]),a=A(function(c,p){r.current===c&&(r.current=p)},[]),u=A(function(){n.current||i.current&&(n.current=requestAnimationFrame(function(){n.current=null;var c=r.current;c&&l(c)}))},[l]),s=A(function(c){r.current=null;var p=document.activeElement;p&&p.getAttribute(tn.draggableId)===c&&(r.current=c)},[]);_e(function(){return i.current=!0,function(){i.current=!1;var c=n.current;c&&cancelAnimationFrame(c)}},[]);var f=$(function(){return{register:o,tryRecordFocus:s,tryRestoreFocusRecorded:u,tryShiftRecord:a}},[o,s,u,a]);return f}function E2(){var e={draggables:{},droppables:{}},t=[];function r(d){return t.push(d),function(){var p=t.indexOf(d);p!==-1&&t.splice(p,1)}}function n(d){t.length&&t.forEach(function(c){return c(d)})}function i(d){return e.draggables[d]||null}function o(d){var c=i(d);return c||I(),c}var l={register:function(c){e.draggables[c.descriptor.id]=c,n({type:"ADDITION",value:c})},update:function(c,p){var m=e.draggables[p.descriptor.id];m&&m.uniqueId===c.uniqueId&&(delete e.draggables[p.descriptor.id],e.draggables[c.descriptor.id]=c)},unregister:function(c){var p=c.descriptor.id,m=i(p);m&&c.uniqueId===m.uniqueId&&(delete e.draggables[p],n({type:"REMOVAL",value:c}))},getById:o,findById:i,exists:function(c){return!!i(c)},getAllByType:function(c){return $o(e.draggables).filter(function(p){return p.descriptor.type===c})}};function a(d){return e.droppables[d]||null}function u(d){var c=a(d);return c||I(),c}var s={register:function(c){e.droppables[c.descriptor.id]=c},unregister:function(c){var p=a(c.descriptor.id);p&&c.uniqueId===p.uniqueId&&delete e.droppables[c.descriptor.id]},getById:u,findById:a,exists:function(c){return!!a(c)},getAllByType:function(c){return $o(e.droppables).filter(function(p){return p.descriptor.type===c})}};function f(){e.draggables={},e.droppables={},t.length=0}return{draggable:l,droppable:s,subscribe:r,clean:f}}function C2(){var e=$(E2,[]);return E.useEffect(function(){return function(){requestAnimationFrame(e.clean)}},[e]),e}var qs=z.createContext(null),_o=function(){var e=document.body;return e||I(),e},b2={position:"absolute",width:"1px",height:"1px",margin:"-1px",border:"0",padding:"0",overflow:"hidden",clip:"rect(0 0 0 0)","clip-path":"inset(100%)"},D2=function(t){return"rbd-announcement-"+t};function P2(e){var t=$(function(){return D2(e)},[e]),r=E.useRef(null);E.useEffect(function(){var o=document.createElement("div");return r.current=o,o.id=t,o.setAttribute("aria-live","assertive"),o.setAttribute("aria-atomic","true"),L(o.style,b2),_o().appendChild(o),function(){setTimeout(function(){var u=_o();u.contains(o)&&u.removeChild(o),o===r.current&&(r.current=null)})}},[t]);var n=A(function(i){var o=r.current;if(o){o.textContent=i;return}},[]);return n}var I2=0,N2={separator:"::"};function Qs(e,t){return t===void 0&&(t=N2),$(function(){return""+e+t.separator+I2++},[t.separator,e])}function O2(e){var t=e.contextId,r=e.uniqueId;return"rbd-hidden-text-"+t+"-"+r}function R2(e){var t=e.contextId,r=e.text,n=Qs("hidden-text",{separator:"-"}),i=$(function(){return O2({contextId:t,uniqueId:n})},[n,t]);return E.useEffect(function(){var l=document.createElement("div");return l.id=i,l.textContent=r,l.style.display="none",_o().appendChild(l),function(){var u=_o();u.contains(l)&&u.removeChild(l)}},[i,r]),i}var Pl=z.createContext(null);function zg(e){var t=E.useRef(e);return E.useEffect(function(){t.current=e}),t}function k2(){var e=null;function t(){return!!e}function r(l){return l===e}function n(l){e&&I();var a={abandon:l};return e=a,a}function i(){e||I(),e=null}function o(){e&&(e.abandon(),i())}return{isClaimed:t,isActive:r,claim:n,release:i,tryAbandon:o}}var T2=9,A2=13,Ks=27,$g=32,L2=33,M2=34,B2=35,F2=36,j2=37,z2=38,$2=39,U2=40,Gi,_2=(Gi={},Gi[A2]=!0,Gi[T2]=!0,Gi),Ug=function(e){_2[e.keyCode]&&e.preventDefault()},Il=function(){var e="visibilitychange";if(typeof document>"u")return e;var t=[e,"ms"+e,"webkit"+e,"moz"+e,"o"+e],r=or(t,function(n){return"on"+n in document});return r||e}(),_g=0,Yd=5;function W2(e,t){return Math.abs(t.x-e.x)>=Yd||Math.abs(t.y-e.y)>=Yd}var Xd={type:"IDLE"};function H2(e){var t=e.cancel,r=e.completed,n=e.getPhase,i=e.setPhase;return[{eventName:"mousemove",fn:function(l){var a=l.button,u=l.clientX,s=l.clientY;if(a===_g){var f={x:u,y:s},d=n();if(d.type==="DRAGGING"){l.preventDefault(),d.actions.move(f);return}d.type!=="PENDING"&&I();var c=d.point;if(W2(c,f)){l.preventDefault();var p=d.actions.fluidLift(f);i({type:"DRAGGING",actions:p})}}}},{eventName:"mouseup",fn:function(l){var a=n();if(a.type!=="DRAGGING"){t();return}l.preventDefault(),a.actions.drop({shouldBlockNextClick:!0}),r()}},{eventName:"mousedown",fn:function(l){n().type==="DRAGGING"&&l.preventDefault(),t()}},{eventName:"keydown",fn:function(l){var a=n();if(a.type==="PENDING"){t();return}if(l.keyCode===Ks){l.preventDefault(),t();return}Ug(l)}},{eventName:"resize",fn:t},{eventName:"scroll",options:{passive:!0,capture:!1},fn:function(){n().type==="PENDING"&&t()}},{eventName:"webkitmouseforcedown",fn:function(l){var a=n();if(a.type==="IDLE"&&I(),a.actions.shouldRespectForcePress()){t();return}l.preventDefault()}},{eventName:Il,fn:t}]}function V2(e){var t=E.useRef(Xd),r=E.useRef(Qt),n=$(function(){return{eventName:"mousedown",fn:function(d){if(!d.defaultPrevented&&d.button===_g&&!(d.ctrlKey||d.metaKey||d.shiftKey||d.altKey)){var c=e.findClosestDraggableId(d);if(c){var p=e.tryGetLock(c,l,{sourceEvent:d});if(p){d.preventDefault();var m={x:d.clientX,y:d.clientY};r.current(),s(p,m)}}}}}},[e]),i=$(function(){return{eventName:"webkitmouseforcewillbegin",fn:function(d){if(!d.defaultPrevented){var c=e.findClosestDraggableId(d);if(c){var p=e.findOptionsForDraggable(c);p&&(p.shouldRespectForcePress||e.canGetLock(c)&&d.preventDefault())}}}}},[e]),o=A(function(){var d={passive:!1,capture:!0};r.current=et(window,[i,n],d)},[i,n]),l=A(function(){var f=t.current;f.type!=="IDLE"&&(t.current=Xd,r.current(),o())},[o]),a=A(function(){var f=t.current;l(),f.type==="DRAGGING"&&f.actions.cancel({shouldBlockNextClick:!0}),f.type==="PENDING"&&f.actions.abort()},[l]),u=A(function(){var d={capture:!0,passive:!1},c=H2({cancel:a,completed:l,getPhase:function(){return t.current},setPhase:function(m){t.current=m}});r.current=et(window,c,d)},[a,l]),s=A(function(d,c){t.current.type!=="IDLE"&&I(),t.current={type:"PENDING",point:c,actions:d},u()},[u]);_e(function(){return o(),function(){r.current()}},[o])}var Dr;function G2(){}var q2=(Dr={},Dr[M2]=!0,Dr[L2]=!0,Dr[F2]=!0,Dr[B2]=!0,Dr);function Q2(e,t){function r(){t(),e.cancel()}function n(){t(),e.drop()}return[{eventName:"keydown",fn:function(o){if(o.keyCode===Ks){o.preventDefault(),r();return}if(o.keyCode===$g){o.preventDefault(),n();return}if(o.keyCode===U2){o.preventDefault(),e.moveDown();return}if(o.keyCode===z2){o.preventDefault(),e.moveUp();return}if(o.keyCode===$2){o.preventDefault(),e.moveRight();return}if(o.keyCode===j2){o.preventDefault(),e.moveLeft();return}if(q2[o.keyCode]){o.preventDefault();return}Ug(o)}},{eventName:"mousedown",fn:r},{eventName:"mouseup",fn:r},{eventName:"click",fn:r},{eventName:"touchstart",fn:r},{eventName:"resize",fn:r},{eventName:"wheel",fn:r,options:{passive:!0}},{eventName:Il,fn:r}]}function K2(e){var t=E.useRef(G2),r=$(function(){return{eventName:"keydown",fn:function(o){if(o.defaultPrevented||o.keyCode!==$g)return;var l=e.findClosestDraggableId(o);if(!l)return;var a=e.tryGetLock(l,f,{sourceEvent:o});if(!a)return;o.preventDefault();var u=!0,s=a.snapLift();t.current();function f(){u||I(),u=!1,t.current(),n()}t.current=et(window,Q2(s,f),{capture:!0,passive:!1})}}},[e]),n=A(function(){var o={passive:!1,capture:!0};t.current=et(window,[r],o)},[r]);_e(function(){return n(),function(){t.current()}},[n])}var wa={type:"IDLE"},Y2=120,X2=.15;function Z2(e){var t=e.cancel,r=e.getPhase;return[{eventName:"orientationchange",fn:t},{eventName:"resize",fn:t},{eventName:"contextmenu",fn:function(i){i.preventDefault()}},{eventName:"keydown",fn:function(i){if(r().type!=="DRAGGING"){t();return}i.keyCode===Ks&&i.preventDefault(),t()}},{eventName:Il,fn:t}]}function J2(e){var t=e.cancel,r=e.completed,n=e.getPhase;return[{eventName:"touchmove",options:{capture:!1},fn:function(o){var l=n();if(l.type!=="DRAGGING"){t();return}l.hasMoved=!0;var a=o.touches[0],u=a.clientX,s=a.clientY,f={x:u,y:s};o.preventDefault(),l.actions.move(f)}},{eventName:"touchend",fn:function(o){var l=n();if(l.type!=="DRAGGING"){t();return}o.preventDefault(),l.actions.drop({shouldBlockNextClick:!0}),r()}},{eventName:"touchcancel",fn:function(o){if(n().type!=="DRAGGING"){t();return}o.preventDefault(),t()}},{eventName:"touchforcechange",fn:function(o){var l=n();l.type==="IDLE"&&I();var a=o.touches[0];if(a){var u=a.force>=X2;if(u){var s=l.actions.shouldRespectForcePress();if(l.type==="PENDING"){s&&t();return}if(s){if(l.hasMoved){o.preventDefault();return}t();return}o.preventDefault()}}}},{eventName:Il,fn:t}]}function ex(e){var t=E.useRef(wa),r=E.useRef(Qt),n=A(function(){return t.current},[]),i=A(function(p){t.current=p},[]),o=$(function(){return{eventName:"touchstart",fn:function(p){if(!p.defaultPrevented){var m=e.findClosestDraggableId(p);if(m){var y=e.tryGetLock(m,a,{sourceEvent:p});if(y){var w=p.touches[0],g=w.clientX,v=w.clientY,h={x:g,y:v};r.current(),d(y,h)}}}}}},[e]),l=A(function(){var p={capture:!0,passive:!1};r.current=et(window,[o],p)},[o]),a=A(function(){var c=t.current;c.type!=="IDLE"&&(c.type==="PENDING"&&clearTimeout(c.longPressTimerId),i(wa),r.current(),l())},[l,i]),u=A(function(){var c=t.current;a(),c.type==="DRAGGING"&&c.actions.cancel({shouldBlockNextClick:!0}),c.type==="PENDING"&&c.actions.abort()},[a]),s=A(function(){var p={capture:!0,passive:!1},m={cancel:u,completed:a,getPhase:n},y=et(window,J2(m),p),w=et(window,Z2(m),p);r.current=function(){y(),w()}},[u,n,a]),f=A(function(){var p=n();p.type!=="PENDING"&&I();var m=p.actions.fluidLift(p.point);i({type:"DRAGGING",actions:m,hasMoved:!1})},[n,i]),d=A(function(p,m){n().type!=="IDLE"&&I();var y=setTimeout(f,Y2);i({type:"PENDING",point:m,actions:p,longPressTimerId:y}),s()},[s,n,i,f]);_e(function(){return l(),function(){r.current();var m=n();m.type==="PENDING"&&(clearTimeout(m.longPressTimerId),i(wa))}},[n,l,i]),_e(function(){var p=et(window,[{eventName:"touchmove",fn:function(){},options:{capture:!1,passive:!1}}]);return p},[])}var tx={input:!0,button:!0,textarea:!0,select:!0,option:!0,optgroup:!0,video:!0,audio:!0};function Wg(e,t){if(t==null)return!1;var r=!!tx[t.tagName.toLowerCase()];if(r)return!0;var n=t.getAttribute("contenteditable");return n==="true"||n===""?!0:t===e?!1:Wg(e,t.parentElement)}function rx(e,t){var r=t.target;return Dl(r)?Wg(e,r):!1}var nx=function(e){return st(e.getBoundingClientRect()).center};function ix(e){return e instanceof jg(e).Element}var ox=function(){var e="matches";if(typeof document>"u")return e;var t=[e,"msMatchesSelector","webkitMatchesSelector"],r=or(t,function(n){return n in Element.prototype});return r||e}();function Hg(e,t){return e==null?null:e[ox](t)?e:Hg(e.parentElement,t)}function lx(e,t){return e.closest?e.closest(t):Hg(e,t)}function ax(e){return"["+tn.contextId+'="'+e+'"]'}function ux(e,t){var r=t.target;if(!ix(r))return null;var n=ax(e),i=lx(r,n);return!i||!Dl(i)?null:i}function sx(e,t){var r=ux(e,t);return r?r.getAttribute(tn.draggableId):null}function cx(e,t){var r="["+Su.contextId+'="'+e+'"]',n=lg(document.querySelectorAll(r)),i=or(n,function(o){return o.getAttribute(Su.id)===t});return!i||!Dl(i)?null:i}function dx(e){e.preventDefault()}function qi(e){var t=e.expected,r=e.phase,n=e.isLockActive;return e.shouldWarn,!(!n()||t!==r)}function Vg(e){var t=e.lockAPI,r=e.store,n=e.registry,i=e.draggableId;if(t.isClaimed())return!1;var o=n.draggable.findById(i);return!(!o||!o.options.isEnabled||!Lg(r.getState(),i))}function fx(e){var t=e.lockAPI,r=e.contextId,n=e.store,i=e.registry,o=e.draggableId,l=e.forceSensorStop,a=e.sourceEvent,u=Vg({lockAPI:t,store:n,registry:i,draggableId:o});if(!u)return null;var s=i.draggable.getById(o),f=cx(r,s.descriptor.id);if(!f||a&&!s.options.canDragInteractiveElements&&rx(f,a))return null;var d=t.claim(l||Qt),c="PRE_DRAG";function p(){return s.options.shouldRespectForcePress}function m(){return t.isActive(d)}function y(C,P){qi({expected:C,phase:c,isLockActive:m,shouldWarn:!0})&&n.dispatch(P())}var w=y.bind(null,"DRAGGING");function g(C){function P(){t.release(),c="COMPLETED"}c!=="PRE_DRAG"&&(P(),c!=="PRE_DRAG"&&I()),n.dispatch(oS(C.liftActionArgs)),c="DRAGGING";function N(T,k){if(k===void 0&&(k={shouldBlockNextClick:!1}),C.cleanup(),k.shouldBlockNextClick){var F=et(window,[{eventName:"click",fn:dx,options:{once:!0,passive:!1,capture:!0}}]);setTimeout(F)}P(),n.dispatch(Ig({reason:T}))}return L({isActive:function(){return qi({expected:"DRAGGING",phase:c,isLockActive:m,shouldWarn:!1})},shouldRespectForcePress:p,drop:function(k){return N("DROP",k)},cancel:function(k){return N("CANCEL",k)}},C.actions)}function v(C){var P=ni(function(T){w(function(){return Pg({client:T})})}),N=g({liftActionArgs:{id:o,clientSelection:C,movementMode:"FLUID"},cleanup:function(){return P.cancel()},actions:{move:P}});return L({},N,{move:P})}function h(){var C={moveUp:function(){return w(vS)},moveRight:function(){return w(mS)},moveDown:function(){return w(gS)},moveLeft:function(){return w(hS)}};return g({liftActionArgs:{id:o,clientSelection:nx(f),movementMode:"SNAP"},cleanup:Qt,actions:C})}function S(){var C=qi({expected:"PRE_DRAG",phase:c,isLockActive:m,shouldWarn:!0});C&&t.release()}var x={isActive:function(){return qi({expected:"PRE_DRAG",phase:c,isLockActive:m,shouldWarn:!1})},shouldRespectForcePress:p,fluidLift:v,snapLift:h,abort:S};return x}var px=[V2,K2,ex];function vx(e){var t=e.contextId,r=e.store,n=e.registry,i=e.customSensors,o=e.enableDefaultSensors,l=[].concat(o?px:[],i||[]),a=E.useState(function(){return k2()})[0],u=A(function(v,h){v.isDragging&&!h.isDragging&&a.tryAbandon()},[a]);_e(function(){var v=r.getState(),h=r.subscribe(function(){var S=r.getState();u(v,S),v=S});return h},[a,r,u]),_e(function(){return a.tryAbandon},[a.tryAbandon]);for(var s=A(function(g){return Vg({lockAPI:a,registry:n,store:r,draggableId:g})},[a,n,r]),f=A(function(g,v,h){return fx({lockAPI:a,registry:n,contextId:t,store:r,draggableId:g,forceSensorStop:v,sourceEvent:h&&h.sourceEvent?h.sourceEvent:null})},[t,a,n,r]),d=A(function(g){return sx(t,g)},[t]),c=A(function(g){var v=n.draggable.findById(g);return v?v.options:null},[n.draggable]),p=A(function(){a.isClaimed()&&(a.tryAbandon(),r.getState().phase!=="IDLE"&&r.dispatch(zs()))},[a,r]),m=A(a.isClaimed,[a]),y=$(function(){return{canGetLock:s,tryGetLock:f,findClosestDraggableId:d,findOptionsForDraggable:c,tryReleaseLock:p,isLockClaimed:m}},[s,f,d,c,p,m]),w=0;w{const{apps:e}=ln(),{favoriteApps:t,setFavoriteApps:r}=vi(),[n,i]=E.useState([]);E.useEffect(()=>{let u=[];const s=Object.entries(t).filter(([c,{favorite:p}])=>p).map(([c,{order:p}])=>({...e.find(m=>m.package_name===c),order:p})).filter(c=>c),f=s.filter(c=>c.order!==void 0&&c.order!==null),d=s.filter(c=>c.order===void 0||c.order===null);for(let c=0;cc),d.forEach(c=>u.push(c)),i(u)},[e,t]);const o=ir(),l=(u,s,f)=>{const d=Array.from(u),[c]=d.splice(s,1);return d.splice(f,0,c),d},a=u=>{if(!u.destination)return;const f=l(n,u.source.index,u.destination.index).map(c=>c.package_name),d={...t};f.forEach((c,p)=>{d[c].order=p}),r(d),console.log({favoriteApps:t}),fetch(Pn("/order"),{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(f)}).catch(c=>console.error(c))};return b.jsx(wx,{onDragEnd:a,children:b.jsx(Xg,{droppableId:"droppable",direction:"horizontal",children:(u,s)=>b.jsxs("div",{ref:u.innerRef,...u.droppableProps,className:Te("flex-center flex-wrap border border-orange bg-orange/25 p-2 rounded !rounded-xl",{"gap-8":!o&&n.length>0,"gap-4":!o&&n.length===0,"mb-4":!o,"gap-4 mb-2":o,"flex-col":n.length===0}),children:[n.map(f=>b.jsx(rE,{draggableId:f.package_name,index:n.indexOf(f),children:(d,c)=>b.jsx("div",{ref:d.innerRef,...d.draggableProps,...d.dragHandleProps,children:b.jsx(Av,{app:f})})},f.package_name)),u.placeholder,n.length===0&&b.jsx("div",{children:"Favorite an app to pin it to your dock."})]})})})},sE=({expanded:e})=>{const{apps:t}=ln(),r=ir();return b.jsx("div",{className:Te("flex-center flex-wrap overflow-y-auto fixed h-screen w-screen backdrop-blur-md transition transition-all ease-in-out duration-500",{"top-[100vh]":!e,"top-0":e,"gap-4 p-8":r,"gap-8 p-16":!r}),children:t.length===0?b.jsx("div",{children:"Loading apps..."}):t.map(n=>b.jsx(Av,{app:n},n.package_name))})},cE=({package_name:e,widget:t,forceLarge:r})=>{var d,c,p,m,y;const{apps:n}=ln(),{widgetSettings:i,toggleWidgetVisibility:o}=vi(),[l,a]=E.useState(!1),u=ir(),s=r||((d=i[e])==null?void 0:d.size)==="large",f=!((c=i[e])!=null&&c.size)||((p=i[e])==null?void 0:p.size)==="small";return b.jsxs("div",{className:Te("self-stretch flex-col-center shadow-lg rounded-lg relative",{"max-w-1/2 min-w-1/2":s&&!u,"max-w-1/4 min-w-1/4":f&&!u,"w-full":u}),onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),children:[b.jsx("h6",{className:"flex-center my-2",children:((m=n.find(w=>w.package_name===e))==null?void 0:m.label)||e}),b.jsx("iframe",{srcDoc:t||"",className:"grow self-stretch","data-widget-code":t}),l&&b.jsx("button",{className:"absolute top-0 left-0 icon",onClick:()=>o(e),children:(y=i[e])!=null&&y.hide?b.jsx(E0,{}):b.jsx(x0,{})})]})},dE=()=>{const{apps:e}=ln(),{widgetSettings:t}=vi(),r=ir();return b.jsx("div",{className:Te("flex-center flex-wrap flex-grow self-stretch",{"gap-2 m-2":r,"gap-4 m-4":!r}),children:e.filter(n=>n.widget).map(({widget:n,package_name:i},o,l)=>{var a;return!((a=t[i])!=null&&a.hide)&&b.jsx(cE,{package_name:i,widget:n,forceLarge:l.length===1},i)})})},fE=({title:e,onClose:t,children:r})=>{const n=ir();return b.jsx("div",{className:"flex fixed top-0 left-0 w-full h-full bg-black bg-opacity-50 place-items-center place-content-center backdrop-blur-md",children:b.jsxs("div",{className:Te("flex flex-col rounded-lg bg-black py-4 shadow-lg max-h-screen overflow-y-auto",{"min-w-[500px] px-8 w-1/2":!n,"px-4 w-full":n}),children:[b.jsxs("div",{className:"flex",children:[b.jsx("h1",{className:"grow",children:e}),b.jsx("button",{className:"icon self-start",onClick:t,children:b.jsx(D0,{})})]}),r]})})},pE=()=>{const{apps:e,setShowWidgetsSettings:t}=ln(),{widgetSettings:r,toggleWidgetVisibility:n,setWidgetSize:i}=vi();return b.jsx(fE,{title:"Widget Settings",onClose:()=>t(!1),children:b.jsxs("div",{className:"flex-col-center gap-4 mt-4",children:[e.filter(o=>o.widget).map(({label:o,package_name:l})=>{var a,u,s,f;return b.jsxs("div",{className:"flex items-start bg-white/10 rounded p-2 self-stretch",children:[b.jsx("h4",{className:"mr-4 grow",children:o}),b.jsxs("div",{className:"flex flex-col gap-4 grow",children:[b.jsxs("div",{className:"flex-center gap-2",children:[b.jsx("span",{children:"Show widget"}),b.jsxs("div",{className:"flex relative grow",children:[b.jsx("input",{type:"checkbox",checked:!((a=r[l])!=null&&a.hide),onChange:()=>n(l),autoFocus:!0}),!((u=r[l])!=null&&u.hide)&&b.jsx("span",{onClick:()=>n(l),className:"checkmark",children:"✓"})]})]}),b.jsxs("div",{className:"flex-center gap-2",children:[b.jsx("span",{children:"Widget size"}),b.jsxs("div",{className:"flex-center grow",children:[b.jsx("button",{className:Te({clear:((s=r[l])==null?void 0:s.size)==="large"}),onClick:()=>i(l,"small"),children:"Small"}),b.jsx("button",{className:Te({clear:((f=r[l])==null?void 0:f.size)!=="large"}),onClick:()=>i(l,"large"),children:"Large"})]})]})]})]})}),b.jsx("button",{className:"clear",onClick:()=>window.location.href="/settings:settings:sys",children:"Looking for system settings?"})]})})},vE="/assets/valet-icon-COgctyxf.png";function gE(){const[e,t]=E.useState(""),[r,n]=E.useState(""),[i,o]=E.useState(!1),{setApps:l,isHosted:a,fetchHostedStatus:u,showWidgetsSettings:s,setShowWidgetsSettings:f}=ln(),d=ir(),c=()=>{Promise.all([fetch(Pn("/apps"),{credentials:"include"}).then(p=>p.json()).catch(()=>[]),fetch(Pn("/main:app_store:sys/apps"),{credentials:"include"}).then(p=>p.json()).catch(()=>[]),fetch(Pn("/version"),{credentials:"include"}).then(p=>p.text()).catch(()=>"")]).then(([p,m,y])=>{n(y);const w=p.map(g=>({...g,is_favorite:!1}));m.forEach(g=>{const v=w.findIndex(h=>h.package_name===g.package);v===-1?w.push({package_name:g.package,path:"",label:g.package,state:g.state,is_favorite:!1}):w[v]={...w[v],state:g.state}}),l(w);for(let g=0;g<5&&w.find(v=>v.package_name==="app_store"&&!v.base64_icon);g++)c()})};return E.useEffect(()=>{c()},[e]),E.useEffect(()=>{fetch(Pn("/our"),{credentials:"include"}).then(p=>p.text()).then(p=>{p.match(/^[a-zA-Z0-9\-\.]+\.[a-zA-Z]+$/)&&(t(p),u(p))})},[e]),b.jsxs("div",{className:Te("flex-col-center relative w-screen overflow-hidden special-bg-homepage min-h-screen",{}),children:[b.jsxs("h5",{className:Te("absolute flex gap-4 c",{"top-8 left-8 right-8":!d,"top-2 left-2 right-2":d}),children:[a&&b.jsx("img",{src:vE,className:"!w-12 !h-12 !p-1 button icon object-cover",onClick:()=>window.location.href="https://valet.kinode.org/"}),b.jsx("span",{children:e}),b.jsxs("span",{className:"bg-white/10 rounded p-1",children:["v",r]}),b.jsx("button",{className:"icon ml-auto",onClick:()=>f(!0),children:b.jsx(b0,{})})]}),d?b.jsxs("div",{className:"flex-center gap-4 p-8 mt-8 max-w-screen",children:[b.jsx(cd,{}),b.jsx(sd,{})]}):b.jsxs("div",{className:Te("flex-col-center mx-0 gap-4 mt-8 mb-4"),children:[b.jsx("h3",{className:"text-center",children:"Welcome to"}),b.jsx(sd,{}),b.jsx(cd,{})]}),b.jsx(uE,{}),b.jsx(dE,{}),b.jsxs("button",{className:Te("fixed alt clear flex-center self-center z-20",{"bottom-2 right-2":d,"bottom-8 right-8":!d}),onClick:()=>o(!i),children:[i?b.jsx(w0,{}):b.jsx(S0,{}),b.jsx("span",{className:"ml-2",children:i?"Collapse":"All apps"})]}),b.jsx(sE,{expanded:i}),s&&b.jsx(pE,{})]})}/** + `}},l=[n,r,i,o];return{always:Sn(l,"always"),resting:Sn(l,"resting"),dragging:Sn(l,"dragging"),dropAnimating:Sn(l,"dropAnimating"),userCancel:Sn(l,"userCancel")}},_e=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u"?E.useLayoutEffect:E.useEffect,ya=function(){var t=document.querySelector("head");return t||I(),t},Kd=function(t){var r=document.createElement("style");return t&&r.setAttribute("nonce",t),r.type="text/css",r};function w2(e,t){var r=$(function(){return y2(e)},[e]),n=E.useRef(null),i=E.useRef(null),o=A(ce(function(d){var c=i.current;c||I(),c.textContent=d}),[]),l=A(function(d){var c=n.current;c||I(),c.textContent=d},[]);_e(function(){!n.current&&!i.current||I();var d=Kd(t),c=Kd(t);return n.current=d,i.current=c,d.setAttribute(en+"-always",e),c.setAttribute(en+"-dynamic",e),ya().appendChild(d),ya().appendChild(c),l(r.always),o(r.resting),function(){var p=function(y){var w=y.current;w||I(),ya().removeChild(w),y.current=null};p(n),p(i)}},[t,l,o,r.always,r.resting,e]);var a=A(function(){return o(r.dragging)},[o,r.dragging]),u=A(function(d){if(d==="DROP"){o(r.dropAnimating);return}o(r.userCancel)},[o,r.dropAnimating,r.userCancel]),s=A(function(){i.current&&o(r.resting)},[o,r.resting]),f=$(function(){return{dragging:a,dropping:u,resting:s}},[a,u,s]);return f}var jg=function(e){return e&&e.ownerDocument?e.ownerDocument.defaultView:window};function Dl(e){return e instanceof jg(e).HTMLElement}function S2(e,t){var r="["+tn.contextId+'="'+e+'"]',n=lg(document.querySelectorAll(r));if(!n.length)return null;var i=or(n,function(o){return o.getAttribute(tn.draggableId)===t});return!i||!Dl(i)?null:i}function x2(e){var t=E.useRef({}),r=E.useRef(null),n=E.useRef(null),i=E.useRef(!1),o=A(function(c,p){var m={id:c,focus:p};return t.current[c]=m,function(){var w=t.current,g=w[c];g!==m&&delete w[c]}},[]),l=A(function(c){var p=S2(e,c);p&&p!==document.activeElement&&p.focus()},[e]),a=A(function(c,p){r.current===c&&(r.current=p)},[]),u=A(function(){n.current||i.current&&(n.current=requestAnimationFrame(function(){n.current=null;var c=r.current;c&&l(c)}))},[l]),s=A(function(c){r.current=null;var p=document.activeElement;p&&p.getAttribute(tn.draggableId)===c&&(r.current=c)},[]);_e(function(){return i.current=!0,function(){i.current=!1;var c=n.current;c&&cancelAnimationFrame(c)}},[]);var f=$(function(){return{register:o,tryRecordFocus:s,tryRestoreFocusRecorded:u,tryShiftRecord:a}},[o,s,u,a]);return f}function E2(){var e={draggables:{},droppables:{}},t=[];function r(d){return t.push(d),function(){var p=t.indexOf(d);p!==-1&&t.splice(p,1)}}function n(d){t.length&&t.forEach(function(c){return c(d)})}function i(d){return e.draggables[d]||null}function o(d){var c=i(d);return c||I(),c}var l={register:function(c){e.draggables[c.descriptor.id]=c,n({type:"ADDITION",value:c})},update:function(c,p){var m=e.draggables[p.descriptor.id];m&&m.uniqueId===c.uniqueId&&(delete e.draggables[p.descriptor.id],e.draggables[c.descriptor.id]=c)},unregister:function(c){var p=c.descriptor.id,m=i(p);m&&c.uniqueId===m.uniqueId&&(delete e.draggables[p],n({type:"REMOVAL",value:c}))},getById:o,findById:i,exists:function(c){return!!i(c)},getAllByType:function(c){return $o(e.draggables).filter(function(p){return p.descriptor.type===c})}};function a(d){return e.droppables[d]||null}function u(d){var c=a(d);return c||I(),c}var s={register:function(c){e.droppables[c.descriptor.id]=c},unregister:function(c){var p=a(c.descriptor.id);p&&c.uniqueId===p.uniqueId&&delete e.droppables[c.descriptor.id]},getById:u,findById:a,exists:function(c){return!!a(c)},getAllByType:function(c){return $o(e.droppables).filter(function(p){return p.descriptor.type===c})}};function f(){e.draggables={},e.droppables={},t.length=0}return{draggable:l,droppable:s,subscribe:r,clean:f}}function C2(){var e=$(E2,[]);return E.useEffect(function(){return function(){requestAnimationFrame(e.clean)}},[e]),e}var qs=z.createContext(null),_o=function(){var e=document.body;return e||I(),e},b2={position:"absolute",width:"1px",height:"1px",margin:"-1px",border:"0",padding:"0",overflow:"hidden",clip:"rect(0 0 0 0)","clip-path":"inset(100%)"},D2=function(t){return"rbd-announcement-"+t};function P2(e){var t=$(function(){return D2(e)},[e]),r=E.useRef(null);E.useEffect(function(){var o=document.createElement("div");return r.current=o,o.id=t,o.setAttribute("aria-live","assertive"),o.setAttribute("aria-atomic","true"),L(o.style,b2),_o().appendChild(o),function(){setTimeout(function(){var u=_o();u.contains(o)&&u.removeChild(o),o===r.current&&(r.current=null)})}},[t]);var n=A(function(i){var o=r.current;if(o){o.textContent=i;return}},[]);return n}var I2=0,N2={separator:"::"};function Qs(e,t){return t===void 0&&(t=N2),$(function(){return""+e+t.separator+I2++},[t.separator,e])}function O2(e){var t=e.contextId,r=e.uniqueId;return"rbd-hidden-text-"+t+"-"+r}function R2(e){var t=e.contextId,r=e.text,n=Qs("hidden-text",{separator:"-"}),i=$(function(){return O2({contextId:t,uniqueId:n})},[n,t]);return E.useEffect(function(){var l=document.createElement("div");return l.id=i,l.textContent=r,l.style.display="none",_o().appendChild(l),function(){var u=_o();u.contains(l)&&u.removeChild(l)}},[i,r]),i}var Pl=z.createContext(null);function zg(e){var t=E.useRef(e);return E.useEffect(function(){t.current=e}),t}function k2(){var e=null;function t(){return!!e}function r(l){return l===e}function n(l){e&&I();var a={abandon:l};return e=a,a}function i(){e||I(),e=null}function o(){e&&(e.abandon(),i())}return{isClaimed:t,isActive:r,claim:n,release:i,tryAbandon:o}}var T2=9,A2=13,Ks=27,$g=32,L2=33,M2=34,B2=35,F2=36,j2=37,z2=38,$2=39,U2=40,Gi,_2=(Gi={},Gi[A2]=!0,Gi[T2]=!0,Gi),Ug=function(e){_2[e.keyCode]&&e.preventDefault()},Il=function(){var e="visibilitychange";if(typeof document>"u")return e;var t=[e,"ms"+e,"webkit"+e,"moz"+e,"o"+e],r=or(t,function(n){return"on"+n in document});return r||e}(),_g=0,Yd=5;function W2(e,t){return Math.abs(t.x-e.x)>=Yd||Math.abs(t.y-e.y)>=Yd}var Xd={type:"IDLE"};function H2(e){var t=e.cancel,r=e.completed,n=e.getPhase,i=e.setPhase;return[{eventName:"mousemove",fn:function(l){var a=l.button,u=l.clientX,s=l.clientY;if(a===_g){var f={x:u,y:s},d=n();if(d.type==="DRAGGING"){l.preventDefault(),d.actions.move(f);return}d.type!=="PENDING"&&I();var c=d.point;if(W2(c,f)){l.preventDefault();var p=d.actions.fluidLift(f);i({type:"DRAGGING",actions:p})}}}},{eventName:"mouseup",fn:function(l){var a=n();if(a.type!=="DRAGGING"){t();return}l.preventDefault(),a.actions.drop({shouldBlockNextClick:!0}),r()}},{eventName:"mousedown",fn:function(l){n().type==="DRAGGING"&&l.preventDefault(),t()}},{eventName:"keydown",fn:function(l){var a=n();if(a.type==="PENDING"){t();return}if(l.keyCode===Ks){l.preventDefault(),t();return}Ug(l)}},{eventName:"resize",fn:t},{eventName:"scroll",options:{passive:!0,capture:!1},fn:function(){n().type==="PENDING"&&t()}},{eventName:"webkitmouseforcedown",fn:function(l){var a=n();if(a.type==="IDLE"&&I(),a.actions.shouldRespectForcePress()){t();return}l.preventDefault()}},{eventName:Il,fn:t}]}function V2(e){var t=E.useRef(Xd),r=E.useRef(Qt),n=$(function(){return{eventName:"mousedown",fn:function(d){if(!d.defaultPrevented&&d.button===_g&&!(d.ctrlKey||d.metaKey||d.shiftKey||d.altKey)){var c=e.findClosestDraggableId(d);if(c){var p=e.tryGetLock(c,l,{sourceEvent:d});if(p){d.preventDefault();var m={x:d.clientX,y:d.clientY};r.current(),s(p,m)}}}}}},[e]),i=$(function(){return{eventName:"webkitmouseforcewillbegin",fn:function(d){if(!d.defaultPrevented){var c=e.findClosestDraggableId(d);if(c){var p=e.findOptionsForDraggable(c);p&&(p.shouldRespectForcePress||e.canGetLock(c)&&d.preventDefault())}}}}},[e]),o=A(function(){var d={passive:!1,capture:!0};r.current=et(window,[i,n],d)},[i,n]),l=A(function(){var f=t.current;f.type!=="IDLE"&&(t.current=Xd,r.current(),o())},[o]),a=A(function(){var f=t.current;l(),f.type==="DRAGGING"&&f.actions.cancel({shouldBlockNextClick:!0}),f.type==="PENDING"&&f.actions.abort()},[l]),u=A(function(){var d={capture:!0,passive:!1},c=H2({cancel:a,completed:l,getPhase:function(){return t.current},setPhase:function(m){t.current=m}});r.current=et(window,c,d)},[a,l]),s=A(function(d,c){t.current.type!=="IDLE"&&I(),t.current={type:"PENDING",point:c,actions:d},u()},[u]);_e(function(){return o(),function(){r.current()}},[o])}var Dr;function G2(){}var q2=(Dr={},Dr[M2]=!0,Dr[L2]=!0,Dr[F2]=!0,Dr[B2]=!0,Dr);function Q2(e,t){function r(){t(),e.cancel()}function n(){t(),e.drop()}return[{eventName:"keydown",fn:function(o){if(o.keyCode===Ks){o.preventDefault(),r();return}if(o.keyCode===$g){o.preventDefault(),n();return}if(o.keyCode===U2){o.preventDefault(),e.moveDown();return}if(o.keyCode===z2){o.preventDefault(),e.moveUp();return}if(o.keyCode===$2){o.preventDefault(),e.moveRight();return}if(o.keyCode===j2){o.preventDefault(),e.moveLeft();return}if(q2[o.keyCode]){o.preventDefault();return}Ug(o)}},{eventName:"mousedown",fn:r},{eventName:"mouseup",fn:r},{eventName:"click",fn:r},{eventName:"touchstart",fn:r},{eventName:"resize",fn:r},{eventName:"wheel",fn:r,options:{passive:!0}},{eventName:Il,fn:r}]}function K2(e){var t=E.useRef(G2),r=$(function(){return{eventName:"keydown",fn:function(o){if(o.defaultPrevented||o.keyCode!==$g)return;var l=e.findClosestDraggableId(o);if(!l)return;var a=e.tryGetLock(l,f,{sourceEvent:o});if(!a)return;o.preventDefault();var u=!0,s=a.snapLift();t.current();function f(){u||I(),u=!1,t.current(),n()}t.current=et(window,Q2(s,f),{capture:!0,passive:!1})}}},[e]),n=A(function(){var o={passive:!1,capture:!0};t.current=et(window,[r],o)},[r]);_e(function(){return n(),function(){t.current()}},[n])}var wa={type:"IDLE"},Y2=120,X2=.15;function Z2(e){var t=e.cancel,r=e.getPhase;return[{eventName:"orientationchange",fn:t},{eventName:"resize",fn:t},{eventName:"contextmenu",fn:function(i){i.preventDefault()}},{eventName:"keydown",fn:function(i){if(r().type!=="DRAGGING"){t();return}i.keyCode===Ks&&i.preventDefault(),t()}},{eventName:Il,fn:t}]}function J2(e){var t=e.cancel,r=e.completed,n=e.getPhase;return[{eventName:"touchmove",options:{capture:!1},fn:function(o){var l=n();if(l.type!=="DRAGGING"){t();return}l.hasMoved=!0;var a=o.touches[0],u=a.clientX,s=a.clientY,f={x:u,y:s};o.preventDefault(),l.actions.move(f)}},{eventName:"touchend",fn:function(o){var l=n();if(l.type!=="DRAGGING"){t();return}o.preventDefault(),l.actions.drop({shouldBlockNextClick:!0}),r()}},{eventName:"touchcancel",fn:function(o){if(n().type!=="DRAGGING"){t();return}o.preventDefault(),t()}},{eventName:"touchforcechange",fn:function(o){var l=n();l.type==="IDLE"&&I();var a=o.touches[0];if(a){var u=a.force>=X2;if(u){var s=l.actions.shouldRespectForcePress();if(l.type==="PENDING"){s&&t();return}if(s){if(l.hasMoved){o.preventDefault();return}t();return}o.preventDefault()}}}},{eventName:Il,fn:t}]}function ex(e){var t=E.useRef(wa),r=E.useRef(Qt),n=A(function(){return t.current},[]),i=A(function(p){t.current=p},[]),o=$(function(){return{eventName:"touchstart",fn:function(p){if(!p.defaultPrevented){var m=e.findClosestDraggableId(p);if(m){var y=e.tryGetLock(m,a,{sourceEvent:p});if(y){var w=p.touches[0],g=w.clientX,v=w.clientY,h={x:g,y:v};r.current(),d(y,h)}}}}}},[e]),l=A(function(){var p={capture:!0,passive:!1};r.current=et(window,[o],p)},[o]),a=A(function(){var c=t.current;c.type!=="IDLE"&&(c.type==="PENDING"&&clearTimeout(c.longPressTimerId),i(wa),r.current(),l())},[l,i]),u=A(function(){var c=t.current;a(),c.type==="DRAGGING"&&c.actions.cancel({shouldBlockNextClick:!0}),c.type==="PENDING"&&c.actions.abort()},[a]),s=A(function(){var p={capture:!0,passive:!1},m={cancel:u,completed:a,getPhase:n},y=et(window,J2(m),p),w=et(window,Z2(m),p);r.current=function(){y(),w()}},[u,n,a]),f=A(function(){var p=n();p.type!=="PENDING"&&I();var m=p.actions.fluidLift(p.point);i({type:"DRAGGING",actions:m,hasMoved:!1})},[n,i]),d=A(function(p,m){n().type!=="IDLE"&&I();var y=setTimeout(f,Y2);i({type:"PENDING",point:m,actions:p,longPressTimerId:y}),s()},[s,n,i,f]);_e(function(){return l(),function(){r.current();var m=n();m.type==="PENDING"&&(clearTimeout(m.longPressTimerId),i(wa))}},[n,l,i]),_e(function(){var p=et(window,[{eventName:"touchmove",fn:function(){},options:{capture:!1,passive:!1}}]);return p},[])}var tx={input:!0,button:!0,textarea:!0,select:!0,option:!0,optgroup:!0,video:!0,audio:!0};function Wg(e,t){if(t==null)return!1;var r=!!tx[t.tagName.toLowerCase()];if(r)return!0;var n=t.getAttribute("contenteditable");return n==="true"||n===""?!0:t===e?!1:Wg(e,t.parentElement)}function rx(e,t){var r=t.target;return Dl(r)?Wg(e,r):!1}var nx=function(e){return st(e.getBoundingClientRect()).center};function ix(e){return e instanceof jg(e).Element}var ox=function(){var e="matches";if(typeof document>"u")return e;var t=[e,"msMatchesSelector","webkitMatchesSelector"],r=or(t,function(n){return n in Element.prototype});return r||e}();function Hg(e,t){return e==null?null:e[ox](t)?e:Hg(e.parentElement,t)}function lx(e,t){return e.closest?e.closest(t):Hg(e,t)}function ax(e){return"["+tn.contextId+'="'+e+'"]'}function ux(e,t){var r=t.target;if(!ix(r))return null;var n=ax(e),i=lx(r,n);return!i||!Dl(i)?null:i}function sx(e,t){var r=ux(e,t);return r?r.getAttribute(tn.draggableId):null}function cx(e,t){var r="["+Su.contextId+'="'+e+'"]',n=lg(document.querySelectorAll(r)),i=or(n,function(o){return o.getAttribute(Su.id)===t});return!i||!Dl(i)?null:i}function dx(e){e.preventDefault()}function qi(e){var t=e.expected,r=e.phase,n=e.isLockActive;return e.shouldWarn,!(!n()||t!==r)}function Vg(e){var t=e.lockAPI,r=e.store,n=e.registry,i=e.draggableId;if(t.isClaimed())return!1;var o=n.draggable.findById(i);return!(!o||!o.options.isEnabled||!Lg(r.getState(),i))}function fx(e){var t=e.lockAPI,r=e.contextId,n=e.store,i=e.registry,o=e.draggableId,l=e.forceSensorStop,a=e.sourceEvent,u=Vg({lockAPI:t,store:n,registry:i,draggableId:o});if(!u)return null;var s=i.draggable.getById(o),f=cx(r,s.descriptor.id);if(!f||a&&!s.options.canDragInteractiveElements&&rx(f,a))return null;var d=t.claim(l||Qt),c="PRE_DRAG";function p(){return s.options.shouldRespectForcePress}function m(){return t.isActive(d)}function y(C,P){qi({expected:C,phase:c,isLockActive:m,shouldWarn:!0})&&n.dispatch(P())}var w=y.bind(null,"DRAGGING");function g(C){function P(){t.release(),c="COMPLETED"}c!=="PRE_DRAG"&&(P(),c!=="PRE_DRAG"&&I()),n.dispatch(oS(C.liftActionArgs)),c="DRAGGING";function N(T,k){if(k===void 0&&(k={shouldBlockNextClick:!1}),C.cleanup(),k.shouldBlockNextClick){var F=et(window,[{eventName:"click",fn:dx,options:{once:!0,passive:!1,capture:!0}}]);setTimeout(F)}P(),n.dispatch(Ig({reason:T}))}return L({isActive:function(){return qi({expected:"DRAGGING",phase:c,isLockActive:m,shouldWarn:!1})},shouldRespectForcePress:p,drop:function(k){return N("DROP",k)},cancel:function(k){return N("CANCEL",k)}},C.actions)}function v(C){var P=ni(function(T){w(function(){return Pg({client:T})})}),N=g({liftActionArgs:{id:o,clientSelection:C,movementMode:"FLUID"},cleanup:function(){return P.cancel()},actions:{move:P}});return L({},N,{move:P})}function h(){var C={moveUp:function(){return w(vS)},moveRight:function(){return w(mS)},moveDown:function(){return w(gS)},moveLeft:function(){return w(hS)}};return g({liftActionArgs:{id:o,clientSelection:nx(f),movementMode:"SNAP"},cleanup:Qt,actions:C})}function S(){var C=qi({expected:"PRE_DRAG",phase:c,isLockActive:m,shouldWarn:!0});C&&t.release()}var x={isActive:function(){return qi({expected:"PRE_DRAG",phase:c,isLockActive:m,shouldWarn:!1})},shouldRespectForcePress:p,fluidLift:v,snapLift:h,abort:S};return x}var px=[V2,K2,ex];function vx(e){var t=e.contextId,r=e.store,n=e.registry,i=e.customSensors,o=e.enableDefaultSensors,l=[].concat(o?px:[],i||[]),a=E.useState(function(){return k2()})[0],u=A(function(v,h){v.isDragging&&!h.isDragging&&a.tryAbandon()},[a]);_e(function(){var v=r.getState(),h=r.subscribe(function(){var S=r.getState();u(v,S),v=S});return h},[a,r,u]),_e(function(){return a.tryAbandon},[a.tryAbandon]);for(var s=A(function(g){return Vg({lockAPI:a,registry:n,store:r,draggableId:g})},[a,n,r]),f=A(function(g,v,h){return fx({lockAPI:a,registry:n,contextId:t,store:r,draggableId:g,forceSensorStop:v,sourceEvent:h&&h.sourceEvent?h.sourceEvent:null})},[t,a,n,r]),d=A(function(g){return sx(t,g)},[t]),c=A(function(g){var v=n.draggable.findById(g);return v?v.options:null},[n.draggable]),p=A(function(){a.isClaimed()&&(a.tryAbandon(),r.getState().phase!=="IDLE"&&r.dispatch(zs()))},[a,r]),m=A(a.isClaimed,[a]),y=$(function(){return{canGetLock:s,tryGetLock:f,findClosestDraggableId:d,findOptionsForDraggable:c,tryReleaseLock:p,isLockClaimed:m}},[s,f,d,c,p,m]),w=0;w{const{apps:e}=ln(),{favoriteApps:t,setFavoriteApps:r}=vi(),[n,i]=E.useState([]);E.useEffect(()=>{let u=[];const s=Object.entries(t).filter(([c,{favorite:p}])=>p).map(([c,{order:p}])=>({...e.find(m=>m.package_name===c),order:p})).filter(c=>c),f=s.filter(c=>c.order!==void 0&&c.order!==null),d=s.filter(c=>c.order===void 0||c.order===null);for(let c=0;cc),d.forEach(c=>u.push(c)),i(u)},[e,t]);const o=ir(),l=(u,s,f)=>{const d=Array.from(u),[c]=d.splice(s,1);return d.splice(f,0,c),d},a=u=>{if(!u.destination)return;const f=l(n,u.source.index,u.destination.index).map(c=>c.package_name),d={...t};f.forEach((c,p)=>{d[c].order=p}),r(d),console.log({favoriteApps:t}),fetch(Pn("/order"),{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(f)}).catch(c=>console.error(c))};return b.jsx(wx,{onDragEnd:a,children:b.jsx(Xg,{droppableId:"droppable",direction:"horizontal",children:(u,s)=>b.jsxs("div",{ref:u.innerRef,...u.droppableProps,className:Te("flex-center flex-wrap border border-orange bg-orange/25 p-2 rounded !rounded-xl",{"gap-8":!o&&n.length>0,"gap-4":!o&&n.length===0,"mb-4":!o,"gap-4 mb-2":o,"flex-col":n.length===0}),children:[n.map(f=>b.jsx(rE,{draggableId:f.package_name,index:n.indexOf(f),children:(d,c)=>b.jsx("div",{ref:d.innerRef,...d.draggableProps,...d.dragHandleProps,children:b.jsx(Av,{app:f})})},f.package_name)),u.placeholder,n.length===0&&b.jsx("div",{children:"Favorite an app to pin it to your dock."})]})})})},sE=({expanded:e})=>{const{apps:t}=ln(),r=ir();return b.jsx("div",{className:Te("flex-center flex-wrap overflow-y-auto fixed h-screen w-screen backdrop-blur-md transition transition-all ease-in-out duration-500",{"top-[100vh]":!e,"top-0":e,"gap-4 p-8":r,"gap-8 p-16":!r}),children:t.length===0?b.jsx("div",{children:"Loading apps..."}):t.map(n=>b.jsx(Av,{app:n},n.package_name))})},cE=({package_name:e,widget:t,forceLarge:r})=>{var c,p,m,y,w;const{apps:n}=ln(),{widgetSettings:i,toggleWidgetVisibility:o}=vi(),[l,a]=E.useState(!1),u=ir(),s=r||((c=i[e])==null?void 0:c.size)==="large",f=!((p=i[e])!=null&&p.size)||((m=i[e])==null?void 0:m.size)==="small",d=window.innerHeight>window.innerWidth;return b.jsxs("div",{className:Te("self-stretch flex-col-center shadow-lg rounded-lg relative",{"max-w-1/2 min-w-1/2":s&&!u,"min-w-1/4":f&&!u,"max-w-1/4":f&&!d,"w-full":u}),onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),children:[b.jsx("h6",{className:"flex-center my-2",children:((y=n.find(g=>g.package_name===e))==null?void 0:y.label)||e}),b.jsx("iframe",{srcDoc:t||"",className:"grow self-stretch","data-widget-code":t}),l&&b.jsx("button",{className:"absolute top-0 left-0 icon",onClick:()=>o(e),children:(w=i[e])!=null&&w.hide?b.jsx(E0,{}):b.jsx(x0,{})})]})},dE=()=>{const{apps:e}=ln(),{widgetSettings:t}=vi(),r=ir();return b.jsx("div",{className:Te("flex-center flex-wrap flex-grow self-stretch",{"gap-2 m-2":r,"gap-4 m-4":!r}),children:e.filter(n=>n.widget).map(({widget:n,package_name:i},o,l)=>{var a;return!((a=t[i])!=null&&a.hide)&&b.jsx(cE,{package_name:i,widget:n,forceLarge:l.length===1},i)})})},fE=({title:e,onClose:t,children:r})=>{const n=ir();return b.jsx("div",{className:"flex fixed top-0 left-0 w-full h-full bg-black bg-opacity-50 place-items-center place-content-center backdrop-blur-md",children:b.jsxs("div",{className:Te("flex flex-col rounded-lg bg-black py-4 shadow-lg max-h-screen overflow-y-auto",{"min-w-[500px] px-8 w-1/2":!n,"px-4 w-full":n}),children:[b.jsxs("div",{className:"flex",children:[b.jsx("h1",{className:"grow",children:e}),b.jsx("button",{className:"icon self-start",onClick:t,children:b.jsx(D0,{})})]}),r]})})},pE=()=>{const{apps:e,setShowWidgetsSettings:t}=ln(),{widgetSettings:r,toggleWidgetVisibility:n,setWidgetSize:i}=vi();return b.jsx(fE,{title:"Widget Settings",onClose:()=>t(!1),children:b.jsxs("div",{className:"flex-col-center gap-4 mt-4",children:[e.filter(o=>o.widget).map(({label:o,package_name:l})=>{var a,u,s,f;return b.jsxs("div",{className:"flex items-start bg-white/10 rounded p-2 self-stretch",children:[b.jsx("h4",{className:"mr-4 grow",children:o}),b.jsxs("div",{className:"flex flex-col gap-4 grow",children:[b.jsxs("div",{className:"flex-center gap-2",children:[b.jsx("span",{children:"Show widget"}),b.jsxs("div",{className:"flex relative grow",children:[b.jsx("input",{type:"checkbox",checked:!((a=r[l])!=null&&a.hide),onChange:()=>n(l),autoFocus:!0}),!((u=r[l])!=null&&u.hide)&&b.jsx("span",{onClick:()=>n(l),className:"checkmark",children:"✓"})]})]}),b.jsxs("div",{className:"flex-center gap-2",children:[b.jsx("span",{children:"Widget size"}),b.jsxs("div",{className:"flex-center grow",children:[b.jsx("button",{className:Te({clear:((s=r[l])==null?void 0:s.size)==="large"}),onClick:()=>i(l,"small"),children:"Small"}),b.jsx("button",{className:Te({clear:((f=r[l])==null?void 0:f.size)!=="large"}),onClick:()=>i(l,"large"),children:"Large"})]})]})]})]})}),b.jsx("button",{className:"clear",onClick:()=>window.location.href="/settings:settings:sys",children:"Looking for system settings?"})]})})},vE="/assets/valet-icon-COgctyxf.png";function gE(){const[e,t]=E.useState(""),[r,n]=E.useState(""),[i,o]=E.useState(!1),{setApps:l,isHosted:a,fetchHostedStatus:u,showWidgetsSettings:s,setShowWidgetsSettings:f}=ln(),d=ir(),c=()=>{Promise.all([fetch(Pn("/apps"),{credentials:"include"}).then(p=>p.json()).catch(()=>[]),fetch(Pn("/main:app_store:sys/apps"),{credentials:"include"}).then(p=>p.json()).catch(()=>[]),fetch(Pn("/version"),{credentials:"include"}).then(p=>p.text()).catch(()=>"")]).then(([p,m,y])=>{n(y);const w=p.map(g=>({...g,is_favorite:!1}));m.forEach(g=>{const v=w.findIndex(h=>h.package_name===g.package);v===-1?w.push({package_name:g.package,path:"",label:g.package,state:g.state,is_favorite:!1}):w[v]={...w[v],state:g.state}}),l(w);for(let g=0;g<5&&w.find(v=>v.package_name==="app_store"&&!v.base64_icon);g++)c()})};return E.useEffect(()=>{c()},[e]),E.useEffect(()=>{fetch(Pn("/our"),{credentials:"include"}).then(p=>p.text()).then(p=>{p.match(/^[a-zA-Z0-9\-\.]+\.[a-zA-Z]+$/)&&(t(p),u(p))})},[e]),b.jsxs("div",{className:Te("flex-col-center relative w-screen overflow-hidden special-bg-homepage min-h-screen",{}),children:[b.jsxs("h5",{className:Te("absolute flex gap-4 c",{"top-8 left-8 right-8":!d,"top-2 left-2 right-2":d}),children:[a&&b.jsx("img",{src:vE,className:"!w-12 !h-12 !p-1 button icon object-cover",onClick:()=>window.location.href="https://valet.kinode.org/"}),b.jsx("span",{children:e}),b.jsxs("span",{className:"bg-white/10 rounded p-1",children:["v",r]}),b.jsx("button",{className:"icon ml-auto",onClick:()=>f(!0),children:b.jsx(b0,{})})]}),d?b.jsxs("div",{className:"flex-center gap-4 p-8 mt-8 max-w-screen",children:[b.jsx(cd,{}),b.jsx(sd,{})]}):b.jsxs("div",{className:Te("flex-col-center mx-0 gap-4 mt-8 mb-4"),children:[b.jsx("h3",{className:"text-center",children:"Welcome to"}),b.jsx(sd,{}),b.jsx(cd,{})]}),b.jsx(uE,{}),b.jsx(dE,{}),b.jsxs("button",{className:Te("fixed alt clear flex-center self-center z-20",{"bottom-2 right-2":d,"bottom-8 right-8":!d}),onClick:()=>o(!i),children:[i?b.jsx(w0,{}):b.jsx(S0,{}),b.jsx("span",{className:"ml-2",children:i?"Collapse":"All apps"})]}),b.jsx(sE,{expanded:i}),s&&b.jsx(pE,{})]})}/** * @remix-run/router v1.16.0 * * Copyright (c) Remix Software Inc. diff --git a/kinode/packages/homepage/pkg/ui/index.html b/kinode/packages/homepage/pkg/ui/index.html index fbbe1d72e..654bbb19d 100644 --- a/kinode/packages/homepage/pkg/ui/index.html +++ b/kinode/packages/homepage/pkg/ui/index.html @@ -9,7 +9,7 @@ - + diff --git a/kinode/packages/homepage/ui/dist/index.html b/kinode/packages/homepage/ui/dist/index.html index fbbe1d72e..654bbb19d 100644 --- a/kinode/packages/homepage/ui/dist/index.html +++ b/kinode/packages/homepage/ui/dist/index.html @@ -9,7 +9,7 @@ - + diff --git a/kinode/packages/homepage/ui/src/components/Widget.tsx b/kinode/packages/homepage/ui/src/components/Widget.tsx index 12fede5a8..c94db42af 100644 --- a/kinode/packages/homepage/ui/src/components/Widget.tsx +++ b/kinode/packages/homepage/ui/src/components/Widget.tsx @@ -18,10 +18,12 @@ const Widget: React.FC = ({ package_name, widget, forceLarge }) => const isMobile = isMobileCheck() const isLarge = forceLarge || widgetSettings[package_name]?.size === "large" const isSmall = !widgetSettings[package_name]?.size || widgetSettings[package_name]?.size === "small" + const screenIsTallerThanItIsWide = window.innerHeight > window.innerWidth return
setIsHovered(true)} From f5d30b5b1b04121627b62b9b2c879658b9512309 Mon Sep 17 00:00:00 2001 From: Tobias Merkle Date: Fri, 14 Jun 2024 14:55:27 -0400 Subject: [PATCH 15/53] correctly watch windowsize changes --- .../assets/{index-CTL7geHV.js => index-BLQ3kP3C.js} | 4 ++-- kinode/packages/homepage/pkg/ui/index.html | 2 +- kinode/packages/homepage/ui/dist/index.html | 2 +- .../homepage/ui/src/components/AppDisplay.tsx | 2 +- .../homepage/ui/src/components/AppIconPlaceholder.tsx | 2 +- kinode/packages/homepage/ui/src/components/Widget.tsx | 11 ++++++++--- 6 files changed, 14 insertions(+), 9 deletions(-) rename kinode/packages/homepage/pkg/ui/assets/{index-CTL7geHV.js => index-BLQ3kP3C.js} (95%) diff --git a/kinode/packages/homepage/pkg/ui/assets/index-CTL7geHV.js b/kinode/packages/homepage/pkg/ui/assets/index-BLQ3kP3C.js similarity index 95% rename from kinode/packages/homepage/pkg/ui/assets/index-CTL7geHV.js rename to kinode/packages/homepage/pkg/ui/assets/index-BLQ3kP3C.js index 6c617b22b..4ab5f6ef3 100644 --- a/kinode/packages/homepage/pkg/ui/assets/index-CTL7geHV.js +++ b/kinode/packages/homepage/pkg/ui/assets/index-BLQ3kP3C.js @@ -57,7 +57,7 @@ Error generating stack: `+o.message+` Copyright (c) 2018 Jed Watson. Licensed under the MIT License (MIT), see http://jedwatson.github.io/classnames -*/(function(e){(function(){var t={}.hasOwnProperty;function r(){for(var o="",l=0;l({get:t,set:e,widgetSettings:{},favoriteApps:{},setWidgetSettings:r=>e({widgetSettings:r}),setFavoriteApps:r=>e({favoriteApps:r}),toggleWidgetVisibility:r=>{var i;const{widgetSettings:n}=t();e({widgetSettings:{...n,[r]:{...n[r],hide:!((i=n[r])!=null&&i.hide)}}})},setWidgetSize:(r,n)=>{const{widgetSettings:i}=t();e({widgetSettings:{...i,[r]:{...i[r],size:n}}})},favoriteApp:async r=>{var i;const{favoriteApps:n}=t();e({favoriteApps:{...n,[r]:{...n[r],favorite:!((i=n[r])!=null&&i.favorite)}}})}}),{name:"homepage_persistent_store",storage:xs(()=>localStorage)})),ir=()=>window.innerWidth<=600,N0=({text:e,className:t,size:r})=>{var l;const i=`/icons/${((l=e.split("").pop())==null?void 0:l.toUpperCase())||"0"}`;if(!i)return null;const o=ir();return b.jsx("img",{src:i,className:Te("m-0 align-self-center rounded-full",{"h-32 w-32":!o&&r==="large","h-18 w-18":!o&&r==="medium","h-12 w-12":o||r==="small"},t)})},Av=({app:e})=>{var l,a;const{favoriteApp:t,favoriteApps:r}=vi(),[n,i]=E.useState(!1),o=ir();return b.jsxs("a",{className:Te("flex-col-center gap-2 relative hover:opacity-90 transition-opacity",{"cursor-pointer":e==null?void 0:e.path,"cursor-not-allowed":!(e!=null&&e.path)}),id:e==null?void 0:e.package_name,href:e==null?void 0:e.path,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),children:[e!=null&&e.base64_icon?b.jsx("img",{src:e.base64_icon,className:Te("rounded",{"h-8 w-8":o,"h-16 w-16":!o})}):b.jsx(N0,{text:((l=e==null?void 0:e.state)==null?void 0:l.our_version)||"0",size:"small",className:"h-16 w-16"}),b.jsx("h6",{children:e==null?void 0:e.label}),(e==null?void 0:e.path)&&n&&b.jsx("button",{className:"absolute p-2 -top-2 -right-2 clear text-sm",onClick:u=>{u.preventDefault(),t(e.package_name)},children:(a=r[e.package_name])!=null&&a.favorite?b.jsx(C0,{}):b.jsx(P0,{})})]})};function gu(e,t){return gu=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,i){return n.__proto__=i,n},gu(e,t)}function Lv(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,gu(e,t)}function L(){return L=Object.assign?Object.assign.bind():function(e){for(var t=1;t"u"&&(r=t,t=void 0),typeof r<"u"){if(typeof r!="function")throw new Error(Oe(1));return r(Mv)(e,t)}if(typeof e!="function")throw new Error(Oe(2));var i=e,o=t,l=[],a=l,u=!1;function s(){a===l&&(a=l.slice())}function f(){if(u)throw new Error(Oe(3));return o}function d(y){if(typeof y!="function")throw new Error(Oe(4));if(u)throw new Error(Oe(5));var w=!0;return s(),a.push(y),function(){if(w){if(u)throw new Error(Oe(6));w=!1,s();var v=a.indexOf(y);a.splice(v,1),l=null}}}function c(y){if(!T0(y))throw new Error(Oe(7));if(typeof y.type>"u")throw new Error(Oe(8));if(u)throw new Error(Oe(9));try{u=!0,o=i(o,y)}finally{u=!1}for(var w=l=a,g=0;g=0)continue;r[n]=e[n]}return r}var Uv={exports:{}},V={};/** @license React v16.13.1 +*/(function(e){(function(){var t={}.hasOwnProperty;function r(){for(var o="",l=0;l({get:t,set:e,widgetSettings:{},favoriteApps:{},setWidgetSettings:r=>e({widgetSettings:r}),setFavoriteApps:r=>e({favoriteApps:r}),toggleWidgetVisibility:r=>{var i;const{widgetSettings:n}=t();e({widgetSettings:{...n,[r]:{...n[r],hide:!((i=n[r])!=null&&i.hide)}}})},setWidgetSize:(r,n)=>{const{widgetSettings:i}=t();e({widgetSettings:{...i,[r]:{...i[r],size:n}}})},favoriteApp:async r=>{var i;const{favoriteApps:n}=t();e({favoriteApps:{...n,[r]:{...n[r],favorite:!((i=n[r])!=null&&i.favorite)}}})}}),{name:"homepage_persistent_store",storage:xs(()=>localStorage)})),ir=()=>window.innerWidth<=600,N0=({text:e,className:t,size:r})=>{var l;const i=`/api/icons/${((l=e.split("").pop())==null?void 0:l.toUpperCase())||"0"}`;if(!i)return null;const o=ir();return b.jsx("img",{src:i,className:Te("m-0 align-self-center rounded-full",{"h-32 w-32":!o&&r==="large","h-18 w-18":!o&&r==="medium","h-12 w-12":o||r==="small"},t)})},Av=({app:e})=>{var l,a;const{favoriteApp:t,favoriteApps:r}=vi(),[n,i]=E.useState(!1),o=ir();return b.jsxs("a",{className:Te("flex-col-center gap-2 relative hover:opacity-90 transition-opacity",{"cursor-pointer":e==null?void 0:e.path,"cursor-not-allowed":!(e!=null&&e.path)}),id:e==null?void 0:e.package_name,href:e==null?void 0:e.path,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),children:[e!=null&&e.base64_icon?b.jsx("img",{src:e.base64_icon,className:Te("rounded",{"h-8 w-8":o,"h-16 w-16":!o})}):b.jsx(N0,{text:((l=e==null?void 0:e.state)==null?void 0:l.our_version)||"0",size:"small",className:"h-16 w-16"}),b.jsx("h6",{children:(e==null?void 0:e.label)||(e==null?void 0:e.package_name)}),(e==null?void 0:e.path)&&n&&b.jsx("button",{className:"absolute p-2 -top-2 -right-2 clear text-sm",onClick:u=>{u.preventDefault(),t(e.package_name)},children:(a=r[e.package_name])!=null&&a.favorite?b.jsx(C0,{}):b.jsx(P0,{})})]})};function gu(e,t){return gu=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,i){return n.__proto__=i,n},gu(e,t)}function Lv(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,gu(e,t)}function L(){return L=Object.assign?Object.assign.bind():function(e){for(var t=1;t"u"&&(r=t,t=void 0),typeof r<"u"){if(typeof r!="function")throw new Error(Oe(1));return r(Mv)(e,t)}if(typeof e!="function")throw new Error(Oe(2));var i=e,o=t,l=[],a=l,u=!1;function s(){a===l&&(a=l.slice())}function f(){if(u)throw new Error(Oe(3));return o}function d(y){if(typeof y!="function")throw new Error(Oe(4));if(u)throw new Error(Oe(5));var w=!0;return s(),a.push(y),function(){if(w){if(u)throw new Error(Oe(6));w=!1,s();var v=a.indexOf(y);a.splice(v,1),l=null}}}function c(y){if(!T0(y))throw new Error(Oe(7));if(typeof y.type>"u")throw new Error(Oe(8));if(u)throw new Error(Oe(9));try{u=!0,o=i(o,y)}finally{u=!1}for(var w=l=a,g=0;g=0)continue;r[n]=e[n]}return r}var Uv={exports:{}},V={};/** @license React v16.13.1 * react-is.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. @@ -124,7 +124,7 @@ Error generating stack: `+o.message+` -moz-user-select: none; -ms-user-select: none; overflow-anchor: none; - `}},l=[n,r,i,o];return{always:Sn(l,"always"),resting:Sn(l,"resting"),dragging:Sn(l,"dragging"),dropAnimating:Sn(l,"dropAnimating"),userCancel:Sn(l,"userCancel")}},_e=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u"?E.useLayoutEffect:E.useEffect,ya=function(){var t=document.querySelector("head");return t||I(),t},Kd=function(t){var r=document.createElement("style");return t&&r.setAttribute("nonce",t),r.type="text/css",r};function w2(e,t){var r=$(function(){return y2(e)},[e]),n=E.useRef(null),i=E.useRef(null),o=A(ce(function(d){var c=i.current;c||I(),c.textContent=d}),[]),l=A(function(d){var c=n.current;c||I(),c.textContent=d},[]);_e(function(){!n.current&&!i.current||I();var d=Kd(t),c=Kd(t);return n.current=d,i.current=c,d.setAttribute(en+"-always",e),c.setAttribute(en+"-dynamic",e),ya().appendChild(d),ya().appendChild(c),l(r.always),o(r.resting),function(){var p=function(y){var w=y.current;w||I(),ya().removeChild(w),y.current=null};p(n),p(i)}},[t,l,o,r.always,r.resting,e]);var a=A(function(){return o(r.dragging)},[o,r.dragging]),u=A(function(d){if(d==="DROP"){o(r.dropAnimating);return}o(r.userCancel)},[o,r.dropAnimating,r.userCancel]),s=A(function(){i.current&&o(r.resting)},[o,r.resting]),f=$(function(){return{dragging:a,dropping:u,resting:s}},[a,u,s]);return f}var jg=function(e){return e&&e.ownerDocument?e.ownerDocument.defaultView:window};function Dl(e){return e instanceof jg(e).HTMLElement}function S2(e,t){var r="["+tn.contextId+'="'+e+'"]',n=lg(document.querySelectorAll(r));if(!n.length)return null;var i=or(n,function(o){return o.getAttribute(tn.draggableId)===t});return!i||!Dl(i)?null:i}function x2(e){var t=E.useRef({}),r=E.useRef(null),n=E.useRef(null),i=E.useRef(!1),o=A(function(c,p){var m={id:c,focus:p};return t.current[c]=m,function(){var w=t.current,g=w[c];g!==m&&delete w[c]}},[]),l=A(function(c){var p=S2(e,c);p&&p!==document.activeElement&&p.focus()},[e]),a=A(function(c,p){r.current===c&&(r.current=p)},[]),u=A(function(){n.current||i.current&&(n.current=requestAnimationFrame(function(){n.current=null;var c=r.current;c&&l(c)}))},[l]),s=A(function(c){r.current=null;var p=document.activeElement;p&&p.getAttribute(tn.draggableId)===c&&(r.current=c)},[]);_e(function(){return i.current=!0,function(){i.current=!1;var c=n.current;c&&cancelAnimationFrame(c)}},[]);var f=$(function(){return{register:o,tryRecordFocus:s,tryRestoreFocusRecorded:u,tryShiftRecord:a}},[o,s,u,a]);return f}function E2(){var e={draggables:{},droppables:{}},t=[];function r(d){return t.push(d),function(){var p=t.indexOf(d);p!==-1&&t.splice(p,1)}}function n(d){t.length&&t.forEach(function(c){return c(d)})}function i(d){return e.draggables[d]||null}function o(d){var c=i(d);return c||I(),c}var l={register:function(c){e.draggables[c.descriptor.id]=c,n({type:"ADDITION",value:c})},update:function(c,p){var m=e.draggables[p.descriptor.id];m&&m.uniqueId===c.uniqueId&&(delete e.draggables[p.descriptor.id],e.draggables[c.descriptor.id]=c)},unregister:function(c){var p=c.descriptor.id,m=i(p);m&&c.uniqueId===m.uniqueId&&(delete e.draggables[p],n({type:"REMOVAL",value:c}))},getById:o,findById:i,exists:function(c){return!!i(c)},getAllByType:function(c){return $o(e.draggables).filter(function(p){return p.descriptor.type===c})}};function a(d){return e.droppables[d]||null}function u(d){var c=a(d);return c||I(),c}var s={register:function(c){e.droppables[c.descriptor.id]=c},unregister:function(c){var p=a(c.descriptor.id);p&&c.uniqueId===p.uniqueId&&delete e.droppables[c.descriptor.id]},getById:u,findById:a,exists:function(c){return!!a(c)},getAllByType:function(c){return $o(e.droppables).filter(function(p){return p.descriptor.type===c})}};function f(){e.draggables={},e.droppables={},t.length=0}return{draggable:l,droppable:s,subscribe:r,clean:f}}function C2(){var e=$(E2,[]);return E.useEffect(function(){return function(){requestAnimationFrame(e.clean)}},[e]),e}var qs=z.createContext(null),_o=function(){var e=document.body;return e||I(),e},b2={position:"absolute",width:"1px",height:"1px",margin:"-1px",border:"0",padding:"0",overflow:"hidden",clip:"rect(0 0 0 0)","clip-path":"inset(100%)"},D2=function(t){return"rbd-announcement-"+t};function P2(e){var t=$(function(){return D2(e)},[e]),r=E.useRef(null);E.useEffect(function(){var o=document.createElement("div");return r.current=o,o.id=t,o.setAttribute("aria-live","assertive"),o.setAttribute("aria-atomic","true"),L(o.style,b2),_o().appendChild(o),function(){setTimeout(function(){var u=_o();u.contains(o)&&u.removeChild(o),o===r.current&&(r.current=null)})}},[t]);var n=A(function(i){var o=r.current;if(o){o.textContent=i;return}},[]);return n}var I2=0,N2={separator:"::"};function Qs(e,t){return t===void 0&&(t=N2),$(function(){return""+e+t.separator+I2++},[t.separator,e])}function O2(e){var t=e.contextId,r=e.uniqueId;return"rbd-hidden-text-"+t+"-"+r}function R2(e){var t=e.contextId,r=e.text,n=Qs("hidden-text",{separator:"-"}),i=$(function(){return O2({contextId:t,uniqueId:n})},[n,t]);return E.useEffect(function(){var l=document.createElement("div");return l.id=i,l.textContent=r,l.style.display="none",_o().appendChild(l),function(){var u=_o();u.contains(l)&&u.removeChild(l)}},[i,r]),i}var Pl=z.createContext(null);function zg(e){var t=E.useRef(e);return E.useEffect(function(){t.current=e}),t}function k2(){var e=null;function t(){return!!e}function r(l){return l===e}function n(l){e&&I();var a={abandon:l};return e=a,a}function i(){e||I(),e=null}function o(){e&&(e.abandon(),i())}return{isClaimed:t,isActive:r,claim:n,release:i,tryAbandon:o}}var T2=9,A2=13,Ks=27,$g=32,L2=33,M2=34,B2=35,F2=36,j2=37,z2=38,$2=39,U2=40,Gi,_2=(Gi={},Gi[A2]=!0,Gi[T2]=!0,Gi),Ug=function(e){_2[e.keyCode]&&e.preventDefault()},Il=function(){var e="visibilitychange";if(typeof document>"u")return e;var t=[e,"ms"+e,"webkit"+e,"moz"+e,"o"+e],r=or(t,function(n){return"on"+n in document});return r||e}(),_g=0,Yd=5;function W2(e,t){return Math.abs(t.x-e.x)>=Yd||Math.abs(t.y-e.y)>=Yd}var Xd={type:"IDLE"};function H2(e){var t=e.cancel,r=e.completed,n=e.getPhase,i=e.setPhase;return[{eventName:"mousemove",fn:function(l){var a=l.button,u=l.clientX,s=l.clientY;if(a===_g){var f={x:u,y:s},d=n();if(d.type==="DRAGGING"){l.preventDefault(),d.actions.move(f);return}d.type!=="PENDING"&&I();var c=d.point;if(W2(c,f)){l.preventDefault();var p=d.actions.fluidLift(f);i({type:"DRAGGING",actions:p})}}}},{eventName:"mouseup",fn:function(l){var a=n();if(a.type!=="DRAGGING"){t();return}l.preventDefault(),a.actions.drop({shouldBlockNextClick:!0}),r()}},{eventName:"mousedown",fn:function(l){n().type==="DRAGGING"&&l.preventDefault(),t()}},{eventName:"keydown",fn:function(l){var a=n();if(a.type==="PENDING"){t();return}if(l.keyCode===Ks){l.preventDefault(),t();return}Ug(l)}},{eventName:"resize",fn:t},{eventName:"scroll",options:{passive:!0,capture:!1},fn:function(){n().type==="PENDING"&&t()}},{eventName:"webkitmouseforcedown",fn:function(l){var a=n();if(a.type==="IDLE"&&I(),a.actions.shouldRespectForcePress()){t();return}l.preventDefault()}},{eventName:Il,fn:t}]}function V2(e){var t=E.useRef(Xd),r=E.useRef(Qt),n=$(function(){return{eventName:"mousedown",fn:function(d){if(!d.defaultPrevented&&d.button===_g&&!(d.ctrlKey||d.metaKey||d.shiftKey||d.altKey)){var c=e.findClosestDraggableId(d);if(c){var p=e.tryGetLock(c,l,{sourceEvent:d});if(p){d.preventDefault();var m={x:d.clientX,y:d.clientY};r.current(),s(p,m)}}}}}},[e]),i=$(function(){return{eventName:"webkitmouseforcewillbegin",fn:function(d){if(!d.defaultPrevented){var c=e.findClosestDraggableId(d);if(c){var p=e.findOptionsForDraggable(c);p&&(p.shouldRespectForcePress||e.canGetLock(c)&&d.preventDefault())}}}}},[e]),o=A(function(){var d={passive:!1,capture:!0};r.current=et(window,[i,n],d)},[i,n]),l=A(function(){var f=t.current;f.type!=="IDLE"&&(t.current=Xd,r.current(),o())},[o]),a=A(function(){var f=t.current;l(),f.type==="DRAGGING"&&f.actions.cancel({shouldBlockNextClick:!0}),f.type==="PENDING"&&f.actions.abort()},[l]),u=A(function(){var d={capture:!0,passive:!1},c=H2({cancel:a,completed:l,getPhase:function(){return t.current},setPhase:function(m){t.current=m}});r.current=et(window,c,d)},[a,l]),s=A(function(d,c){t.current.type!=="IDLE"&&I(),t.current={type:"PENDING",point:c,actions:d},u()},[u]);_e(function(){return o(),function(){r.current()}},[o])}var Dr;function G2(){}var q2=(Dr={},Dr[M2]=!0,Dr[L2]=!0,Dr[F2]=!0,Dr[B2]=!0,Dr);function Q2(e,t){function r(){t(),e.cancel()}function n(){t(),e.drop()}return[{eventName:"keydown",fn:function(o){if(o.keyCode===Ks){o.preventDefault(),r();return}if(o.keyCode===$g){o.preventDefault(),n();return}if(o.keyCode===U2){o.preventDefault(),e.moveDown();return}if(o.keyCode===z2){o.preventDefault(),e.moveUp();return}if(o.keyCode===$2){o.preventDefault(),e.moveRight();return}if(o.keyCode===j2){o.preventDefault(),e.moveLeft();return}if(q2[o.keyCode]){o.preventDefault();return}Ug(o)}},{eventName:"mousedown",fn:r},{eventName:"mouseup",fn:r},{eventName:"click",fn:r},{eventName:"touchstart",fn:r},{eventName:"resize",fn:r},{eventName:"wheel",fn:r,options:{passive:!0}},{eventName:Il,fn:r}]}function K2(e){var t=E.useRef(G2),r=$(function(){return{eventName:"keydown",fn:function(o){if(o.defaultPrevented||o.keyCode!==$g)return;var l=e.findClosestDraggableId(o);if(!l)return;var a=e.tryGetLock(l,f,{sourceEvent:o});if(!a)return;o.preventDefault();var u=!0,s=a.snapLift();t.current();function f(){u||I(),u=!1,t.current(),n()}t.current=et(window,Q2(s,f),{capture:!0,passive:!1})}}},[e]),n=A(function(){var o={passive:!1,capture:!0};t.current=et(window,[r],o)},[r]);_e(function(){return n(),function(){t.current()}},[n])}var wa={type:"IDLE"},Y2=120,X2=.15;function Z2(e){var t=e.cancel,r=e.getPhase;return[{eventName:"orientationchange",fn:t},{eventName:"resize",fn:t},{eventName:"contextmenu",fn:function(i){i.preventDefault()}},{eventName:"keydown",fn:function(i){if(r().type!=="DRAGGING"){t();return}i.keyCode===Ks&&i.preventDefault(),t()}},{eventName:Il,fn:t}]}function J2(e){var t=e.cancel,r=e.completed,n=e.getPhase;return[{eventName:"touchmove",options:{capture:!1},fn:function(o){var l=n();if(l.type!=="DRAGGING"){t();return}l.hasMoved=!0;var a=o.touches[0],u=a.clientX,s=a.clientY,f={x:u,y:s};o.preventDefault(),l.actions.move(f)}},{eventName:"touchend",fn:function(o){var l=n();if(l.type!=="DRAGGING"){t();return}o.preventDefault(),l.actions.drop({shouldBlockNextClick:!0}),r()}},{eventName:"touchcancel",fn:function(o){if(n().type!=="DRAGGING"){t();return}o.preventDefault(),t()}},{eventName:"touchforcechange",fn:function(o){var l=n();l.type==="IDLE"&&I();var a=o.touches[0];if(a){var u=a.force>=X2;if(u){var s=l.actions.shouldRespectForcePress();if(l.type==="PENDING"){s&&t();return}if(s){if(l.hasMoved){o.preventDefault();return}t();return}o.preventDefault()}}}},{eventName:Il,fn:t}]}function ex(e){var t=E.useRef(wa),r=E.useRef(Qt),n=A(function(){return t.current},[]),i=A(function(p){t.current=p},[]),o=$(function(){return{eventName:"touchstart",fn:function(p){if(!p.defaultPrevented){var m=e.findClosestDraggableId(p);if(m){var y=e.tryGetLock(m,a,{sourceEvent:p});if(y){var w=p.touches[0],g=w.clientX,v=w.clientY,h={x:g,y:v};r.current(),d(y,h)}}}}}},[e]),l=A(function(){var p={capture:!0,passive:!1};r.current=et(window,[o],p)},[o]),a=A(function(){var c=t.current;c.type!=="IDLE"&&(c.type==="PENDING"&&clearTimeout(c.longPressTimerId),i(wa),r.current(),l())},[l,i]),u=A(function(){var c=t.current;a(),c.type==="DRAGGING"&&c.actions.cancel({shouldBlockNextClick:!0}),c.type==="PENDING"&&c.actions.abort()},[a]),s=A(function(){var p={capture:!0,passive:!1},m={cancel:u,completed:a,getPhase:n},y=et(window,J2(m),p),w=et(window,Z2(m),p);r.current=function(){y(),w()}},[u,n,a]),f=A(function(){var p=n();p.type!=="PENDING"&&I();var m=p.actions.fluidLift(p.point);i({type:"DRAGGING",actions:m,hasMoved:!1})},[n,i]),d=A(function(p,m){n().type!=="IDLE"&&I();var y=setTimeout(f,Y2);i({type:"PENDING",point:m,actions:p,longPressTimerId:y}),s()},[s,n,i,f]);_e(function(){return l(),function(){r.current();var m=n();m.type==="PENDING"&&(clearTimeout(m.longPressTimerId),i(wa))}},[n,l,i]),_e(function(){var p=et(window,[{eventName:"touchmove",fn:function(){},options:{capture:!1,passive:!1}}]);return p},[])}var tx={input:!0,button:!0,textarea:!0,select:!0,option:!0,optgroup:!0,video:!0,audio:!0};function Wg(e,t){if(t==null)return!1;var r=!!tx[t.tagName.toLowerCase()];if(r)return!0;var n=t.getAttribute("contenteditable");return n==="true"||n===""?!0:t===e?!1:Wg(e,t.parentElement)}function rx(e,t){var r=t.target;return Dl(r)?Wg(e,r):!1}var nx=function(e){return st(e.getBoundingClientRect()).center};function ix(e){return e instanceof jg(e).Element}var ox=function(){var e="matches";if(typeof document>"u")return e;var t=[e,"msMatchesSelector","webkitMatchesSelector"],r=or(t,function(n){return n in Element.prototype});return r||e}();function Hg(e,t){return e==null?null:e[ox](t)?e:Hg(e.parentElement,t)}function lx(e,t){return e.closest?e.closest(t):Hg(e,t)}function ax(e){return"["+tn.contextId+'="'+e+'"]'}function ux(e,t){var r=t.target;if(!ix(r))return null;var n=ax(e),i=lx(r,n);return!i||!Dl(i)?null:i}function sx(e,t){var r=ux(e,t);return r?r.getAttribute(tn.draggableId):null}function cx(e,t){var r="["+Su.contextId+'="'+e+'"]',n=lg(document.querySelectorAll(r)),i=or(n,function(o){return o.getAttribute(Su.id)===t});return!i||!Dl(i)?null:i}function dx(e){e.preventDefault()}function qi(e){var t=e.expected,r=e.phase,n=e.isLockActive;return e.shouldWarn,!(!n()||t!==r)}function Vg(e){var t=e.lockAPI,r=e.store,n=e.registry,i=e.draggableId;if(t.isClaimed())return!1;var o=n.draggable.findById(i);return!(!o||!o.options.isEnabled||!Lg(r.getState(),i))}function fx(e){var t=e.lockAPI,r=e.contextId,n=e.store,i=e.registry,o=e.draggableId,l=e.forceSensorStop,a=e.sourceEvent,u=Vg({lockAPI:t,store:n,registry:i,draggableId:o});if(!u)return null;var s=i.draggable.getById(o),f=cx(r,s.descriptor.id);if(!f||a&&!s.options.canDragInteractiveElements&&rx(f,a))return null;var d=t.claim(l||Qt),c="PRE_DRAG";function p(){return s.options.shouldRespectForcePress}function m(){return t.isActive(d)}function y(C,P){qi({expected:C,phase:c,isLockActive:m,shouldWarn:!0})&&n.dispatch(P())}var w=y.bind(null,"DRAGGING");function g(C){function P(){t.release(),c="COMPLETED"}c!=="PRE_DRAG"&&(P(),c!=="PRE_DRAG"&&I()),n.dispatch(oS(C.liftActionArgs)),c="DRAGGING";function N(T,k){if(k===void 0&&(k={shouldBlockNextClick:!1}),C.cleanup(),k.shouldBlockNextClick){var F=et(window,[{eventName:"click",fn:dx,options:{once:!0,passive:!1,capture:!0}}]);setTimeout(F)}P(),n.dispatch(Ig({reason:T}))}return L({isActive:function(){return qi({expected:"DRAGGING",phase:c,isLockActive:m,shouldWarn:!1})},shouldRespectForcePress:p,drop:function(k){return N("DROP",k)},cancel:function(k){return N("CANCEL",k)}},C.actions)}function v(C){var P=ni(function(T){w(function(){return Pg({client:T})})}),N=g({liftActionArgs:{id:o,clientSelection:C,movementMode:"FLUID"},cleanup:function(){return P.cancel()},actions:{move:P}});return L({},N,{move:P})}function h(){var C={moveUp:function(){return w(vS)},moveRight:function(){return w(mS)},moveDown:function(){return w(gS)},moveLeft:function(){return w(hS)}};return g({liftActionArgs:{id:o,clientSelection:nx(f),movementMode:"SNAP"},cleanup:Qt,actions:C})}function S(){var C=qi({expected:"PRE_DRAG",phase:c,isLockActive:m,shouldWarn:!0});C&&t.release()}var x={isActive:function(){return qi({expected:"PRE_DRAG",phase:c,isLockActive:m,shouldWarn:!1})},shouldRespectForcePress:p,fluidLift:v,snapLift:h,abort:S};return x}var px=[V2,K2,ex];function vx(e){var t=e.contextId,r=e.store,n=e.registry,i=e.customSensors,o=e.enableDefaultSensors,l=[].concat(o?px:[],i||[]),a=E.useState(function(){return k2()})[0],u=A(function(v,h){v.isDragging&&!h.isDragging&&a.tryAbandon()},[a]);_e(function(){var v=r.getState(),h=r.subscribe(function(){var S=r.getState();u(v,S),v=S});return h},[a,r,u]),_e(function(){return a.tryAbandon},[a.tryAbandon]);for(var s=A(function(g){return Vg({lockAPI:a,registry:n,store:r,draggableId:g})},[a,n,r]),f=A(function(g,v,h){return fx({lockAPI:a,registry:n,contextId:t,store:r,draggableId:g,forceSensorStop:v,sourceEvent:h&&h.sourceEvent?h.sourceEvent:null})},[t,a,n,r]),d=A(function(g){return sx(t,g)},[t]),c=A(function(g){var v=n.draggable.findById(g);return v?v.options:null},[n.draggable]),p=A(function(){a.isClaimed()&&(a.tryAbandon(),r.getState().phase!=="IDLE"&&r.dispatch(zs()))},[a,r]),m=A(a.isClaimed,[a]),y=$(function(){return{canGetLock:s,tryGetLock:f,findClosestDraggableId:d,findOptionsForDraggable:c,tryReleaseLock:p,isLockClaimed:m}},[s,f,d,c,p,m]),w=0;w{const{apps:e}=ln(),{favoriteApps:t,setFavoriteApps:r}=vi(),[n,i]=E.useState([]);E.useEffect(()=>{let u=[];const s=Object.entries(t).filter(([c,{favorite:p}])=>p).map(([c,{order:p}])=>({...e.find(m=>m.package_name===c),order:p})).filter(c=>c),f=s.filter(c=>c.order!==void 0&&c.order!==null),d=s.filter(c=>c.order===void 0||c.order===null);for(let c=0;cc),d.forEach(c=>u.push(c)),i(u)},[e,t]);const o=ir(),l=(u,s,f)=>{const d=Array.from(u),[c]=d.splice(s,1);return d.splice(f,0,c),d},a=u=>{if(!u.destination)return;const f=l(n,u.source.index,u.destination.index).map(c=>c.package_name),d={...t};f.forEach((c,p)=>{d[c].order=p}),r(d),console.log({favoriteApps:t}),fetch(Pn("/order"),{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(f)}).catch(c=>console.error(c))};return b.jsx(wx,{onDragEnd:a,children:b.jsx(Xg,{droppableId:"droppable",direction:"horizontal",children:(u,s)=>b.jsxs("div",{ref:u.innerRef,...u.droppableProps,className:Te("flex-center flex-wrap border border-orange bg-orange/25 p-2 rounded !rounded-xl",{"gap-8":!o&&n.length>0,"gap-4":!o&&n.length===0,"mb-4":!o,"gap-4 mb-2":o,"flex-col":n.length===0}),children:[n.map(f=>b.jsx(rE,{draggableId:f.package_name,index:n.indexOf(f),children:(d,c)=>b.jsx("div",{ref:d.innerRef,...d.draggableProps,...d.dragHandleProps,children:b.jsx(Av,{app:f})})},f.package_name)),u.placeholder,n.length===0&&b.jsx("div",{children:"Favorite an app to pin it to your dock."})]})})})},sE=({expanded:e})=>{const{apps:t}=ln(),r=ir();return b.jsx("div",{className:Te("flex-center flex-wrap overflow-y-auto fixed h-screen w-screen backdrop-blur-md transition transition-all ease-in-out duration-500",{"top-[100vh]":!e,"top-0":e,"gap-4 p-8":r,"gap-8 p-16":!r}),children:t.length===0?b.jsx("div",{children:"Loading apps..."}):t.map(n=>b.jsx(Av,{app:n},n.package_name))})},cE=({package_name:e,widget:t,forceLarge:r})=>{var c,p,m,y,w;const{apps:n}=ln(),{widgetSettings:i,toggleWidgetVisibility:o}=vi(),[l,a]=E.useState(!1),u=ir(),s=r||((c=i[e])==null?void 0:c.size)==="large",f=!((p=i[e])!=null&&p.size)||((m=i[e])==null?void 0:m.size)==="small",d=window.innerHeight>window.innerWidth;return b.jsxs("div",{className:Te("self-stretch flex-col-center shadow-lg rounded-lg relative",{"max-w-1/2 min-w-1/2":s&&!u,"min-w-1/4":f&&!u,"max-w-1/4":f&&!d,"w-full":u}),onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),children:[b.jsx("h6",{className:"flex-center my-2",children:((y=n.find(g=>g.package_name===e))==null?void 0:y.label)||e}),b.jsx("iframe",{srcDoc:t||"",className:"grow self-stretch","data-widget-code":t}),l&&b.jsx("button",{className:"absolute top-0 left-0 icon",onClick:()=>o(e),children:(w=i[e])!=null&&w.hide?b.jsx(E0,{}):b.jsx(x0,{})})]})},dE=()=>{const{apps:e}=ln(),{widgetSettings:t}=vi(),r=ir();return b.jsx("div",{className:Te("flex-center flex-wrap flex-grow self-stretch",{"gap-2 m-2":r,"gap-4 m-4":!r}),children:e.filter(n=>n.widget).map(({widget:n,package_name:i},o,l)=>{var a;return!((a=t[i])!=null&&a.hide)&&b.jsx(cE,{package_name:i,widget:n,forceLarge:l.length===1},i)})})},fE=({title:e,onClose:t,children:r})=>{const n=ir();return b.jsx("div",{className:"flex fixed top-0 left-0 w-full h-full bg-black bg-opacity-50 place-items-center place-content-center backdrop-blur-md",children:b.jsxs("div",{className:Te("flex flex-col rounded-lg bg-black py-4 shadow-lg max-h-screen overflow-y-auto",{"min-w-[500px] px-8 w-1/2":!n,"px-4 w-full":n}),children:[b.jsxs("div",{className:"flex",children:[b.jsx("h1",{className:"grow",children:e}),b.jsx("button",{className:"icon self-start",onClick:t,children:b.jsx(D0,{})})]}),r]})})},pE=()=>{const{apps:e,setShowWidgetsSettings:t}=ln(),{widgetSettings:r,toggleWidgetVisibility:n,setWidgetSize:i}=vi();return b.jsx(fE,{title:"Widget Settings",onClose:()=>t(!1),children:b.jsxs("div",{className:"flex-col-center gap-4 mt-4",children:[e.filter(o=>o.widget).map(({label:o,package_name:l})=>{var a,u,s,f;return b.jsxs("div",{className:"flex items-start bg-white/10 rounded p-2 self-stretch",children:[b.jsx("h4",{className:"mr-4 grow",children:o}),b.jsxs("div",{className:"flex flex-col gap-4 grow",children:[b.jsxs("div",{className:"flex-center gap-2",children:[b.jsx("span",{children:"Show widget"}),b.jsxs("div",{className:"flex relative grow",children:[b.jsx("input",{type:"checkbox",checked:!((a=r[l])!=null&&a.hide),onChange:()=>n(l),autoFocus:!0}),!((u=r[l])!=null&&u.hide)&&b.jsx("span",{onClick:()=>n(l),className:"checkmark",children:"✓"})]})]}),b.jsxs("div",{className:"flex-center gap-2",children:[b.jsx("span",{children:"Widget size"}),b.jsxs("div",{className:"flex-center grow",children:[b.jsx("button",{className:Te({clear:((s=r[l])==null?void 0:s.size)==="large"}),onClick:()=>i(l,"small"),children:"Small"}),b.jsx("button",{className:Te({clear:((f=r[l])==null?void 0:f.size)!=="large"}),onClick:()=>i(l,"large"),children:"Large"})]})]})]})]})}),b.jsx("button",{className:"clear",onClick:()=>window.location.href="/settings:settings:sys",children:"Looking for system settings?"})]})})},vE="/assets/valet-icon-COgctyxf.png";function gE(){const[e,t]=E.useState(""),[r,n]=E.useState(""),[i,o]=E.useState(!1),{setApps:l,isHosted:a,fetchHostedStatus:u,showWidgetsSettings:s,setShowWidgetsSettings:f}=ln(),d=ir(),c=()=>{Promise.all([fetch(Pn("/apps"),{credentials:"include"}).then(p=>p.json()).catch(()=>[]),fetch(Pn("/main:app_store:sys/apps"),{credentials:"include"}).then(p=>p.json()).catch(()=>[]),fetch(Pn("/version"),{credentials:"include"}).then(p=>p.text()).catch(()=>"")]).then(([p,m,y])=>{n(y);const w=p.map(g=>({...g,is_favorite:!1}));m.forEach(g=>{const v=w.findIndex(h=>h.package_name===g.package);v===-1?w.push({package_name:g.package,path:"",label:g.package,state:g.state,is_favorite:!1}):w[v]={...w[v],state:g.state}}),l(w);for(let g=0;g<5&&w.find(v=>v.package_name==="app_store"&&!v.base64_icon);g++)c()})};return E.useEffect(()=>{c()},[e]),E.useEffect(()=>{fetch(Pn("/our"),{credentials:"include"}).then(p=>p.text()).then(p=>{p.match(/^[a-zA-Z0-9\-\.]+\.[a-zA-Z]+$/)&&(t(p),u(p))})},[e]),b.jsxs("div",{className:Te("flex-col-center relative w-screen overflow-hidden special-bg-homepage min-h-screen",{}),children:[b.jsxs("h5",{className:Te("absolute flex gap-4 c",{"top-8 left-8 right-8":!d,"top-2 left-2 right-2":d}),children:[a&&b.jsx("img",{src:vE,className:"!w-12 !h-12 !p-1 button icon object-cover",onClick:()=>window.location.href="https://valet.kinode.org/"}),b.jsx("span",{children:e}),b.jsxs("span",{className:"bg-white/10 rounded p-1",children:["v",r]}),b.jsx("button",{className:"icon ml-auto",onClick:()=>f(!0),children:b.jsx(b0,{})})]}),d?b.jsxs("div",{className:"flex-center gap-4 p-8 mt-8 max-w-screen",children:[b.jsx(cd,{}),b.jsx(sd,{})]}):b.jsxs("div",{className:Te("flex-col-center mx-0 gap-4 mt-8 mb-4"),children:[b.jsx("h3",{className:"text-center",children:"Welcome to"}),b.jsx(sd,{}),b.jsx(cd,{})]}),b.jsx(uE,{}),b.jsx(dE,{}),b.jsxs("button",{className:Te("fixed alt clear flex-center self-center z-20",{"bottom-2 right-2":d,"bottom-8 right-8":!d}),onClick:()=>o(!i),children:[i?b.jsx(w0,{}):b.jsx(S0,{}),b.jsx("span",{className:"ml-2",children:i?"Collapse":"All apps"})]}),b.jsx(sE,{expanded:i}),s&&b.jsx(pE,{})]})}/** + `}},l=[n,r,i,o];return{always:Sn(l,"always"),resting:Sn(l,"resting"),dragging:Sn(l,"dragging"),dropAnimating:Sn(l,"dropAnimating"),userCancel:Sn(l,"userCancel")}},_e=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u"?E.useLayoutEffect:E.useEffect,ya=function(){var t=document.querySelector("head");return t||I(),t},Kd=function(t){var r=document.createElement("style");return t&&r.setAttribute("nonce",t),r.type="text/css",r};function w2(e,t){var r=$(function(){return y2(e)},[e]),n=E.useRef(null),i=E.useRef(null),o=A(ce(function(d){var c=i.current;c||I(),c.textContent=d}),[]),l=A(function(d){var c=n.current;c||I(),c.textContent=d},[]);_e(function(){!n.current&&!i.current||I();var d=Kd(t),c=Kd(t);return n.current=d,i.current=c,d.setAttribute(en+"-always",e),c.setAttribute(en+"-dynamic",e),ya().appendChild(d),ya().appendChild(c),l(r.always),o(r.resting),function(){var p=function(y){var w=y.current;w||I(),ya().removeChild(w),y.current=null};p(n),p(i)}},[t,l,o,r.always,r.resting,e]);var a=A(function(){return o(r.dragging)},[o,r.dragging]),u=A(function(d){if(d==="DROP"){o(r.dropAnimating);return}o(r.userCancel)},[o,r.dropAnimating,r.userCancel]),s=A(function(){i.current&&o(r.resting)},[o,r.resting]),f=$(function(){return{dragging:a,dropping:u,resting:s}},[a,u,s]);return f}var jg=function(e){return e&&e.ownerDocument?e.ownerDocument.defaultView:window};function Dl(e){return e instanceof jg(e).HTMLElement}function S2(e,t){var r="["+tn.contextId+'="'+e+'"]',n=lg(document.querySelectorAll(r));if(!n.length)return null;var i=or(n,function(o){return o.getAttribute(tn.draggableId)===t});return!i||!Dl(i)?null:i}function x2(e){var t=E.useRef({}),r=E.useRef(null),n=E.useRef(null),i=E.useRef(!1),o=A(function(c,p){var m={id:c,focus:p};return t.current[c]=m,function(){var w=t.current,g=w[c];g!==m&&delete w[c]}},[]),l=A(function(c){var p=S2(e,c);p&&p!==document.activeElement&&p.focus()},[e]),a=A(function(c,p){r.current===c&&(r.current=p)},[]),u=A(function(){n.current||i.current&&(n.current=requestAnimationFrame(function(){n.current=null;var c=r.current;c&&l(c)}))},[l]),s=A(function(c){r.current=null;var p=document.activeElement;p&&p.getAttribute(tn.draggableId)===c&&(r.current=c)},[]);_e(function(){return i.current=!0,function(){i.current=!1;var c=n.current;c&&cancelAnimationFrame(c)}},[]);var f=$(function(){return{register:o,tryRecordFocus:s,tryRestoreFocusRecorded:u,tryShiftRecord:a}},[o,s,u,a]);return f}function E2(){var e={draggables:{},droppables:{}},t=[];function r(d){return t.push(d),function(){var p=t.indexOf(d);p!==-1&&t.splice(p,1)}}function n(d){t.length&&t.forEach(function(c){return c(d)})}function i(d){return e.draggables[d]||null}function o(d){var c=i(d);return c||I(),c}var l={register:function(c){e.draggables[c.descriptor.id]=c,n({type:"ADDITION",value:c})},update:function(c,p){var m=e.draggables[p.descriptor.id];m&&m.uniqueId===c.uniqueId&&(delete e.draggables[p.descriptor.id],e.draggables[c.descriptor.id]=c)},unregister:function(c){var p=c.descriptor.id,m=i(p);m&&c.uniqueId===m.uniqueId&&(delete e.draggables[p],n({type:"REMOVAL",value:c}))},getById:o,findById:i,exists:function(c){return!!i(c)},getAllByType:function(c){return $o(e.draggables).filter(function(p){return p.descriptor.type===c})}};function a(d){return e.droppables[d]||null}function u(d){var c=a(d);return c||I(),c}var s={register:function(c){e.droppables[c.descriptor.id]=c},unregister:function(c){var p=a(c.descriptor.id);p&&c.uniqueId===p.uniqueId&&delete e.droppables[c.descriptor.id]},getById:u,findById:a,exists:function(c){return!!a(c)},getAllByType:function(c){return $o(e.droppables).filter(function(p){return p.descriptor.type===c})}};function f(){e.draggables={},e.droppables={},t.length=0}return{draggable:l,droppable:s,subscribe:r,clean:f}}function C2(){var e=$(E2,[]);return E.useEffect(function(){return function(){requestAnimationFrame(e.clean)}},[e]),e}var qs=z.createContext(null),_o=function(){var e=document.body;return e||I(),e},b2={position:"absolute",width:"1px",height:"1px",margin:"-1px",border:"0",padding:"0",overflow:"hidden",clip:"rect(0 0 0 0)","clip-path":"inset(100%)"},D2=function(t){return"rbd-announcement-"+t};function P2(e){var t=$(function(){return D2(e)},[e]),r=E.useRef(null);E.useEffect(function(){var o=document.createElement("div");return r.current=o,o.id=t,o.setAttribute("aria-live","assertive"),o.setAttribute("aria-atomic","true"),L(o.style,b2),_o().appendChild(o),function(){setTimeout(function(){var u=_o();u.contains(o)&&u.removeChild(o),o===r.current&&(r.current=null)})}},[t]);var n=A(function(i){var o=r.current;if(o){o.textContent=i;return}},[]);return n}var I2=0,N2={separator:"::"};function Qs(e,t){return t===void 0&&(t=N2),$(function(){return""+e+t.separator+I2++},[t.separator,e])}function O2(e){var t=e.contextId,r=e.uniqueId;return"rbd-hidden-text-"+t+"-"+r}function R2(e){var t=e.contextId,r=e.text,n=Qs("hidden-text",{separator:"-"}),i=$(function(){return O2({contextId:t,uniqueId:n})},[n,t]);return E.useEffect(function(){var l=document.createElement("div");return l.id=i,l.textContent=r,l.style.display="none",_o().appendChild(l),function(){var u=_o();u.contains(l)&&u.removeChild(l)}},[i,r]),i}var Pl=z.createContext(null);function zg(e){var t=E.useRef(e);return E.useEffect(function(){t.current=e}),t}function k2(){var e=null;function t(){return!!e}function r(l){return l===e}function n(l){e&&I();var a={abandon:l};return e=a,a}function i(){e||I(),e=null}function o(){e&&(e.abandon(),i())}return{isClaimed:t,isActive:r,claim:n,release:i,tryAbandon:o}}var T2=9,A2=13,Ks=27,$g=32,L2=33,M2=34,B2=35,F2=36,j2=37,z2=38,$2=39,U2=40,Gi,_2=(Gi={},Gi[A2]=!0,Gi[T2]=!0,Gi),Ug=function(e){_2[e.keyCode]&&e.preventDefault()},Il=function(){var e="visibilitychange";if(typeof document>"u")return e;var t=[e,"ms"+e,"webkit"+e,"moz"+e,"o"+e],r=or(t,function(n){return"on"+n in document});return r||e}(),_g=0,Yd=5;function W2(e,t){return Math.abs(t.x-e.x)>=Yd||Math.abs(t.y-e.y)>=Yd}var Xd={type:"IDLE"};function H2(e){var t=e.cancel,r=e.completed,n=e.getPhase,i=e.setPhase;return[{eventName:"mousemove",fn:function(l){var a=l.button,u=l.clientX,s=l.clientY;if(a===_g){var f={x:u,y:s},d=n();if(d.type==="DRAGGING"){l.preventDefault(),d.actions.move(f);return}d.type!=="PENDING"&&I();var c=d.point;if(W2(c,f)){l.preventDefault();var p=d.actions.fluidLift(f);i({type:"DRAGGING",actions:p})}}}},{eventName:"mouseup",fn:function(l){var a=n();if(a.type!=="DRAGGING"){t();return}l.preventDefault(),a.actions.drop({shouldBlockNextClick:!0}),r()}},{eventName:"mousedown",fn:function(l){n().type==="DRAGGING"&&l.preventDefault(),t()}},{eventName:"keydown",fn:function(l){var a=n();if(a.type==="PENDING"){t();return}if(l.keyCode===Ks){l.preventDefault(),t();return}Ug(l)}},{eventName:"resize",fn:t},{eventName:"scroll",options:{passive:!0,capture:!1},fn:function(){n().type==="PENDING"&&t()}},{eventName:"webkitmouseforcedown",fn:function(l){var a=n();if(a.type==="IDLE"&&I(),a.actions.shouldRespectForcePress()){t();return}l.preventDefault()}},{eventName:Il,fn:t}]}function V2(e){var t=E.useRef(Xd),r=E.useRef(Qt),n=$(function(){return{eventName:"mousedown",fn:function(d){if(!d.defaultPrevented&&d.button===_g&&!(d.ctrlKey||d.metaKey||d.shiftKey||d.altKey)){var c=e.findClosestDraggableId(d);if(c){var p=e.tryGetLock(c,l,{sourceEvent:d});if(p){d.preventDefault();var m={x:d.clientX,y:d.clientY};r.current(),s(p,m)}}}}}},[e]),i=$(function(){return{eventName:"webkitmouseforcewillbegin",fn:function(d){if(!d.defaultPrevented){var c=e.findClosestDraggableId(d);if(c){var p=e.findOptionsForDraggable(c);p&&(p.shouldRespectForcePress||e.canGetLock(c)&&d.preventDefault())}}}}},[e]),o=A(function(){var d={passive:!1,capture:!0};r.current=et(window,[i,n],d)},[i,n]),l=A(function(){var f=t.current;f.type!=="IDLE"&&(t.current=Xd,r.current(),o())},[o]),a=A(function(){var f=t.current;l(),f.type==="DRAGGING"&&f.actions.cancel({shouldBlockNextClick:!0}),f.type==="PENDING"&&f.actions.abort()},[l]),u=A(function(){var d={capture:!0,passive:!1},c=H2({cancel:a,completed:l,getPhase:function(){return t.current},setPhase:function(m){t.current=m}});r.current=et(window,c,d)},[a,l]),s=A(function(d,c){t.current.type!=="IDLE"&&I(),t.current={type:"PENDING",point:c,actions:d},u()},[u]);_e(function(){return o(),function(){r.current()}},[o])}var Dr;function G2(){}var q2=(Dr={},Dr[M2]=!0,Dr[L2]=!0,Dr[F2]=!0,Dr[B2]=!0,Dr);function Q2(e,t){function r(){t(),e.cancel()}function n(){t(),e.drop()}return[{eventName:"keydown",fn:function(o){if(o.keyCode===Ks){o.preventDefault(),r();return}if(o.keyCode===$g){o.preventDefault(),n();return}if(o.keyCode===U2){o.preventDefault(),e.moveDown();return}if(o.keyCode===z2){o.preventDefault(),e.moveUp();return}if(o.keyCode===$2){o.preventDefault(),e.moveRight();return}if(o.keyCode===j2){o.preventDefault(),e.moveLeft();return}if(q2[o.keyCode]){o.preventDefault();return}Ug(o)}},{eventName:"mousedown",fn:r},{eventName:"mouseup",fn:r},{eventName:"click",fn:r},{eventName:"touchstart",fn:r},{eventName:"resize",fn:r},{eventName:"wheel",fn:r,options:{passive:!0}},{eventName:Il,fn:r}]}function K2(e){var t=E.useRef(G2),r=$(function(){return{eventName:"keydown",fn:function(o){if(o.defaultPrevented||o.keyCode!==$g)return;var l=e.findClosestDraggableId(o);if(!l)return;var a=e.tryGetLock(l,f,{sourceEvent:o});if(!a)return;o.preventDefault();var u=!0,s=a.snapLift();t.current();function f(){u||I(),u=!1,t.current(),n()}t.current=et(window,Q2(s,f),{capture:!0,passive:!1})}}},[e]),n=A(function(){var o={passive:!1,capture:!0};t.current=et(window,[r],o)},[r]);_e(function(){return n(),function(){t.current()}},[n])}var wa={type:"IDLE"},Y2=120,X2=.15;function Z2(e){var t=e.cancel,r=e.getPhase;return[{eventName:"orientationchange",fn:t},{eventName:"resize",fn:t},{eventName:"contextmenu",fn:function(i){i.preventDefault()}},{eventName:"keydown",fn:function(i){if(r().type!=="DRAGGING"){t();return}i.keyCode===Ks&&i.preventDefault(),t()}},{eventName:Il,fn:t}]}function J2(e){var t=e.cancel,r=e.completed,n=e.getPhase;return[{eventName:"touchmove",options:{capture:!1},fn:function(o){var l=n();if(l.type!=="DRAGGING"){t();return}l.hasMoved=!0;var a=o.touches[0],u=a.clientX,s=a.clientY,f={x:u,y:s};o.preventDefault(),l.actions.move(f)}},{eventName:"touchend",fn:function(o){var l=n();if(l.type!=="DRAGGING"){t();return}o.preventDefault(),l.actions.drop({shouldBlockNextClick:!0}),r()}},{eventName:"touchcancel",fn:function(o){if(n().type!=="DRAGGING"){t();return}o.preventDefault(),t()}},{eventName:"touchforcechange",fn:function(o){var l=n();l.type==="IDLE"&&I();var a=o.touches[0];if(a){var u=a.force>=X2;if(u){var s=l.actions.shouldRespectForcePress();if(l.type==="PENDING"){s&&t();return}if(s){if(l.hasMoved){o.preventDefault();return}t();return}o.preventDefault()}}}},{eventName:Il,fn:t}]}function ex(e){var t=E.useRef(wa),r=E.useRef(Qt),n=A(function(){return t.current},[]),i=A(function(p){t.current=p},[]),o=$(function(){return{eventName:"touchstart",fn:function(p){if(!p.defaultPrevented){var m=e.findClosestDraggableId(p);if(m){var y=e.tryGetLock(m,a,{sourceEvent:p});if(y){var w=p.touches[0],g=w.clientX,v=w.clientY,h={x:g,y:v};r.current(),d(y,h)}}}}}},[e]),l=A(function(){var p={capture:!0,passive:!1};r.current=et(window,[o],p)},[o]),a=A(function(){var c=t.current;c.type!=="IDLE"&&(c.type==="PENDING"&&clearTimeout(c.longPressTimerId),i(wa),r.current(),l())},[l,i]),u=A(function(){var c=t.current;a(),c.type==="DRAGGING"&&c.actions.cancel({shouldBlockNextClick:!0}),c.type==="PENDING"&&c.actions.abort()},[a]),s=A(function(){var p={capture:!0,passive:!1},m={cancel:u,completed:a,getPhase:n},y=et(window,J2(m),p),w=et(window,Z2(m),p);r.current=function(){y(),w()}},[u,n,a]),f=A(function(){var p=n();p.type!=="PENDING"&&I();var m=p.actions.fluidLift(p.point);i({type:"DRAGGING",actions:m,hasMoved:!1})},[n,i]),d=A(function(p,m){n().type!=="IDLE"&&I();var y=setTimeout(f,Y2);i({type:"PENDING",point:m,actions:p,longPressTimerId:y}),s()},[s,n,i,f]);_e(function(){return l(),function(){r.current();var m=n();m.type==="PENDING"&&(clearTimeout(m.longPressTimerId),i(wa))}},[n,l,i]),_e(function(){var p=et(window,[{eventName:"touchmove",fn:function(){},options:{capture:!1,passive:!1}}]);return p},[])}var tx={input:!0,button:!0,textarea:!0,select:!0,option:!0,optgroup:!0,video:!0,audio:!0};function Wg(e,t){if(t==null)return!1;var r=!!tx[t.tagName.toLowerCase()];if(r)return!0;var n=t.getAttribute("contenteditable");return n==="true"||n===""?!0:t===e?!1:Wg(e,t.parentElement)}function rx(e,t){var r=t.target;return Dl(r)?Wg(e,r):!1}var nx=function(e){return st(e.getBoundingClientRect()).center};function ix(e){return e instanceof jg(e).Element}var ox=function(){var e="matches";if(typeof document>"u")return e;var t=[e,"msMatchesSelector","webkitMatchesSelector"],r=or(t,function(n){return n in Element.prototype});return r||e}();function Hg(e,t){return e==null?null:e[ox](t)?e:Hg(e.parentElement,t)}function lx(e,t){return e.closest?e.closest(t):Hg(e,t)}function ax(e){return"["+tn.contextId+'="'+e+'"]'}function ux(e,t){var r=t.target;if(!ix(r))return null;var n=ax(e),i=lx(r,n);return!i||!Dl(i)?null:i}function sx(e,t){var r=ux(e,t);return r?r.getAttribute(tn.draggableId):null}function cx(e,t){var r="["+Su.contextId+'="'+e+'"]',n=lg(document.querySelectorAll(r)),i=or(n,function(o){return o.getAttribute(Su.id)===t});return!i||!Dl(i)?null:i}function dx(e){e.preventDefault()}function qi(e){var t=e.expected,r=e.phase,n=e.isLockActive;return e.shouldWarn,!(!n()||t!==r)}function Vg(e){var t=e.lockAPI,r=e.store,n=e.registry,i=e.draggableId;if(t.isClaimed())return!1;var o=n.draggable.findById(i);return!(!o||!o.options.isEnabled||!Lg(r.getState(),i))}function fx(e){var t=e.lockAPI,r=e.contextId,n=e.store,i=e.registry,o=e.draggableId,l=e.forceSensorStop,a=e.sourceEvent,u=Vg({lockAPI:t,store:n,registry:i,draggableId:o});if(!u)return null;var s=i.draggable.getById(o),f=cx(r,s.descriptor.id);if(!f||a&&!s.options.canDragInteractiveElements&&rx(f,a))return null;var d=t.claim(l||Qt),c="PRE_DRAG";function p(){return s.options.shouldRespectForcePress}function m(){return t.isActive(d)}function y(C,P){qi({expected:C,phase:c,isLockActive:m,shouldWarn:!0})&&n.dispatch(P())}var w=y.bind(null,"DRAGGING");function g(C){function P(){t.release(),c="COMPLETED"}c!=="PRE_DRAG"&&(P(),c!=="PRE_DRAG"&&I()),n.dispatch(oS(C.liftActionArgs)),c="DRAGGING";function N(T,k){if(k===void 0&&(k={shouldBlockNextClick:!1}),C.cleanup(),k.shouldBlockNextClick){var F=et(window,[{eventName:"click",fn:dx,options:{once:!0,passive:!1,capture:!0}}]);setTimeout(F)}P(),n.dispatch(Ig({reason:T}))}return L({isActive:function(){return qi({expected:"DRAGGING",phase:c,isLockActive:m,shouldWarn:!1})},shouldRespectForcePress:p,drop:function(k){return N("DROP",k)},cancel:function(k){return N("CANCEL",k)}},C.actions)}function v(C){var P=ni(function(T){w(function(){return Pg({client:T})})}),N=g({liftActionArgs:{id:o,clientSelection:C,movementMode:"FLUID"},cleanup:function(){return P.cancel()},actions:{move:P}});return L({},N,{move:P})}function h(){var C={moveUp:function(){return w(vS)},moveRight:function(){return w(mS)},moveDown:function(){return w(gS)},moveLeft:function(){return w(hS)}};return g({liftActionArgs:{id:o,clientSelection:nx(f),movementMode:"SNAP"},cleanup:Qt,actions:C})}function S(){var C=qi({expected:"PRE_DRAG",phase:c,isLockActive:m,shouldWarn:!0});C&&t.release()}var x={isActive:function(){return qi({expected:"PRE_DRAG",phase:c,isLockActive:m,shouldWarn:!1})},shouldRespectForcePress:p,fluidLift:v,snapLift:h,abort:S};return x}var px=[V2,K2,ex];function vx(e){var t=e.contextId,r=e.store,n=e.registry,i=e.customSensors,o=e.enableDefaultSensors,l=[].concat(o?px:[],i||[]),a=E.useState(function(){return k2()})[0],u=A(function(v,h){v.isDragging&&!h.isDragging&&a.tryAbandon()},[a]);_e(function(){var v=r.getState(),h=r.subscribe(function(){var S=r.getState();u(v,S),v=S});return h},[a,r,u]),_e(function(){return a.tryAbandon},[a.tryAbandon]);for(var s=A(function(g){return Vg({lockAPI:a,registry:n,store:r,draggableId:g})},[a,n,r]),f=A(function(g,v,h){return fx({lockAPI:a,registry:n,contextId:t,store:r,draggableId:g,forceSensorStop:v,sourceEvent:h&&h.sourceEvent?h.sourceEvent:null})},[t,a,n,r]),d=A(function(g){return sx(t,g)},[t]),c=A(function(g){var v=n.draggable.findById(g);return v?v.options:null},[n.draggable]),p=A(function(){a.isClaimed()&&(a.tryAbandon(),r.getState().phase!=="IDLE"&&r.dispatch(zs()))},[a,r]),m=A(a.isClaimed,[a]),y=$(function(){return{canGetLock:s,tryGetLock:f,findClosestDraggableId:d,findOptionsForDraggable:c,tryReleaseLock:p,isLockClaimed:m}},[s,f,d,c,p,m]),w=0;w{const{apps:e}=ln(),{favoriteApps:t,setFavoriteApps:r}=vi(),[n,i]=E.useState([]);E.useEffect(()=>{let u=[];const s=Object.entries(t).filter(([c,{favorite:p}])=>p).map(([c,{order:p}])=>({...e.find(m=>m.package_name===c),order:p})).filter(c=>c),f=s.filter(c=>c.order!==void 0&&c.order!==null),d=s.filter(c=>c.order===void 0||c.order===null);for(let c=0;cc),d.forEach(c=>u.push(c)),i(u)},[e,t]);const o=ir(),l=(u,s,f)=>{const d=Array.from(u),[c]=d.splice(s,1);return d.splice(f,0,c),d},a=u=>{if(!u.destination)return;const f=l(n,u.source.index,u.destination.index).map(c=>c.package_name),d={...t};f.forEach((c,p)=>{d[c].order=p}),r(d),console.log({favoriteApps:t}),fetch(Pn("/order"),{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(f)}).catch(c=>console.error(c))};return b.jsx(wx,{onDragEnd:a,children:b.jsx(Xg,{droppableId:"droppable",direction:"horizontal",children:(u,s)=>b.jsxs("div",{ref:u.innerRef,...u.droppableProps,className:Te("flex-center flex-wrap border border-orange bg-orange/25 p-2 rounded !rounded-xl",{"gap-8":!o&&n.length>0,"gap-4":!o&&n.length===0,"mb-4":!o,"gap-4 mb-2":o,"flex-col":n.length===0}),children:[n.map(f=>b.jsx(rE,{draggableId:f.package_name,index:n.indexOf(f),children:(d,c)=>b.jsx("div",{ref:d.innerRef,...d.draggableProps,...d.dragHandleProps,children:b.jsx(Av,{app:f})})},f.package_name)),u.placeholder,n.length===0&&b.jsx("div",{children:"Favorite an app to pin it to your dock."})]})})})},sE=({expanded:e})=>{const{apps:t}=ln(),r=ir();return b.jsx("div",{className:Te("flex-center flex-wrap overflow-y-auto fixed h-screen w-screen backdrop-blur-md transition transition-all ease-in-out duration-500",{"top-[100vh]":!e,"top-0":e,"gap-4 p-8":r,"gap-8 p-16":!r}),children:t.length===0?b.jsx("div",{children:"Loading apps..."}):t.map(n=>b.jsx(Av,{app:n},n.package_name))})},cE=({package_name:e,widget:t,forceLarge:r})=>{var p,m,y,w,g;const{apps:n}=ln(),{widgetSettings:i,toggleWidgetVisibility:o}=vi(),[l,a]=E.useState(!1),u=ir(),s=r||((p=i[e])==null?void 0:p.size)==="large",f=!((m=i[e])!=null&&m.size)||((y=i[e])==null?void 0:y.size)==="small",[d,c]=E.useState(window.innerHeight>window.innerWidth);return E.useEffect(()=>{c(window.innerHeight>window.innerWidth)},[window.innerHeight,window.innerWidth]),b.jsxs("div",{className:Te("self-stretch flex-col-center shadow-lg rounded-lg relative",{"max-w-1/2 min-w-1/2":s&&!u,"min-w-1/4":f&&!u,"max-w-1/4":f&&!d,"w-full":u}),onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),children:[b.jsx("h6",{className:"flex-center my-2",children:((w=n.find(v=>v.package_name===e))==null?void 0:w.label)||e}),b.jsx("iframe",{srcDoc:t||"",className:"grow self-stretch","data-widget-code":t}),l&&b.jsx("button",{className:"absolute top-0 left-0 icon",onClick:()=>o(e),children:(g=i[e])!=null&&g.hide?b.jsx(E0,{}):b.jsx(x0,{})})]})},dE=()=>{const{apps:e}=ln(),{widgetSettings:t}=vi(),r=ir();return b.jsx("div",{className:Te("flex-center flex-wrap flex-grow self-stretch",{"gap-2 m-2":r,"gap-4 m-4":!r}),children:e.filter(n=>n.widget).map(({widget:n,package_name:i},o,l)=>{var a;return!((a=t[i])!=null&&a.hide)&&b.jsx(cE,{package_name:i,widget:n,forceLarge:l.length===1},i)})})},fE=({title:e,onClose:t,children:r})=>{const n=ir();return b.jsx("div",{className:"flex fixed top-0 left-0 w-full h-full bg-black bg-opacity-50 place-items-center place-content-center backdrop-blur-md",children:b.jsxs("div",{className:Te("flex flex-col rounded-lg bg-black py-4 shadow-lg max-h-screen overflow-y-auto",{"min-w-[500px] px-8 w-1/2":!n,"px-4 w-full":n}),children:[b.jsxs("div",{className:"flex",children:[b.jsx("h1",{className:"grow",children:e}),b.jsx("button",{className:"icon self-start",onClick:t,children:b.jsx(D0,{})})]}),r]})})},pE=()=>{const{apps:e,setShowWidgetsSettings:t}=ln(),{widgetSettings:r,toggleWidgetVisibility:n,setWidgetSize:i}=vi();return b.jsx(fE,{title:"Widget Settings",onClose:()=>t(!1),children:b.jsxs("div",{className:"flex-col-center gap-4 mt-4",children:[e.filter(o=>o.widget).map(({label:o,package_name:l})=>{var a,u,s,f;return b.jsxs("div",{className:"flex items-start bg-white/10 rounded p-2 self-stretch",children:[b.jsx("h4",{className:"mr-4 grow",children:o}),b.jsxs("div",{className:"flex flex-col gap-4 grow",children:[b.jsxs("div",{className:"flex-center gap-2",children:[b.jsx("span",{children:"Show widget"}),b.jsxs("div",{className:"flex relative grow",children:[b.jsx("input",{type:"checkbox",checked:!((a=r[l])!=null&&a.hide),onChange:()=>n(l),autoFocus:!0}),!((u=r[l])!=null&&u.hide)&&b.jsx("span",{onClick:()=>n(l),className:"checkmark",children:"✓"})]})]}),b.jsxs("div",{className:"flex-center gap-2",children:[b.jsx("span",{children:"Widget size"}),b.jsxs("div",{className:"flex-center grow",children:[b.jsx("button",{className:Te({clear:((s=r[l])==null?void 0:s.size)==="large"}),onClick:()=>i(l,"small"),children:"Small"}),b.jsx("button",{className:Te({clear:((f=r[l])==null?void 0:f.size)!=="large"}),onClick:()=>i(l,"large"),children:"Large"})]})]})]})]})}),b.jsx("button",{className:"clear",onClick:()=>window.location.href="/settings:settings:sys",children:"Looking for system settings?"})]})})},vE="/assets/valet-icon-COgctyxf.png";function gE(){const[e,t]=E.useState(""),[r,n]=E.useState(""),[i,o]=E.useState(!1),{setApps:l,isHosted:a,fetchHostedStatus:u,showWidgetsSettings:s,setShowWidgetsSettings:f}=ln(),d=ir(),c=()=>{Promise.all([fetch(Pn("/apps"),{credentials:"include"}).then(p=>p.json()).catch(()=>[]),fetch(Pn("/main:app_store:sys/apps"),{credentials:"include"}).then(p=>p.json()).catch(()=>[]),fetch(Pn("/version"),{credentials:"include"}).then(p=>p.text()).catch(()=>"")]).then(([p,m,y])=>{n(y);const w=p.map(g=>({...g,is_favorite:!1}));m.forEach(g=>{const v=w.findIndex(h=>h.package_name===g.package);v===-1?w.push({package_name:g.package,path:"",label:g.package,state:g.state,is_favorite:!1}):w[v]={...w[v],state:g.state}}),l(w);for(let g=0;g<5&&w.find(v=>v.package_name==="app_store"&&!v.base64_icon);g++)c()})};return E.useEffect(()=>{c()},[e]),E.useEffect(()=>{fetch(Pn("/our"),{credentials:"include"}).then(p=>p.text()).then(p=>{p.match(/^[a-zA-Z0-9\-\.]+\.[a-zA-Z]+$/)&&(t(p),u(p))})},[e]),b.jsxs("div",{className:Te("flex-col-center relative w-screen overflow-hidden special-bg-homepage min-h-screen",{}),children:[b.jsxs("h5",{className:Te("absolute flex gap-4 c",{"top-8 left-8 right-8":!d,"top-2 left-2 right-2":d}),children:[a&&b.jsx("img",{src:vE,className:"!w-12 !h-12 !p-1 button icon object-cover",onClick:()=>window.location.href="https://valet.kinode.org/"}),b.jsx("span",{children:e}),b.jsxs("span",{className:"bg-white/10 rounded p-1",children:["v",r]}),b.jsx("button",{className:"icon ml-auto",onClick:()=>f(!0),children:b.jsx(b0,{})})]}),d?b.jsxs("div",{className:"flex-center gap-4 p-8 mt-8 max-w-screen",children:[b.jsx(cd,{}),b.jsx(sd,{})]}):b.jsxs("div",{className:Te("flex-col-center mx-0 gap-4 mt-8 mb-4"),children:[b.jsx("h3",{className:"text-center",children:"Welcome to"}),b.jsx(sd,{}),b.jsx(cd,{})]}),b.jsx(uE,{}),b.jsx(dE,{}),b.jsxs("button",{className:Te("fixed alt clear flex-center self-center z-20",{"bottom-2 right-2":d,"bottom-8 right-8":!d}),onClick:()=>o(!i),children:[i?b.jsx(w0,{}):b.jsx(S0,{}),b.jsx("span",{className:"ml-2",children:i?"Collapse":"All apps"})]}),b.jsx(sE,{expanded:i}),s&&b.jsx(pE,{})]})}/** * @remix-run/router v1.16.0 * * Copyright (c) Remix Software Inc. diff --git a/kinode/packages/homepage/pkg/ui/index.html b/kinode/packages/homepage/pkg/ui/index.html index 654bbb19d..a2dddcadb 100644 --- a/kinode/packages/homepage/pkg/ui/index.html +++ b/kinode/packages/homepage/pkg/ui/index.html @@ -9,7 +9,7 @@ - + diff --git a/kinode/packages/homepage/ui/dist/index.html b/kinode/packages/homepage/ui/dist/index.html index 654bbb19d..a2dddcadb 100644 --- a/kinode/packages/homepage/ui/dist/index.html +++ b/kinode/packages/homepage/ui/dist/index.html @@ -9,7 +9,7 @@ - + diff --git a/kinode/packages/homepage/ui/src/components/AppDisplay.tsx b/kinode/packages/homepage/ui/src/components/AppDisplay.tsx index cd38a731e..05749cbcf 100644 --- a/kinode/packages/homepage/ui/src/components/AppDisplay.tsx +++ b/kinode/packages/homepage/ui/src/components/AppDisplay.tsx @@ -38,7 +38,7 @@ const AppDisplay: React.FC = ({ app }) => { size={'small'} className="h-16 w-16" />} -
{app?.label}
+
{app?.label || app?.package_name}
{app?.path && isHovered &&
); diff --git a/kinode/packages/app_store/ui/src/components/UpdateButton.tsx b/kinode/packages/app_store/ui/src/components/UpdateButton.tsx index f58ec7b6a..605cfcd4a 100644 --- a/kinode/packages/app_store/ui/src/components/UpdateButton.tsx +++ b/kinode/packages/app_store/ui/src/components/UpdateButton.tsx @@ -5,7 +5,7 @@ import Modal from "./Modal"; import { getAppName } from "../utils/app"; import Loader from "./Loader"; import classNames from "classnames"; -import { FaU } from "react-icons/fa6"; +import { FaExclamation } from "react-icons/fa6"; interface UpdateButtonProps extends React.HTMLAttributes { app: AppInfo; @@ -61,7 +61,7 @@ export default function UpdateButton({ app, isIcon = false, ...props }: UpdateBu })} onClick={onClick} > - {isIcon ? : 'Update'} + {isIcon ? : 'Update'} setShowModal(false)}> {loading ? ( diff --git a/kinode/packages/app_store/ui/src/pages/MyAppsPage.tsx b/kinode/packages/app_store/ui/src/pages/MyAppsPage.tsx index b350bd5e6..7c004add0 100644 --- a/kinode/packages/app_store/ui/src/pages/MyAppsPage.tsx +++ b/kinode/packages/app_store/ui/src/pages/MyAppsPage.tsx @@ -63,11 +63,11 @@ export default function MyAppsPage() { // eslint-disable-line 'gap-4 max-w-screen': isMobile, 'gap-8 max-w-[900px]': !isMobile, })}> - + {!isMobile && }

My Packages

- diff --git a/kinode/packages/app_store/ui/src/pages/StorePage.tsx b/kinode/packages/app_store/ui/src/pages/StorePage.tsx index 2f3b1d32a..4875a0ff3 100644 --- a/kinode/packages/app_store/ui/src/pages/StorePage.tsx +++ b/kinode/packages/app_store/ui/src/pages/StorePage.tsx @@ -11,6 +11,8 @@ import classNames from 'classnames'; import { FaArrowRotateRight } from "react-icons/fa6"; import { isMobileCheck } from "../utils/dimensions"; import HomeButton from "../components/HomeButton"; +import Modal from "../components/Modal"; +import Loader from "../components/Loader"; interface StorePageProps extends PageProps { } @@ -24,6 +26,7 @@ export default function StorePage() { const [page, setPage] = useState(1); const [tags, setTags] = useState([]) const [launchPaths, setLaunchPaths] = useState<{ [package_name: string]: string }>({}) + const [isRebuildingIndex, setIsRebuildingIndex] = useState(false); const pages = useMemo( () => @@ -97,12 +100,18 @@ export default function StorePage() { ); const tryRebuildIndex = useCallback(async () => { + if (!window.confirm('Are you sure you want to rebuild the app index? This may take a few seconds.')) { + return; + } + + setIsRebuildingIndex(true); try { await rebuildIndex(); - alert("Index rebuilt successfully."); await getListedApps(); } catch (error) { console.error(error); + } finally { + setIsRebuildingIndex(false); } }, [rebuildIndex]); @@ -127,6 +136,7 @@ export default function StorePage() { return (
@@ -174,41 +184,44 @@ export default function StorePage() {
{!searchQuery &&

Featured Apps

{listedApps.filter(app => { return featuredPackageNames.indexOf(app.package) !== -1 }).map((app) => ( ))}
} -

{searchQuery ? 'Search Results' : 'All Apps'}

-
{searchQuery ? 'Search Results' : 'All Apps'} +
{displayedApps .filter(app => searchQuery ? true : featuredPackageNames.indexOf(app.package) === -1) .map(app => )}
{pages.length > 1 &&
@@ -234,6 +247,9 @@ export default function StorePage() {
} + { }}> + +
); } diff --git a/kinode/packages/app_store/ui/vite.config.ts b/kinode/packages/app_store/ui/vite.config.ts index f8c8742c8..5fb5a6401 100644 --- a/kinode/packages/app_store/ui/vite.config.ts +++ b/kinode/packages/app_store/ui/vite.config.ts @@ -82,6 +82,11 @@ export default defineConfig({ target: PROXY_URL, changeOrigin: true, }, + '/api/*': { + target: PROXY_URL, + changeOrigin: true, + rewrite: (path) => path.replace('/api', ''), + }, // '/example': { // target: PROXY_URL, // changeOrigin: true, diff --git a/kinode/packages/chess/chess/Cargo.lock b/kinode/packages/chess/chess/Cargo.lock index b5f3d9b29..f980bbf59 100644 --- a/kinode/packages/chess/chess/Cargo.lock +++ b/kinode/packages/chess/chess/Cargo.lock @@ -222,13 +222,8 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "kinode_process_lib" -<<<<<<< HEAD:modules/chess/chess/Cargo.lock version = "0.5.7" source = "git+https://github.com/kinode-dao/process_lib?tag=v0.5.9-alpha#c1ac7227951fbd8cabf6568704f0ce11e8558c8a" -======= -version = "0.5.6" -source = "git+https://github.com/kinode-dao/process_lib?rev=fccb6a0#fccb6a0c07ebda3e385bff7f76e4984b741f01c7" ->>>>>>> develop:kinode/packages/chess/chess/Cargo.lock dependencies = [ "anyhow", "bincode", diff --git a/kinode/packages/settings/settings/Cargo.lock b/kinode/packages/settings/settings/Cargo.lock index b5f3d9b29..f980bbf59 100644 --- a/kinode/packages/settings/settings/Cargo.lock +++ b/kinode/packages/settings/settings/Cargo.lock @@ -222,13 +222,8 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "kinode_process_lib" -<<<<<<< HEAD:modules/chess/chess/Cargo.lock version = "0.5.7" source = "git+https://github.com/kinode-dao/process_lib?tag=v0.5.9-alpha#c1ac7227951fbd8cabf6568704f0ce11e8558c8a" -======= -version = "0.5.6" -source = "git+https://github.com/kinode-dao/process_lib?rev=fccb6a0#fccb6a0c07ebda3e385bff7f76e4984b741f01c7" ->>>>>>> develop:kinode/packages/chess/chess/Cargo.lock dependencies = [ "anyhow", "bincode", From b05a0e1640ec14ac10040d5bdd0c7f3114e9112f Mon Sep 17 00:00:00 2001 From: Tobias Merkle Date: Thu, 20 Jun 2024 14:09:15 -0400 Subject: [PATCH 35/53] add screensize meta tags for kinoupdates and appstore widgets; remove quickhide widget button; resize mobile modals --- .../app_store/app_store/src/http_api.rs | 5 ++- .../{index--ISnU8mD.js => index-B8jjW9yS.js} | 16 +++---- .../pkg/ui/assets/index-x8quY1Q7.css | 1 - .../pkg/ui/assets/index-zU7UyELC.css | 1 + kinode/packages/app_store/pkg/ui/index.html | 4 +- .../app_store/ui/src/components/Modal.tsx | 12 +++++- .../{index-BLQ3kP3C.js => index-DRR7woJo.js} | 42 +++++++++---------- kinode/packages/homepage/pkg/ui/index.html | 2 +- kinode/packages/homepage/ui/dist/index.html | 2 +- .../homepage/ui/src/components/Widget.tsx | 12 +----- .../packages/kino_updates/widget/src/lib.rs | 1 + 11 files changed, 49 insertions(+), 49 deletions(-) rename kinode/packages/app_store/pkg/ui/assets/{index--ISnU8mD.js => index-B8jjW9yS.js} (83%) delete mode 100644 kinode/packages/app_store/pkg/ui/assets/index-x8quY1Q7.css create mode 100644 kinode/packages/app_store/pkg/ui/assets/index-zU7UyELC.css rename kinode/packages/homepage/pkg/ui/assets/{index-BLQ3kP3C.js => index-DRR7woJo.js} (79%) diff --git a/kinode/packages/app_store/app_store/src/http_api.rs b/kinode/packages/app_store/app_store/src/http_api.rs index 0630cb748..f449f589f 100644 --- a/kinode/packages/app_store/app_store/src/http_api.rs +++ b/kinode/packages/app_store/app_store/src/http_api.rs @@ -60,6 +60,7 @@ pub fn init_frontend(our: &Address) { fn make_widget() -> String { return r#" +