(
&self,
startup_trace_id: &str,
bootstrap_config: &StartupBootstrapConfig,
workspace_startup_state: Option<&serde_json::Value>,
)
| 416 | } |
| 417 | |
| 418 | fn generate_init_script( |
| 419 | &self, |
| 420 | startup_trace_id: &str, |
| 421 | bootstrap_config: &StartupBootstrapConfig, |
| 422 | workspace_startup_state: Option<&serde_json::Value>, |
| 423 | ) -> String { |
| 424 | let theme_type = if self.is_light { "light" } else { "dark" }; |
| 425 | let startup_locale = &bootstrap_config.locale; |
| 426 | let startup_locale_json = |
| 427 | serde_json::to_string(&startup_locale).unwrap_or_else(|_| "\"zh-CN\"".to_string()); |
| 428 | let startup_messages_json = Self::startup_messages_json(&startup_locale); |
| 429 | let show_startup_window_controls = !cfg!(target_os = "macos"); |
| 430 | let startup_trace_id_json = serde_json::to_string(startup_trace_id) |
| 431 | .unwrap_or_else(|_| "\"desktop-unknown\"".to_string()); |
| 432 | let bootstrap_log_level_json = serde_json::to_string(crate::logging::level_to_str( |
| 433 | crate::logging::current_runtime_log_level(), |
| 434 | )) |
| 435 | .unwrap_or_else(|_| "\"warn\"".to_string()); |
| 436 | let perf_trace_enabled = cfg!(debug_assertions) |
| 437 | || ((cfg!(feature = "devtools") || std::env::var_os("BITFUN_PERF_TRACE").is_some()) |
| 438 | && std::env::var_os("BITFUN_WEBDRIVER_PORT").is_some()); |
| 439 | let bootstrap_theme_id_json = |
| 440 | serde_json::to_string(&self.id).unwrap_or_else(|_| "\"bitfun-light\"".to_string()); |
| 441 | let bootstrap_theme_selection_json = self |
| 442 | .selection_id |
| 443 | .as_ref() |
| 444 | .and_then(|selection| serde_json::to_string(selection).ok()) |
| 445 | .unwrap_or_else(|| "null".to_string()); |
| 446 | let bootstrap_keybindings_assignment = serde_json::to_string(&bootstrap_config.keybindings) |
| 447 | .ok() |
| 448 | .filter(|json| json.len() <= MAX_BOOTSTRAP_KEYBINDINGS_JSON_BYTES) |
| 449 | .map(|json| format!("window.__BITFUN_BOOTSTRAP_KEYBINDINGS__ = {json};")) |
| 450 | .unwrap_or_default(); |
| 451 | let bootstrap_workspace_startup_state_assignment = workspace_startup_state |
| 452 | .and_then(|state| serde_json::to_string(state).ok()) |
| 453 | .filter(|json| json.len() <= MAX_BOOTSTRAP_WORKSPACE_STATE_JSON_BYTES) |
| 454 | .map(|json| format!("window.__BITFUN_BOOTSTRAP_WORKSPACE_STARTUP_STATE__ = {json};")) |
| 455 | .unwrap_or_default(); |
| 456 | |
| 457 | format!( |
| 458 | r#" |
| 459 | (function() {{ |
| 460 | window.__BITFUN_STARTUP_TRACE_ID__ = {startup_trace_id_json}; |
| 461 | window.__BITFUN_PERF_TRACE_ENABLED__ = {perf_trace_enabled}; |
| 462 | window.__BITFUN_BOOTSTRAP_LOG_LEVEL__ = {bootstrap_log_level_json}; |
| 463 | window.__BITFUN_BOOTSTRAP_LOCALE__ = {startup_locale_json}; |
| 464 | window.__BITFUN_BOOTSTRAP_MESSAGES__ = {startup_messages_json}; |
| 465 | window.__BITFUN_SHOW_STARTUP_WINDOW_CONTROLS__ = {show_startup_window_controls}; |
| 466 | window.__BITFUN_BOOTSTRAP_THEME_ID__ = {bootstrap_theme_id_json}; |
| 467 | window.__BITFUN_BOOTSTRAP_THEME_SELECTION__ = {bootstrap_theme_selection_json}; |
| 468 | {bootstrap_keybindings_assignment} |
| 469 | {bootstrap_workspace_startup_state_assignment} |
| 470 | function applyTheme() {{ |
| 471 | var root = document.documentElement; |
| 472 | if (!root) return false; |
| 473 | |
| 474 | root.setAttribute('data-theme', '{id}'); |
| 475 | root.setAttribute('data-theme-type', '{theme_type}'); |
no test coverage detected