Compare commits

...

9 Commits

Author SHA1 Message Date
ffb05e3a0a [clippy] fix clippy issues 2025-06-25 21:18:36 +02:00
8fda4f79ed [code] Mutex -> RwLock 2025-06-25 21:16:39 +02:00
f16d8b1dca [deps] cargo update
Adding   match_token         v0.1.0
Removing itoa                v0.4.8
Removing thin-slice          v0.1.1
Updating brotli-decompressor v4.0.3  -> v5.0.0
Updating brotli              v7.0.0  -> v8.0.1
Updating bumpalo             v3.18.1 -> v3.19.0
Updating cssparser           v0.27.2 -> v0.29.6
Updating html5ever           v0.26.0 -> v0.29.1
Updating kuchikiki           v0.8.2  -> v0.8.8-speedreader
Updating libredox            v0.1.3  -> v0.1.4
Updating markup5ever         v0.11.0 -> v0.14.1
Updating mdns-sd             v0.13.9 -> v0.13.10
Updating num_enum_derive     v0.7.3  -> v0.7.4
Updating num_enum            v0.7.3  -> v0.7.4
Updating phf_codegen         v0.10.0 -> v0.11.3
Updating phf_macros          v0.8.0  -> v0.10.0
Updating selectors           v0.22.0 -> v0.24.0
Updating servo_arc           v0.1.1  -> v0.2.0
Updating tao                 v0.33.0 -> v0.34.0
Updating tauri-build         v2.2.0  -> v2.3.0
Updating tauri-codegen       v2.2.0  -> v2.3.0
Updating tauri-macros        v2.2.0  -> v2.3.0
Updating tauri-plugin-dialog v2.2.2  -> v2.3.0
Updating tauri-plugin-fs     v2.3.0  -> v2.4.0
Updating tauri-plugin-log    v2.5.0  -> v2.6.0
Updating tauri-plugin-shell  v2.2.2  -> v2.3.0
Updating tauri-plugin-store  v2.2.1  -> v2.3.0
Updating tauri-plugin        v2.2.0  -> v2.3.0
Updating tauri-runtime       v2.6.0  -> v2.7.0
Updating tauri-runtime-wry   v2.6.0  -> v2.7.0
Updating tauri-utils         v2.4.0  -> v2.5.0
Updating tauri               v2.5.1  -> v2.6.0
Updating webview2-com-sys    v0.37.0 -> v0.38.0
Updating webview2-com        v0.37.0 -> v0.38.0
Updating wry                 v0.51.2 -> v0.52.0
2025-06-25 20:42:40 +02:00
7566c2908f [deps] cargo update
Adding   dispatch2                v0.3.0
Adding   getrandom                v0.2.16
Adding   getrandom                v0.3.3
Adding   icu_locale_core          v2.0.0
Adding   iri-string               v0.7.8
Adding   once_cell_polyfill       v1.70.1
Adding   potential_utf            v0.1.2
Adding   ref-cast-impl            v1.0.24
Adding   ref-cast                 v1.0.24
Adding   schemars                 v0.9.0
Adding   sigchld                  v0.2.3
Adding   signal-hook              v0.3.18
Adding   toml_write               v0.1.2
Adding   tower-http               v0.6.6
Adding   windows-core             v0.61.2
Adding   windows-future           v0.2.1
Adding   windows-strings          v0.4.2
Adding   windows-targets          v0.53.2
Adding   windows-threading        v0.1.0
Adding   windows                  v0.61.3
Adding   zerocopy-derive          v0.8.26
Adding   zerocopy                 v0.8.26
Adding   zerotrie                 v0.2.2
Removing getrandom                v0.2.15
Removing getrandom                v0.3.2
Removing icu_locid_transform_data v1.5.0
Removing icu_locid_transform      v1.5.0
Removing icu_locid                v1.5.0
Removing icu_provider_macros      v1.5.0
Removing utf16_iter               v1.0.5
Removing windows_aarch64_gnullvm  v0.48.5
Removing windows_aarch64_msvc     v0.48.5
Removing windows-collections      v0.1.1
Removing windows-core             v0.52.0
Removing windows-core             v0.60.1
Removing windows-core             v0.61.0
Removing windows-future           v0.1.1
Removing windows-future           v0.2.0
Removing windows_i686_gnu         v0.48.5
Removing windows_i686_msvc        v0.48.5
Removing windows-implement        v0.59.0
Removing windows-numerics         v0.1.1
Removing windows-registry         v0.4.0
Removing windows-strings          v0.3.1
Removing windows-strings          v0.4.0
Removing windows-targets          v0.48.5
Removing windows-targets          v0.53.0
Removing windows                  v0.60.0
Removing windows                  v0.61.1
Removing windows_x86_64_gnullvm   v0.48.5
Removing windows_x86_64_gnu       v0.48.5
Removing windows_x86_64_msvc      v0.48.5
Removing write16                  v1.0.0
Removing xdg-home                 v1.3.0
Removing zerocopy-derive          v0.7.35
Removing zerocopy-derive          v0.8.24
Removing zerocopy                 v0.7.35
Removing zerocopy                 v0.8.24
Updating adler2                   v2.0.0                         -> v2.0.1
Updating anstream                 v0.6.18                        -> v0.6.19
Updating anstyle-parse            v0.2.6                         -> v0.2.7
Updating anstyle-query            v1.1.2                         -> v1.1.3
Updating anstyle                  v1.0.10                        -> v1.0.11
Updating anstyle-wincon           v3.0.7                         -> v3.0.9
Updating anyhow                   v1.0.97                        -> v1.0.98
Updating autocfg                  v1.4.0                         -> v1.5.0
Updating aws-lc-rs                v1.12.6                        -> v1.13.1
Updating aws-lc-sys               v0.27.1                        -> v0.29.0
Updating backtrace                v0.3.74                        -> v0.3.75
Updating bitflags                 v2.9.0                         -> v2.9.1
Updating block2                   v0.6.0                         -> v0.6.1
Updating borsh-derive             v1.5.6                         -> v1.5.7
Updating borsh                    v1.5.6                         -> v1.5.7
Updating brotli-decompressor      v4.0.2                         -> v4.0.3
Updating bumpalo                  v3.17.0                        -> v3.18.1
Updating bytemuck                 v1.22.0                        -> v1.23.1
Updating camino                   v1.1.9                         -> v1.1.10
Updating cc                       v1.2.17                        -> v1.2.27
Updating cfg-if                   v1.0.0                         -> v1.0.1
Updating chrono                   v0.4.40                        -> v0.4.41
Updating clap_builder             v4.5.32                        -> v4.5.40
Updating clap_derive              v4.5.32                        -> v4.5.40
Updating clap_lex                 v0.7.4                         -> v0.7.5
Updating clap                     v4.5.32                        -> v4.5.40
Updating colorchoice              v1.0.3                         -> v1.0.4
Updating core-foundation          v0.10.0                        -> v0.10.1
Updating crc                      v3.2.1                         -> v3.3.0
Updating crossbeam-channel        v0.5.14                        -> v0.5.15
Updating darling_core             v0.20.10                       -> v0.20.11
Updating darling_macro            v0.20.10                       -> v0.20.11
Updating darling                  v0.20.10                       -> v0.20.11
Updating derive_more              v0.99.19                       -> v0.99.20
Updating dlopen2_derive           v0.4.0                         -> v0.4.1
Updating dpi                      v0.1.1                         -> v0.1.2
Updating embed-resource           v3.0.2                         -> v3.0.4
Updating enumflags2_derive        v0.7.11                        -> v0.7.12
Updating enumflags2               v0.7.11                        -> v0.7.12
Updating errno                    v0.3.10                        -> v0.3.13
Updating event-listener-strategy  v0.5.3                         -> v0.5.4
Updating flate2                   v1.1.0                         -> v1.1.2
Updating gethostname              v1.0.0                         -> v1.0.2
Updating hashbrown                v0.15.2                        -> v0.15.4
Updating hash_hasher              v2.0.3                         -> v2.0.4
Updating hyper-util               v0.1.10                        -> v0.1.14
Updating iana-time-zone           v0.1.61                        -> v0.1.63
Updating icu_collections          v1.5.0                         -> v2.0.0
Updating icu_normalizer_data      v1.5.0                         -> v2.0.0
Updating icu_normalizer           v1.5.0                         -> v2.0.0
Updating icu_properties_data      v1.5.0                         -> v2.0.1
Updating icu_properties           v1.5.1                         -> v2.0.1
Updating icu_provider             v1.5.0                         -> v2.0.0
Updating idna_adapter             v1.2.0                         -> v1.2.1
Updating indexmap                 v2.8.0                         -> v2.9.0
Updating jobserver                v0.1.32                        -> v0.1.33
Updating libc                     v0.2.171                       -> v0.2.174
Updating libloading               v0.8.6                         -> v0.8.8
Updating libm                     v0.2.11                        -> v0.2.15
Updating linux-raw-sys            v0.9.3                         -> v0.9.4
Updating litemap                  v0.7.5                         -> v0.8.0
Updating lock_api                 v0.4.12                        -> v0.4.13
Updating log                      v0.4.26                        -> v0.4.27
Updating mdns-sd                  v0.13.3                        -> v0.13.9
Updating memchr                   v2.7.4                         -> v2.7.5
Updating miniz_oxide              v0.8.5                         -> v0.8.9
Updating mio                      v1.0.3                         -> v1.0.4
Updating nix                      v0.29.0                        -> v0.30.1
Updating objc2-app-kit            v0.3.0                         -> v0.3.1
Updating objc2-cloud-kit          v0.3.0                         -> v0.3.1
Updating objc2-core-data          v0.3.0                         -> v0.3.1
Updating objc2-core-foundation    v0.3.0                         -> v0.3.1
Updating objc2-core-graphics      v0.3.0                         -> v0.3.1
Updating objc2-core-image         v0.3.0                         -> v0.3.1
Updating objc2-foundation         v0.3.0                         -> v0.3.1
Updating objc2-io-surface         v0.3.0                         -> v0.3.1
Updating objc2-quartz-core        v0.3.0                         -> v0.3.1
Updating objc2-ui-kit             v0.3.0                         -> v0.3.1
Updating objc2                    v0.6.0                         -> v0.6.1
Updating objc2-web-kit            v0.3.0                         -> v0.3.1
Updating once_cell                v1.21.1                        -> v1.21.3
Updating os_pipe                  v1.2.1                         -> v1.2.2
Updating parking_lot_core         v0.9.10                        -> v0.9.11
Updating parking_lot              v0.12.3                        -> v0.12.4
Updating plist                    v1.7.0                         -> v1.7.2
Updating prettyplease             v0.2.31                        -> v0.2.35
Updating proc-macro2              v1.0.94                        -> v1.0.95
Updating quick-xml                v0.32.0                        -> v0.37.5
Updating rand                     v0.9.0                         -> v0.9.1
Updating redox_syscall            v0.5.10                        -> v0.5.13
Updating r-efi                    v5.2.0                         -> v5.3.0
Updating reqwest                  v0.12.15                       -> v0.12.20
Updating rustc-demangle           v0.1.24                        -> v0.1.25
Updating rust_decimal             v1.37.0                        -> v1.37.2
Updating rustix                   v1.0.3                         -> v1.0.7
Updating rustls-pki-types         v1.11.0                        -> v1.12.0
Updating rustls                   v0.23.25                       -> v0.23.28
Updating rustls-webpki            v0.103.0                       -> v0.103.3
Updating rustversion              v1.0.20                        -> v1.0.21
Updating s2n-codec                v0.55.0                        -> v0.59.0
Updating s2n-quic-core            v0.55.0                        -> v0.59.0
Updating s2n-quic-crypto          v0.55.0                        -> v0.59.0
Updating s2n-quic-platform        v0.55.0                        -> v0.59.0
Updating s2n-quic-rustls          v0.55.0                        -> v0.59.0
Updating s2n-quic-tls-default     v0.55.0                        -> v0.59.0
Updating s2n-quic-tls             v0.55.0                        -> v0.59.0
Updating s2n-quic-transport       v0.55.0                        -> v0.59.0
Updating s2n-quic                 v1.55.0                        -> v1.59.0
Updating s2n-tls-sys              v0.3.14                        -> v0.3.21
Updating s2n-tls                  v0.3.14                        -> v0.3.21
Updating serde_spanned            v0.6.8                         -> v0.6.9
Updating serde_with_macros        v3.12.0                        -> v3.13.0
Updating serde_with               v3.12.0                        -> v3.13.0
Updating sha2                     v0.10.8                        -> v0.10.9
Updating shared_child             v1.0.1                         -> v1.1.0
Updating signal-hook-registry     v1.4.2                         -> v1.4.5
Updating slab                     v0.4.9                         -> v0.4.10
Updating smallvec                 v1.14.0                        -> v1.15.1
Updating socket2                  v0.5.8                         -> v0.5.10
Updating sqlx-core                v0.8.3                         -> v0.8.6
Updating sqlx-macros-core         v0.8.3                         -> v0.8.6
Updating sqlx-macros              v0.8.3                         -> v0.8.6
Updating sqlx-sqlite              v0.8.3                         -> v0.8.6
Updating sqlx                     v0.8.3                         -> v0.8.6
Updating string_cache             v0.8.8                         -> v0.8.9
Updating synstructure             v0.13.1                        -> v0.13.2
Updating syn                      v2.0.100                       -> v2.0.104
Updating tao                      v0.32.8                        -> v0.33.0
Updating tauri-build              v2.1.0                         -> v2.2.0
Updating tauri-codegen            v2.1.0                         -> v2.2.0
Updating tauri-macros             v2.1.0                         -> v2.2.0
Updating tauri-plugin-dialog      v2.2.0                         -> v2.2.2
Updating tauri-plugin-fs          v2.2.0                         -> v2.3.0
Updating tauri-plugin-log         v2.3.1                         -> v2.5.0
Updating tauri-plugin-shell       v2.2.0                         -> v2.2.2
Updating tauri-plugin-store       v2.2.0                         -> v2.2.1
Updating tauri-plugin             v2.1.0                         -> v2.2.0
Updating tauri-runtime            v2.5.0                         -> v2.6.0
Updating tauri-runtime-wry        v2.5.0                         -> v2.6.0
Updating tauri-utils              v2.3.0                         -> v2.4.0
Updating tauri                    v2.4.0                         -> v2.5.1
Updating tauri-winres             v0.3.0                         -> v0.3.1
Updating tempfile                 v3.19.1                        -> v3.20.0
Updating thread_local             v1.1.8                         -> v1.1.9
Updating time-macros              v0.2.21                        -> v0.2.22
Updating time                     v0.3.40                        -> v0.3.41
Updating tinystr                  v0.7.6                         -> v0.8.1
Updating tokio-util               v0.7.14                        -> v0.7.15
Updating tokio                    v1.44.1                        -> v1.45.1
Updating toml_datetime            v0.6.8                         -> v0.6.11
Updating toml_edit                v0.22.24                       -> v0.22.27
Updating toml                     v0.8.20                        -> v0.8.23
Updating tracing-attributes       v0.1.28                        -> v0.1.30
Updating tracing-core             v0.1.33                        -> v0.1.34
Updating tray-icon                v0.20.0                        -> v0.20.1
Updating uuid                     v1.16.0                        -> v1.17.0
Updating value-bag                v1.10.0                        -> v1.11.1
Updating wasi                     v0.11.0+wasi-snapshot-preview1 -> v0.11.1+wasi-snapshot-preview1
Updating webview2-com-sys         v0.36.0                        -> v0.37.0
Updating webview2-com             v0.36.0                        -> v0.37.0
Updating windows-link             v0.1.1                         -> v0.1.3
Updating windows-result           v0.3.2                         -> v0.3.4
Updating windows-sys              v0.48.0                        -> v0.60.2
Updating winnow                   v0.7.4                         -> v0.7.11
Updating winreg                   v0.52.0                        -> v0.55.0
Updating writeable                v0.5.5                         -> v0.6.1
Updating wry                      v0.50.5                        -> v0.51.2
Updating yoke-derive              v0.7.5                         -> v0.8.0
Updating yoke                     v0.7.5                         -> v0.8.0
Updating zbus_macros              v5.5.0                         -> v5.7.1
Updating zbus                     v5.5.0                         -> v5.7.1
Updating zerovec-derive           v0.10.3                        -> v0.11.1
Updating zerovec                  v0.10.4                        -> v0.11.2
Updating zvariant_derive          v5.4.0                         -> v5.5.3
Updating zvariant                 v5.4.0                         -> v5.5.3
2025-06-21 17:47:45 +02:00
89ec65f0d2 [assets] unrar binary for aarch64-apple-darwin 2025-03-22 14:08:52 +01:00
bad6baa9de [deps] cargo update 2025-03-22 13:56:12 +01:00
4369090a53 [debug] change spammy mDNS from debug to trace 2025-03-22 13:55:05 +01:00
1ef5e4d01a [fix] non-windows systems 2025-03-21 10:54:29 +01:00
572beb66f7 [readme] improved 2025-03-21 08:19:49 +01:00
7 changed files with 825 additions and 923 deletions

1676
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -11,8 +11,11 @@ Simple server and GUI for LAN parties.
```bash ```bash
# install Tauri CLI # install Tauri CLI
cargo install tauri-cli cargo install tauri-cli
# install Deno with a package manager or from https://deno.land/
``` ```
### Build ### Build
#### Frontend #### Frontend
```bash ```bash
@ -23,7 +26,7 @@ cargo tauri dev # prefix with RUST_LOG=your_module=debug or similary for more
cargo tauri build --no-bundle cargo tauri build --no-bundle
# Production # Production
cargo tauri build --profile release-lto # also bundles everything into a nice platform-specific installer cargo tauri build -- --profile release-lto # also bundles everything into a nice platform-specific installer
# on wayland you probably need to set this env var # on wayland you probably need to set this env var
WEBKIT_DISABLE_DMABUF_RENDERER=1 WEBKIT_DISABLE_DMABUF_RENDERER=1
@ -38,5 +41,5 @@ deno outdated --update --latest
./server.sh [options...] # prefix with RUST_LOG=your_module=debug or similary for more verbose output ./server.sh [options...] # prefix with RUST_LOG=your_module=debug or similary for more verbose output
# Production # Production
cargo build --profile release-lto cargo build --profile release-lto -p lanspread-server
``` ```

View File

@ -10,7 +10,7 @@ use s2n_quic::{Client as QuicClient, Connection, client::Connect, provider::limi
use tokio::{ use tokio::{
io::AsyncWriteExt, io::AsyncWriteExt,
sync::{ sync::{
Mutex, RwLock,
mpsc::{UnboundedReceiver, UnboundedSender}, mpsc::{UnboundedReceiver, UnboundedSender},
}, },
}; };
@ -162,7 +162,7 @@ async fn download_game_files(
} }
struct Ctx { struct Ctx {
game_dir: Arc<Mutex<Option<String>>>, game_dir: Arc<RwLock<Option<String>>>,
} }
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines)]
@ -181,7 +181,7 @@ pub async fn run(
// client context // client context
let ctx = Ctx { let ctx = Ctx {
game_dir: Arc::new(Mutex::new(None)), game_dir: Arc::new(RwLock::new(None)),
}; };
loop { loop {
@ -230,7 +230,7 @@ pub async fn run(
continue; continue;
} }
ClientCommand::SetGameDir(game_dir) => { ClientCommand::SetGameDir(game_dir) => {
*ctx.game_dir.lock().await = Some(game_dir.clone()); *ctx.game_dir.write().await = Some(game_dir.clone());
continue; continue;
} }
ClientCommand::DownloadGameFiles { ClientCommand::DownloadGameFiles {
@ -239,7 +239,7 @@ pub async fn run(
} => { } => {
log::info!("got ClientCommand::DownloadGameFiles"); log::info!("got ClientCommand::DownloadGameFiles");
let games_folder = { ctx.game_dir.lock().await.clone() }; let games_folder = { ctx.game_dir.read().await.clone() };
if let Some(games_folder) = games_folder { if let Some(games_folder) = games_folder {
let tx_notify_ui = tx_notify_ui.clone(); let tx_notify_ui = tx_notify_ui.clone();
tokio::task::spawn(async move { tokio::task::spawn(async move {
@ -312,7 +312,7 @@ pub async fn run(
let (mut rx, mut tx) = stream.split(); let (mut rx, mut tx) = stream.split();
if let Err(e) = tx.send(data).await { if let Err(e) = tx.send(data).await {
log::error!("failed to send request to server {:?}", e); log::error!("failed to send request to server {e:?}");
} }
let mut data = BytesMut::new(); let mut data = BytesMut::new();
@ -344,7 +344,7 @@ pub async fn run(
file_descriptions.len() file_descriptions.len()
); );
let games_folder = { ctx.game_dir.lock().await.clone() }; let games_folder = { ctx.game_dir.read().await.clone() };
match games_folder { match games_folder {
Some(games_folder) => { Some(games_folder) => {

View File

@ -11,10 +11,7 @@ use gethostname::gethostname;
use lanspread_compat::eti; use lanspread_compat::eti;
use lanspread_db::db::{Game, GameDB}; use lanspread_db::db::{Game, GameDB};
use lanspread_mdns::{ use lanspread_mdns::{
DaemonEvent, DaemonEvent, LANSPREAD_INSTANCE_NAME, LANSPREAD_SERVICE_TYPE, MdnsAdvertiser,
LANSPREAD_INSTANCE_NAME,
LANSPREAD_SERVICE_TYPE,
MdnsAdvertiser,
}; };
use tracing_subscriber::EnvFilter; use tracing_subscriber::EnvFilter;
use uuid::Uuid; use uuid::Uuid;
@ -53,11 +50,10 @@ fn spawn_mdns_task(server_addr: SocketAddr) -> eyre::Result<()> {
tokio::spawn(async move { tokio::spawn(async move {
while let Ok(event) = mdns.monitor.recv() { while let Ok(event) = mdns.monitor.recv() {
tracing::debug!("mDNS: {:?}", &event); tracing::trace!("mDNS: {:?}", &event);
if let DaemonEvent::Error(e) = event { if let DaemonEvent::Error(e) = event {
tracing::error!("mDNS: {e}"); tracing::error!("mDNS: {e}");
tokio::time::sleep(Duration::from_secs(1)).await; tokio::time::sleep(Duration::from_secs(1)).await;
continue;
} }
} }
}); });

View File

@ -171,10 +171,5 @@ fn get_relative_path(base: &Path, deep_path: &Path) -> std::io::Result<PathBuf>
full_canonical full_canonical
.strip_prefix(&base_canonical) .strip_prefix(&base_canonical)
.map(std::path::Path::to_path_buf) .map(std::path::Path::to_path_buf)
.map_err(|_| { .map_err(|_| std::io::Error::other("Path is not within base directory"))
std::io::Error::new(
std::io::ErrorKind::Other,
"Path is not within base directory",
)
})
} }

View File

@ -11,16 +11,16 @@ use lanspread_db::db::{Game, GameDB};
use lanspread_mdns::{LANSPREAD_INSTANCE_NAME, LANSPREAD_SERVICE_TYPE, discover_service}; use lanspread_mdns::{LANSPREAD_INSTANCE_NAME, LANSPREAD_SERVICE_TYPE, discover_service};
use tauri::{AppHandle, Emitter as _, Manager}; use tauri::{AppHandle, Emitter as _, Manager};
use tauri_plugin_shell::{ShellExt, process::Command}; use tauri_plugin_shell::{ShellExt, process::Command};
use tokio::sync::{Mutex, mpsc::UnboundedSender}; use tokio::sync::{Mutex, RwLock, mpsc::UnboundedSender};
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/ // Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
struct LanSpreadState { struct LanSpreadState {
server_addr: Mutex<Option<SocketAddr>>, server_addr: RwLock<Option<SocketAddr>>,
client_ctrl: UnboundedSender<ClientCommand>, client_ctrl: UnboundedSender<ClientCommand>,
games: Arc<Mutex<GameDB>>, games: Arc<RwLock<GameDB>>,
games_in_download: Arc<Mutex<HashSet<String>>>, games_in_download: Arc<Mutex<HashSet<String>>>,
games_folder: Arc<Mutex<String>>, games_folder: Arc<RwLock<String>>,
} }
#[tauri::command] #[tauri::command]
@ -85,7 +85,7 @@ fn run_game_windows(id: String, state: tauri::State<LanSpreadState>) {
const FIRST_START_DONE_FILE: &str = ".softlan_first_start_done"; const FIRST_START_DONE_FILE: &str = ".softlan_first_start_done";
let games_folder = let games_folder =
tauri::async_runtime::block_on(async { state.inner().games_folder.lock().await.clone() }); tauri::async_runtime::block_on(async { state.inner().games_folder.read().await.clone() });
let games_folder = PathBuf::from(games_folder); let games_folder = PathBuf::from(games_folder);
if !games_folder.exists() { if !games_folder.exists() {
@ -143,7 +143,10 @@ fn run_game(id: String, state: tauri::State<LanSpreadState>) {
run_game_windows(id, state); run_game_windows(id, state);
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
log::error!("run_game not implemented for this platform: id={id}, state={state:?}"); {
let _ = state;
log::error!("run_game not implemented for this platform: id={id}");
}
} }
fn set_game_install_state_from_path(game_db: &mut GameDB, path: &Path, installed: bool) { fn set_game_install_state_from_path(game_db: &mut GameDB, path: &Path, installed: bool) {
@ -177,7 +180,7 @@ fn update_game_directory(app_handle: tauri::AppHandle, path: String) {
.state::<LanSpreadState>() .state::<LanSpreadState>()
.inner() .inner()
.games_folder .games_folder
.lock() .write()
.await; .await;
*games_folder = path.clone(); *games_folder = path.clone();
@ -202,7 +205,7 @@ fn update_game_directory(app_handle: tauri::AppHandle, path: String) {
.state::<LanSpreadState>() .state::<LanSpreadState>()
.inner() .inner()
.games .games
.lock() .write()
.await; .await;
// Reset all games to uninstalled // Reset all games to uninstalled
@ -236,11 +239,7 @@ async fn find_server(app: AppHandle) {
Ok(server_addr) => { Ok(server_addr) => {
log::info!("Found server at {server_addr}"); log::info!("Found server at {server_addr}");
let state: tauri::State<LanSpreadState> = app.state(); let state: tauri::State<LanSpreadState> = app.state();
{ *state.server_addr.write().await = Some(server_addr);
// mutex scope
let mut addr = state.server_addr.lock().await;
*addr = Some(server_addr);
}
state state
.client_ctrl .client_ctrl
.send(ClientCommand::ServerAddr(server_addr)) .send(ClientCommand::ServerAddr(server_addr))
@ -263,8 +262,7 @@ async fn update_game_db(games: Vec<Game>, app: AppHandle) {
let state = app.state::<LanSpreadState>(); let state = app.state::<LanSpreadState>();
// Store games list // Store games list
let mut state_games = state.games.lock().await; *state.games.write().await = GameDB::from(games.clone());
*state_games = GameDB::from(games.clone());
// Tell Frontend about new games list // Tell Frontend about new games list
if let Err(e) = app.emit("games-list-updated", Some(games)) { if let Err(e) = app.emit("games-list-updated", Some(games)) {
@ -358,11 +356,11 @@ pub fn run() {
tokio::sync::mpsc::unbounded_channel::<ClientEvent>(); tokio::sync::mpsc::unbounded_channel::<ClientEvent>();
let lanspread_state = LanSpreadState { let lanspread_state = LanSpreadState {
server_addr: Mutex::new(None), server_addr: RwLock::new(None),
client_ctrl: tx_client_control, client_ctrl: tx_client_control,
games: Arc::new(Mutex::new(GameDB::empty())), games: Arc::new(RwLock::new(GameDB::empty())),
games_in_download: Arc::new(Mutex::new(HashSet::new())), games_in_download: Arc::new(Mutex::new(HashSet::new())),
games_folder: Arc::new(Mutex::new("".to_string())), games_folder: Arc::new(RwLock::new("".to_string())),
}; };
tauri::Builder::default() tauri::Builder::default()
@ -448,7 +446,7 @@ pub fn run() {
.state::<LanSpreadState>() .state::<LanSpreadState>()
.inner() .inner()
.games_folder .games_folder
.lock() .read()
.await .await
.clone(); .clone();