Skip to content

Commit

Permalink
fix: arg helpers, fix safemode
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Dec 15, 2024
1 parent c0d1d10 commit c683b8a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
9 changes: 3 additions & 6 deletions src-tauri/src/functionality/configure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use crate::{
injection::plugin::load_plugins,
log,
util::{
color::start_os_accent_subscriber,
window_helpers::{set_user_agent, ultrashow, window_zoom_level},
args::{is_safemode, is_startup}, color::start_os_accent_subscriber, window_helpers::{set_user_agent, ultrashow, window_zoom_level}
},
};

Expand All @@ -29,8 +28,6 @@ use super::rpc::start_rpc_server;
use super::{extension::load_extensions, tray::create_tray};

pub fn configure(window: &tauri::WebviewWindow) {
let safemode = std::env::args().any(|arg| arg == "--safemode");
let startup = std::env::args().any(|arg| arg == "--startup");
let config = get_config();
let handle = window.app_handle();

Expand All @@ -53,7 +50,7 @@ pub fn configure(window: &tauri::WebviewWindow) {
}

// If safemode is enabled, stop here
if safemode {
if is_safemode() {
window.show().unwrap_or_default();
return;
}
Expand Down Expand Up @@ -85,7 +82,7 @@ pub fn configure(window: &tauri::WebviewWindow) {
}

// If we are opening on startup (which we know from the --startup arg), check to keep the window minimized
if !startup || !config.startup_minimized.unwrap_or(false) {
if !is_startup() || !config.startup_minimized.unwrap_or(false) {
// Now that we are ready, and shouldn't start minimized, show the window
window.show().unwrap_or_default();
} else {
Expand Down
13 changes: 6 additions & 7 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ use injection::{
use processors::{css_preprocess, js_preprocess};
use profiles::init_profiles_folders;
use util::{
helpers,
logger::log,
notifications,
paths::get_webdata_dir,
window_helpers::{self, clear_cache_check},
args::is_safemode, helpers, logger::log, notifications, paths::get_webdata_dir, window_helpers::{self, clear_cache_check}
};

use crate::{
Expand Down Expand Up @@ -249,8 +245,6 @@ fn main() {
let title = format!("Dorion - v{}", app.package_info().version);
let mut win = WebviewWindowBuilder::new(app, "main", url_ext)
.title(title.as_str())
// Preinject is bundled with "use strict" so we put it in it's own function to prevent potential client mod issues
.initialization_script(format!("console.log(window.location);if(window.__DORION_INIT__) {{throw new Error('Dorion already began initializing');}} window.__DORION_INIT__ = true; {preinject};{client_mods}").as_str())
.resizable(true)
.disable_drag_drop_handler()
.data_directory(get_webdata_dir())
Expand All @@ -264,6 +258,11 @@ fn main() {
.zoom_hotkeys_enabled(true)
.browser_extensions_enabled(true);

if !is_safemode() {
// Preinject is bundled with "use strict" so we put it in it's own function to prevent potential client mod issues
win = win.initialization_script(format!("console.log(window.location);if(window.__DORION_INIT__) {{throw new Error('Dorion already began initializing');}} window.__DORION_INIT__ = true; {preinject};{client_mods}").as_str());
}

if let Ok(proxy_uri) = proxy_uri {
win = win.proxy_url(proxy_uri);
}
Expand Down
7 changes: 7 additions & 0 deletions src-tauri/src/util/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub fn is_safemode() -> bool {
std::env::args().any(|arg| arg == "--safemode")
}

pub fn is_startup() -> bool {
std::env::args().any(|arg| arg == "--startup")
}
1 change: 1 addition & 0 deletions src-tauri/src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod args;
pub mod color;
pub mod helpers;
pub mod logger;
Expand Down

0 comments on commit c683b8a

Please sign in to comment.