clippy: just fix
This commit is contained in:
@@ -838,7 +838,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn parses_unrar_technical_listing() {
|
fn parses_unrar_technical_listing() {
|
||||||
let listing = parse_unrar_listing(
|
let listing = parse_unrar_listing(
|
||||||
r#"
|
r"
|
||||||
Archive: game.eti
|
Archive: game.eti
|
||||||
Details: RAR 5, solid
|
Details: RAR 5, solid
|
||||||
|
|
||||||
@@ -849,7 +849,7 @@ Details: RAR 5, solid
|
|||||||
|
|
||||||
Name: bin
|
Name: bin
|
||||||
Type: Directory
|
Type: Directory
|
||||||
"#,
|
",
|
||||||
)
|
)
|
||||||
.expect("listing should parse");
|
.expect("listing should parse");
|
||||||
|
|
||||||
@@ -876,14 +876,14 @@ Details: RAR 5, solid
|
|||||||
#[test]
|
#[test]
|
||||||
fn rejects_unrar_file_entries_without_crc32() {
|
fn rejects_unrar_file_entries_without_crc32() {
|
||||||
let err = parse_unrar_listing(
|
let err = parse_unrar_listing(
|
||||||
r#"
|
r"
|
||||||
Archive: game.eti
|
Archive: game.eti
|
||||||
Details: RAR 5
|
Details: RAR 5
|
||||||
|
|
||||||
Name: bin/payload.bin
|
Name: bin/payload.bin
|
||||||
Type: File
|
Type: File
|
||||||
Size: 123
|
Size: 123
|
||||||
"#,
|
",
|
||||||
)
|
)
|
||||||
.expect_err("file entries without CRC32 should be rejected");
|
.expect_err("file entries without CRC32 should be rejected");
|
||||||
|
|
||||||
@@ -893,14 +893,14 @@ Details: RAR 5
|
|||||||
#[test]
|
#[test]
|
||||||
fn accepts_zero_size_unrar_file_entries_without_crc32() {
|
fn accepts_zero_size_unrar_file_entries_without_crc32() {
|
||||||
let listing = parse_unrar_listing(
|
let listing = parse_unrar_listing(
|
||||||
r#"
|
r"
|
||||||
Archive: game.eti
|
Archive: game.eti
|
||||||
Details: RAR 5
|
Details: RAR 5
|
||||||
|
|
||||||
Name: bin/empty.cfg
|
Name: bin/empty.cfg
|
||||||
Type: File
|
Type: File
|
||||||
Size: 0
|
Size: 0
|
||||||
"#,
|
",
|
||||||
)
|
)
|
||||||
.expect("empty file without CRC32 should parse as CRC32 zero");
|
.expect("empty file without CRC32 should parse as CRC32 zero");
|
||||||
|
|
||||||
|
|||||||
@@ -2266,6 +2266,82 @@ fn handle_download_finished(app_handle: &AppHandle, id: String) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::missing_panics_doc)]
|
||||||
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
|
pub fn run() {
|
||||||
|
// channel to receive events from the peer
|
||||||
|
let (tx_peer_event, rx_peer_event) = tokio::sync::mpsc::unbounded_channel::<PeerEvent>();
|
||||||
|
|
||||||
|
tauri::Builder::default()
|
||||||
|
.plugin(tauri_plugin_store::Builder::new().build())
|
||||||
|
.plugin(tauri_plugin_dialog::init())
|
||||||
|
.plugin(tauri_plugin_shell::init())
|
||||||
|
.invoke_handler(tauri::generate_handler![
|
||||||
|
request_games,
|
||||||
|
install_game,
|
||||||
|
stream_install_game,
|
||||||
|
run_game,
|
||||||
|
start_server,
|
||||||
|
game_directory_exists,
|
||||||
|
update_game_directory,
|
||||||
|
update_game,
|
||||||
|
uninstall_game,
|
||||||
|
remove_downloaded_game,
|
||||||
|
cancel_download,
|
||||||
|
open_game_files,
|
||||||
|
get_peer_count,
|
||||||
|
get_game_thumbnail,
|
||||||
|
get_unpack_logs,
|
||||||
|
get_main_logs
|
||||||
|
])
|
||||||
|
.manage(LanSpreadState::default())
|
||||||
|
.manage(PeerEventTx(tx_peer_event))
|
||||||
|
.setup(move |app| {
|
||||||
|
let state_dir = app.path().app_data_dir()?;
|
||||||
|
std::fs::create_dir_all(&state_dir)?;
|
||||||
|
let main_log_sink = MainLogSink::new(app.handle().clone(), main_log_path(&state_dir));
|
||||||
|
let state = app.state::<LanSpreadState>();
|
||||||
|
if state.main_log_sink.set(main_log_sink.clone()).is_err() {
|
||||||
|
log::warn!("main log sink was already initialized");
|
||||||
|
}
|
||||||
|
init_main_logging(main_log_sink)?;
|
||||||
|
let unpack_logs = load_unpack_logs(&state_dir);
|
||||||
|
tauri::async_runtime::block_on(async {
|
||||||
|
*state.unpack_logs.write().await = unpack_logs;
|
||||||
|
});
|
||||||
|
if state.state_dir.set(state_dir).is_err() {
|
||||||
|
log::warn!("app state directory was already initialized");
|
||||||
|
}
|
||||||
|
spawn_peer_event_loop(app.handle().clone(), rx_peer_event);
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.build(tauri::generate_context!())
|
||||||
|
.expect("error while building tauri application")
|
||||||
|
.run(|app_handle, event| {
|
||||||
|
if matches!(event, tauri::RunEvent::Exit) {
|
||||||
|
shutdown_peer_runtime(app_handle);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shutdown_peer_runtime(app_handle: &AppHandle) {
|
||||||
|
let state = app_handle.state::<LanSpreadState>();
|
||||||
|
let peer_runtime = state.peer_runtime.clone();
|
||||||
|
|
||||||
|
tauri::async_runtime::block_on(async move {
|
||||||
|
let Some(mut handle) = peer_runtime.write().await.take() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
handle.shutdown();
|
||||||
|
if tokio::time::timeout(std::time::Duration::from_secs(2), handle.wait_stopped())
|
||||||
|
.await
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
|
log::warn!("Peer runtime did not stop within 2s of shutdown request");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -2430,7 +2506,7 @@ mod tests {
|
|||||||
trim_main_log_file_to_limit(&path, 21).expect("main log should trim");
|
trim_main_log_file_to_limit(&path, 21).expect("main log should trim");
|
||||||
|
|
||||||
let trimmed = std::fs::read_to_string(&path).expect("trimmed log should remain utf-8");
|
let trimmed = std::fs::read_to_string(&path).expect("trimmed log should remain utf-8");
|
||||||
assert!(trimmed.as_bytes().len() <= 21);
|
assert!(trimmed.len() <= 21);
|
||||||
assert!(trimmed.starts_with('é'));
|
assert!(trimmed.starts_with('é'));
|
||||||
assert!(trimmed.ends_with('é'));
|
assert!(trimmed.ends_with('é'));
|
||||||
|
|
||||||
@@ -2735,79 +2811,3 @@ mod tests {
|
|||||||
assert!(game_db.get_game_by_id("unknown").is_none());
|
assert!(game_db.get_game_by_id("unknown").is_none());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::missing_panics_doc)]
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
|
||||||
pub fn run() {
|
|
||||||
// channel to receive events from the peer
|
|
||||||
let (tx_peer_event, rx_peer_event) = tokio::sync::mpsc::unbounded_channel::<PeerEvent>();
|
|
||||||
|
|
||||||
tauri::Builder::default()
|
|
||||||
.plugin(tauri_plugin_store::Builder::new().build())
|
|
||||||
.plugin(tauri_plugin_dialog::init())
|
|
||||||
.plugin(tauri_plugin_shell::init())
|
|
||||||
.invoke_handler(tauri::generate_handler![
|
|
||||||
request_games,
|
|
||||||
install_game,
|
|
||||||
stream_install_game,
|
|
||||||
run_game,
|
|
||||||
start_server,
|
|
||||||
game_directory_exists,
|
|
||||||
update_game_directory,
|
|
||||||
update_game,
|
|
||||||
uninstall_game,
|
|
||||||
remove_downloaded_game,
|
|
||||||
cancel_download,
|
|
||||||
open_game_files,
|
|
||||||
get_peer_count,
|
|
||||||
get_game_thumbnail,
|
|
||||||
get_unpack_logs,
|
|
||||||
get_main_logs
|
|
||||||
])
|
|
||||||
.manage(LanSpreadState::default())
|
|
||||||
.manage(PeerEventTx(tx_peer_event))
|
|
||||||
.setup(move |app| {
|
|
||||||
let state_dir = app.path().app_data_dir()?;
|
|
||||||
std::fs::create_dir_all(&state_dir)?;
|
|
||||||
let main_log_sink = MainLogSink::new(app.handle().clone(), main_log_path(&state_dir));
|
|
||||||
let state = app.state::<LanSpreadState>();
|
|
||||||
if state.main_log_sink.set(main_log_sink.clone()).is_err() {
|
|
||||||
log::warn!("main log sink was already initialized");
|
|
||||||
}
|
|
||||||
init_main_logging(main_log_sink)?;
|
|
||||||
let unpack_logs = load_unpack_logs(&state_dir);
|
|
||||||
tauri::async_runtime::block_on(async {
|
|
||||||
*state.unpack_logs.write().await = unpack_logs;
|
|
||||||
});
|
|
||||||
if state.state_dir.set(state_dir).is_err() {
|
|
||||||
log::warn!("app state directory was already initialized");
|
|
||||||
}
|
|
||||||
spawn_peer_event_loop(app.handle().clone(), rx_peer_event);
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.build(tauri::generate_context!())
|
|
||||||
.expect("error while building tauri application")
|
|
||||||
.run(|app_handle, event| {
|
|
||||||
if matches!(event, tauri::RunEvent::Exit) {
|
|
||||||
shutdown_peer_runtime(app_handle);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn shutdown_peer_runtime(app_handle: &AppHandle) {
|
|
||||||
let state = app_handle.state::<LanSpreadState>();
|
|
||||||
let peer_runtime = state.peer_runtime.clone();
|
|
||||||
|
|
||||||
tauri::async_runtime::block_on(async move {
|
|
||||||
let Some(mut handle) = peer_runtime.write().await.take() else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
handle.shutdown();
|
|
||||||
if tokio::time::timeout(std::time::Duration::from_secs(2), handle.wait_stopped())
|
|
||||||
.await
|
|
||||||
.is_err()
|
|
||||||
{
|
|
||||||
log::warn!("Peer runtime did not stop within 2s of shutdown request");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user