mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 03:23:57 +08:00
fix: portable flag
This commit is contained in:
parent
fa89fe3e87
commit
981f9d0b01
1
.github/workflows/release.yml
vendored
1
.github/workflows/release.yml
vendored
@ -92,7 +92,6 @@ jobs:
|
|||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
|
TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
|
||||||
TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
|
TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
|
||||||
VITE_WIN_PORTABLE: 1
|
|
||||||
|
|
||||||
release-for-linux:
|
release-for-linux:
|
||||||
strategy:
|
strategy:
|
||||||
|
@ -256,6 +256,11 @@ pub async fn clash_api_get_proxy_delay(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn get_portable_flag() -> CmdResult<bool> {
|
||||||
|
Ok(*dirs::PORTABLE_FLAG.get().unwrap_or(&false))
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub mod service {
|
pub mod service {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -34,6 +34,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
cmds::open_logs_dir,
|
cmds::open_logs_dir,
|
||||||
cmds::open_web_url,
|
cmds::open_web_url,
|
||||||
cmds::open_core_dir,
|
cmds::open_core_dir,
|
||||||
|
cmds::get_portable_flag,
|
||||||
// cmds::kill_sidecar,
|
// cmds::kill_sidecar,
|
||||||
cmds::restart_sidecar,
|
cmds::restart_sidecar,
|
||||||
cmds::grant_permission,
|
cmds::grant_permission,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::core::handle;
|
use crate::core::handle;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use tauri::{
|
use tauri::{
|
||||||
api::path::{data_dir, resource_dir},
|
api::path::{data_dir, resource_dir},
|
||||||
@ -11,12 +12,14 @@ static APP_ID: &str = "io.github.clash-verge-rev.clash-verge-rev";
|
|||||||
#[cfg(feature = "verge-dev")]
|
#[cfg(feature = "verge-dev")]
|
||||||
static APP_ID: &str = "io.github.clash-verge-rev.clash-verge-rev.dev";
|
static APP_ID: &str = "io.github.clash-verge-rev.clash-verge-rev.dev";
|
||||||
|
|
||||||
|
pub static PORTABLE_FLAG: OnceCell<bool> = OnceCell::new();
|
||||||
|
|
||||||
static CLASH_CONFIG: &str = "config.yaml";
|
static CLASH_CONFIG: &str = "config.yaml";
|
||||||
static VERGE_CONFIG: &str = "verge.yaml";
|
static VERGE_CONFIG: &str = "verge.yaml";
|
||||||
static PROFILE_YAML: &str = "profiles.yaml";
|
static PROFILE_YAML: &str = "profiles.yaml";
|
||||||
|
|
||||||
/// get the verge app home dir
|
/// init portable flag
|
||||||
pub fn app_home_dir() -> Result<PathBuf> {
|
pub fn init_portable_flag() -> Result<()> {
|
||||||
use tauri::utils::platform::current_exe;
|
use tauri::utils::platform::current_exe;
|
||||||
|
|
||||||
let app_exe = current_exe()?;
|
let app_exe = current_exe()?;
|
||||||
@ -24,13 +27,27 @@ pub fn app_home_dir() -> Result<PathBuf> {
|
|||||||
let dir = PathBuf::from(dir).join(".config/PORTABLE");
|
let dir = PathBuf::from(dir).join(".config/PORTABLE");
|
||||||
|
|
||||||
if dir.exists() {
|
if dir.exists() {
|
||||||
|
PORTABLE_FLAG.get_or_init(|| true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PORTABLE_FLAG.get_or_init(|| false);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get the verge app home dir
|
||||||
|
pub fn app_home_dir() -> Result<PathBuf> {
|
||||||
|
use tauri::utils::platform::current_exe;
|
||||||
|
|
||||||
|
let flag = PORTABLE_FLAG.get().unwrap_or(&false);
|
||||||
|
if *flag {
|
||||||
|
let app_exe = current_exe()?;
|
||||||
let app_exe = dunce::canonicalize(app_exe)?;
|
let app_exe = dunce::canonicalize(app_exe)?;
|
||||||
let app_dir = app_exe
|
let app_dir = app_exe
|
||||||
.parent()
|
.parent()
|
||||||
.ok_or(anyhow::anyhow!("failed to get the portable app dir"))?;
|
.ok_or(anyhow::anyhow!("failed to get the portable app dir"))?;
|
||||||
return Ok(PathBuf::from(app_dir).join(".config").join(APP_ID));
|
return Ok(PathBuf::from(app_dir).join(".config").join(APP_ID));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(data_dir()
|
Ok(data_dir()
|
||||||
.ok_or(anyhow::anyhow!("failed to get app home dir"))?
|
.ok_or(anyhow::anyhow!("failed to get app home dir"))?
|
||||||
.join(APP_ID))
|
.join(APP_ID))
|
||||||
|
@ -141,6 +141,7 @@ pub fn delete_log() -> Result<()> {
|
|||||||
/// Initialize all the config files
|
/// Initialize all the config files
|
||||||
/// before tauri setup
|
/// before tauri setup
|
||||||
pub fn init_config() -> Result<()> {
|
pub fn init_config() -> Result<()> {
|
||||||
|
let _ = dirs::init_portable_flag();
|
||||||
let _ = init_log();
|
let _ = init_log();
|
||||||
let _ = delete_log();
|
let _ = delete_log();
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import { GuardState } from "./mods/guard-state";
|
|||||||
import { LayoutViewer } from "./mods/layout-viewer";
|
import { LayoutViewer } from "./mods/layout-viewer";
|
||||||
import { UpdateViewer } from "./mods/update-viewer";
|
import { UpdateViewer } from "./mods/update-viewer";
|
||||||
import getSystem from "@/utils/get-system";
|
import getSystem from "@/utils/get-system";
|
||||||
|
import { portableFlag } from "@/pages/_layout";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onError?: (err: Error) => void;
|
onError?: (err: Error) => void;
|
||||||
@ -213,7 +214,7 @@ const SettingVerge = ({ onError }: Props) => {
|
|||||||
</IconButton>
|
</IconButton>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
|
||||||
{!(OS === "windows" && WIN_PORTABLE) && (
|
{!portableFlag && (
|
||||||
<SettingItem label={t("Check for Updates")}>
|
<SettingItem label={t("Check for Updates")}>
|
||||||
<IconButton
|
<IconButton
|
||||||
color="inherit"
|
color="inherit"
|
||||||
|
@ -22,6 +22,9 @@ import { useCustomTheme } from "@/components/layout/use-custom-theme";
|
|||||||
import getSystem from "@/utils/get-system";
|
import getSystem from "@/utils/get-system";
|
||||||
import "dayjs/locale/ru";
|
import "dayjs/locale/ru";
|
||||||
import "dayjs/locale/zh-cn";
|
import "dayjs/locale/zh-cn";
|
||||||
|
import { getPortableFlag } from "@/services/cmds";
|
||||||
|
|
||||||
|
export let portableFlag = false;
|
||||||
|
|
||||||
dayjs.extend(relativeTime);
|
dayjs.extend(relativeTime);
|
||||||
|
|
||||||
@ -71,10 +74,12 @@ const Layout = () => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setTimeout(() => {
|
|
||||||
void appWindow.unminimize();
|
setTimeout(async () => {
|
||||||
void appWindow.show();
|
portableFlag = await getPortableFlag();
|
||||||
void appWindow.setFocus();
|
await appWindow.unminimize();
|
||||||
|
await appWindow.show();
|
||||||
|
await appWindow.setFocus();
|
||||||
}, 50);
|
}, 50);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@ -119,9 +124,7 @@ const Layout = () => {
|
|||||||
<div className="the-logo" data-windrag>
|
<div className="the-logo" data-windrag>
|
||||||
<LogoSvg />
|
<LogoSvg />
|
||||||
|
|
||||||
{!(OS === "windows" && WIN_PORTABLE) && (
|
{!portableFlag && <UpdateButton className="the-newbtn" />}
|
||||||
<UpdateButton className="the-newbtn" />
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<List className="the-menu">
|
<List className="the-menu">
|
||||||
|
@ -191,3 +191,7 @@ export async function invoke_uwp_tool() {
|
|||||||
Notice.error(err?.message || err.toString(), 1500)
|
Notice.error(err?.message || err.toString(), 1500)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getPortableFlag() {
|
||||||
|
return invoke<boolean>("get_portable_flag");
|
||||||
|
}
|
||||||
|
1
src/services/types.d.ts
vendored
1
src/services/types.d.ts
vendored
@ -14,7 +14,6 @@ type Platform =
|
|||||||
/**
|
/**
|
||||||
* defines in `vite.config.ts`
|
* defines in `vite.config.ts`
|
||||||
*/
|
*/
|
||||||
declare const WIN_PORTABLE: boolean;
|
|
||||||
declare const OS_PLATFORM: Platform;
|
declare const OS_PLATFORM: Platform;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,6 +25,5 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
define: {
|
define: {
|
||||||
OS_PLATFORM: `"${process.platform}"`,
|
OS_PLATFORM: `"${process.platform}"`,
|
||||||
WIN_PORTABLE: !!process.env.VITE_WIN_PORTABLE,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user