Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New option to disable persistent storage #1825

Merged
merged 2 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ enum TimeControlCommand {
#[derive(Clone, Copy, Default)]
pub struct StartupOptions {
pub memory_limit: re_memory::MemoryLimit,
pub persist_state: bool,
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -118,9 +119,13 @@ impl App {
);
}

let state: AppState = storage
.and_then(|storage| eframe::get_value(storage, eframe::APP_KEY))
.unwrap_or_default();
let state: AppState = if startup_options.persist_state {
storage
.and_then(|storage| eframe::get_value(storage, eframe::APP_KEY))
.unwrap_or_default()
} else {
AppState::default()
};

let mut analytics = ViewerAnalytics::new();
analytics.on_viewer_started(&build_info, app_env);
Expand Down Expand Up @@ -412,7 +417,9 @@ impl eframe::App for App {
}

fn save(&mut self, storage: &mut dyn eframe::Storage) {
eframe::set_value(storage, eframe::APP_KEY, &self.state);
if self.startup_options.persist_state {
eframe::set_value(storage, eframe::APP_KEY, &self.state);
}
}

fn update(&mut self, egui_ctx: &egui::Context, frame: &mut eframe::Frame) {
Expand Down
22 changes: 22 additions & 0 deletions crates/re_viewer/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ pub async fn start(
Box::new(move |cc| {
let build_info = re_build_info::build_info!();
let app_env = crate::AppEnvironment::Web;
let persist_state = get_persist_state(&cc.integration_info);
let startup_options = crate::StartupOptions {
memory_limit: re_memory::MemoryLimit {
// On wasm32 we only have 4GB of memory to play around with.
limit: Some(3_500_000_000),
},
persist_state,
};
let re_ui = crate::customize_eframe(cc);
let url = url.unwrap_or_else(|| get_url(&cc.integration_info));
Expand Down Expand Up @@ -122,3 +124,23 @@ fn get_url(info: &eframe::IntegrationInfo) -> String {
url
}
}

fn get_persist_state(info: &eframe::IntegrationInfo) -> bool {
match info
.web_info
.location
.query_map
.get("persist")
.map(String::as_str)
{
Some("0") => false,
Some("1") => true,
Some(other) => {
re_log::warn!(
"Unexpected value for 'persist' query: {other:?}. Expected either '0' or '1'. Defaulting to '1'."
);
true
}
_ => true,
}
}
10 changes: 10 additions & 0 deletions crates/rerun/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ struct Args {
#[clap(long)]
memory_limit: Option<String>,

/// Whether the Rerun Viewer should persist the state of the viewer to disk.
///
/// When persisted, the state will be stored at the following locations:
/// - Linux: /home/UserName/.local/share/rerunviewer
/// - macOS: /Users/UserName/Library/Application Support/rerunviewer
/// - Windows: C:\Users\UserName\AppData\Roaming\rerunviewer
#[clap(long, default_value_t = true)]
persist_state: bool,

/// What TCP port do we listen to (for SDK:s to connect to)?
#[cfg(feature = "server")]
#[clap(long, default_value_t = re_sdk_comms::DEFAULT_SERVER_PORT)]
Expand Down Expand Up @@ -273,6 +282,7 @@ async fn run_impl(
re_memory::MemoryLimit::parse(l)
.unwrap_or_else(|err| panic!("Bad --memory-limit: {err}"))
}),
persist_state: args.persist_state,
};

let (shutdown_rx, shutdown_bool) = setup_ctrl_c_handler();
Expand Down