From 41933c8b8004087f6ffd5598d44e3d924c8177da Mon Sep 17 00:00:00 2001 From: Oscar Beaumont Date: Tue, 6 Jun 2023 18:56:31 +0800 Subject: [PATCH] [ENG-694] Remove Spacedrop (#914) * goodbye Spacedrop * fix startup error escaping * fix error fallback being cringe with long error * backwards compatibility for early adopters --- apps/desktop/src-tauri/Cargo.toml | 11 +---------- apps/desktop/src-tauri/src/main.rs | 2 +- core/src/p2p/p2p_manager.rs | 3 ++- core/src/util/migrator.rs | 30 +++++++++++++++++++++++++++++- interface/ErrorFallback.tsx | 15 ++++++++++++--- interface/app/Spacedrop.tsx | 3 +++ 6 files changed, 48 insertions(+), 16 deletions(-) diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index 51a82680e..763cad131 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -9,16 +9,7 @@ repository.workspace = true edition.workspace = true [dependencies] -tauri = { version = "1.3.0", features = [ - "dialog-all", - "linux-protocol-headers", - "macos-private-api", - "os-all", - "path-all", - "protocol-all", - "shell-all", - "window-all", -] } +tauri = { version = "1.3.0", features = ["dialog-all", "linux-protocol-headers", "macos-private-api", "os-all", "path-all", "protocol-all", "shell-all", "window-all"] } rspc = { workspace = true, features = ["tauri"] } httpz = { workspace = true, features = [ "axum", diff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rs index 989ebe617..fb1b2f754 100644 --- a/apps/desktop/src-tauri/src/main.rs +++ b/apps/desktop/src-tauri/src/main.rs @@ -52,7 +52,7 @@ async fn open_logs_dir(node: tauri::State<'_, Arc>) -> Result<(), ()> { pub fn tauri_error_plugin(err: NodeError) -> TauriPlugin { tauri::plugin::Builder::new("spacedrive") - .js_init_script(format!(r#"window.__SD_ERROR__ = "{err}";"#)) + .js_init_script(format!(r#"window.__SD_ERROR__ = `{err}`;"#)) .build() } diff --git a/core/src/p2p/p2p_manager.rs b/core/src/p2p/p2p_manager.rs index 6d41ea53c..fd1075213 100644 --- a/core/src/p2p/p2p_manager.rs +++ b/core/src/p2p/p2p_manager.rs @@ -106,7 +106,8 @@ impl P2PManager { .ok(); // TODO: Don't just connect to everyone when we find them. We should only do it if we know them. - event.dial().await; + // TODO(Spacedrop): Disable Spacedrop for now + // event.dial().await; } Event::PeerMessage(mut event) => { let events = events.clone(); diff --git a/core/src/util/migrator.rs b/core/src/util/migrator.rs index cef8d2e4d..9f8b95cbd 100644 --- a/core/src/util/migrator.rs +++ b/core/src/util/migrator.rs @@ -52,7 +52,33 @@ where match path.try_exists()? { true => { let mut file = File::options().read(true).write(true).open(path)?; - let mut cfg: BaseConfig = serde_json::from_reader(BufReader::new(&mut file))?; + let mut cfg: BaseConfig = match serde_json::from_reader(BufReader::new(&mut file)) { + Ok(cfg) => cfg, + Err(err) => { + // This is for backwards compatibility for the backwards compatibility cause the super super old system store the version as a string. + { + file.rewind()?; + let mut y = match serde_json::from_reader::<_, Value>(BufReader::new( + &mut file, + )) { + Ok(y) => y, + Err(_) => { + return Err(err.into()); + } + }; + + if let Some(obj) = y.as_object_mut() { + if let Some(_) = obj.get("version").and_then(|v| v.as_str()) { + return Err(MigratorError::HasSuperLegacyConfig); // This is just to make the error nicer + } else { + return Err(err.into()); + } + } else { + return Err(err.into()); + } + } + } + }; file.rewind()?; // Fail early so we don't end up invalid state if cfg.version > self.current_version { @@ -112,6 +138,8 @@ pub enum MigratorError { YourAppIsOutdated, #[error("Type '{0}' as generic `Migrator::T` must be serialiable to a Serde object!")] InvalidType(&'static str), + #[error("We detected a Spacedrive config from a super early version of the app!")] + HasSuperLegacyConfig, #[error("custom migration error: {0}")] Custom(String), } diff --git a/interface/ErrorFallback.tsx b/interface/ErrorFallback.tsx index 8808739ba..aeabc5656 100644 --- a/interface/ErrorFallback.tsx +++ b/interface/ErrorFallback.tsx @@ -32,6 +32,13 @@ export default ({ error, resetErrorBoundary }: FallbackProps) => ( /> ); +// This is sketchy but these are all edge cases that will only be encountered by developers if everything works as expected so it's probs fine +const errorsThatRequireACoreReset = [ + 'failed to initialize config', + 'failed to initialize library manager: failed to run library migrations', + 'failed to initialize config: We detected a Spacedrive config from a super early version of the app!' +]; + export function ErrorPage({ reloadBtn, sendReportBtn, @@ -61,7 +68,9 @@ export function ErrorPage({ >

APP CRASHED

We're past the event horizon...

-
{message}
+
+				{message}
+			
{submessage &&
{submessage}
}
{reloadBtn && ( @@ -74,7 +83,7 @@ export function ErrorPage({ Send report )} - {message === 'failed to initialize config' && ( + {errorsThatRequireACoreReset.includes(message) && (

We detected you may have created your library with an older version of @@ -92,7 +101,7 @@ export function ErrorPage({ window.__TAURI_INVOKE__('reset_spacedrive'); }} > - Reset Library + Reset Spacedrive

)} diff --git a/interface/app/Spacedrop.tsx b/interface/app/Spacedrop.tsx index a5ae1b0c7..da0bba030 100644 --- a/interface/app/Spacedrop.tsx +++ b/interface/app/Spacedrop.tsx @@ -14,6 +14,9 @@ import { getSpacedropState, subscribeSpacedropState } from '../hooks/useSpacedro const { Input, useZodForm, z } = forms; export function SpacedropUI() { + // TODO(Spacedrop): Disable Spacedrop for now + return null; + useEffect(() => subscribeSpacedropState(() => { dialogManager.create((dp) => );