Skip to content

Commit

Permalink
feat: supports silent start
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzgydi committed Mar 26, 2022
1 parent a12f58c commit 9d44668
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src-tauri/src/core/verge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ pub struct VergeConfig {
/// can the app auto startup
pub enable_auto_launch: Option<bool>,

/// not show the window on launch
pub enable_silent_start: Option<bool>,

/// set system proxy
pub enable_system_proxy: Option<bool>,

Expand Down Expand Up @@ -197,6 +200,9 @@ impl Verge {
if patch.traffic_graph.is_some() {
self.config.traffic_graph = patch.traffic_graph;
}
if patch.enable_silent_start.is_some() {
self.config.enable_silent_start = patch.enable_silent_start;
}

// should update system startup
if patch.enable_auto_launch.is_some() {
Expand Down
13 changes: 10 additions & 3 deletions src-tauri/src/utils/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use tauri::{App, AppHandle, Manager};

/// handle something when start app
pub fn resolve_setup(app: &App) {
resolve_window(app);

// setup a simple http server for singleton
server::embed_server(&app.handle());

Expand Down Expand Up @@ -46,6 +44,8 @@ pub fn resolve_setup(app: &App) {
.get_item("system_proxy")
.set_selected(enable));
});

resolve_window(app, verge.config.enable_silent_start.clone());
}

/// reset system proxy
Expand All @@ -57,9 +57,16 @@ pub fn resolve_reset(app_handle: &AppHandle) {
}

/// customize the window theme
fn resolve_window(app: &App) {
fn resolve_window(app: &App, hide: Option<bool>) {
let window = app.get_window("main").unwrap();

// silent start
hide.map(|hide| {
if hide {
window.hide().unwrap();
}
});

#[cfg(target_os = "windows")]
{
use window_shadows::set_shadow;
Expand Down
15 changes: 15 additions & 0 deletions src/components/setting/setting-system.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const SettingSystem = ({ onError }: Props) => {
const {
enable_tun_mode,
enable_auto_launch,
enable_silent_start,
enable_system_proxy,
system_proxy_bypass,
enable_proxy_guard,
Expand Down Expand Up @@ -59,6 +60,20 @@ const SettingSystem = ({ onError }: Props) => {
</GuardState>
</SettingItem>

<SettingItem>
<ListItemText primary={t("Silent Start")} />
<GuardState
value={enable_silent_start ?? false}
valueProps="checked"
onCatch={onError}
onFormat={onSwitchFormat}
onChange={(e) => onChangeData({ enable_silent_start: e })}
onGuard={(e) => patchVergeConfig({ enable_silent_start: e })}
>
<Switch edge="end" />
</GuardState>
</SettingItem>

<SettingItem>
<ListItemText
primary={
Expand Down
1 change: 1 addition & 0 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export namespace CmdType {
traffic_graph?: boolean;
enable_tun_mode?: boolean;
enable_auto_launch?: boolean;
enable_silent_start?: boolean;
enable_system_proxy?: boolean;
enable_proxy_guard?: boolean;
system_proxy_bypass?: string;
Expand Down

0 comments on commit 9d44668

Please sign in to comment.