Skip to content

Commit

Permalink
feat: Add UWP tool support, fix install service bug (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuingsmile authored Nov 25, 2023
1 parent 0c9a9f0 commit b09331e
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 6 deletions.
11 changes: 11 additions & 0 deletions scripts/check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ const resolveGeoIP = () =>
file: "geoip.dat",
downloadURL: `https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.dat`,
});
const resolveEnableLoopback = () =>
resolveResource({
file: "enableLoopback.exe",
downloadURL: `https://github.com/Kuingsmile/uwp-tool/releases/download/latest/enableLoopback.exe`,
});

const tasks = [
{ name: "clash", func: () => resolveSidecar(clashBackup()), retry: 5 },
Expand All @@ -348,6 +353,12 @@ const tasks = [
{ name: "mmdb", func: resolveMmdb, retry: 5 },
{ name: "geosite", func: resolveGeosite, retry: 5 },
{ name: "geoip", func: resolveGeoIP, retry: 5 },
{
name: "enableLoopback",
func: resolveEnableLoopback,
retry: 5,
winOnly: true,
},
];

async function runTask() {
Expand Down
8 changes: 3 additions & 5 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ wry = { version = "0.24.3" }


[target.'cfg(windows)'.dependencies]
runas = "1.1.0"
runas = "=1.0.0"
deelevate = "0.2.0"
winreg = { version = "0.50", features = ["transactions"] }
windows-sys = { version = "0.48", features = ["Win32_System_LibraryLoader", "Win32_System_SystemInformation"] }
Expand Down
21 changes: 21 additions & 0 deletions src-tauri/src/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ pub fn open_web_url(url: String) -> CmdResult<()> {
wrap_err!(open::that(url))
}

#[cfg(windows)]
pub mod uwp {
use super::*;
use crate::core::win_uwp;

#[tauri::command]
pub async fn invoke_uwp_tool() -> CmdResult {
wrap_err!(win_uwp::invoke_uwptools().await)
}
}

#[cfg(windows)]
pub mod service {
use super::*;
Expand Down Expand Up @@ -267,3 +278,13 @@ pub mod service {
Ok(())
}
}

#[cfg(not(windows))]
pub mod uwp {
use super::*;

#[tauri::command]
pub async fn invoke_uwp_tool() -> CmdResult {
Ok(())
}
}
1 change: 1 addition & 0 deletions src-tauri/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ pub mod sysopt;
pub mod timer;
pub mod tray;
pub mod win_service;
pub mod win_uwp;

pub use self::core::*;
27 changes: 27 additions & 0 deletions src-tauri/src/core/win_uwp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#![cfg(target_os = "windows")]

use crate::utils::dirs;
use anyhow::{bail, Result};
use deelevate::{PrivilegeLevel, Token};
use runas::Command as RunasCommand;
use std::process::Command as StdCommand;

pub async fn invoke_uwptools() -> Result<()> {
let binary_path = dirs::service_path()?;
let tool_path = binary_path.with_file_name("enableLoopback.exe");

if !tool_path.exists() {
bail!("enableLoopback exe not found");
}

let token = Token::with_current_process()?;
let level = token.privilege_level()?;

match level {
PrivilegeLevel::NotPrivileged => RunasCommand::new(tool_path).status()?,
_ => StdCommand::new(tool_path)
.status()?,
};

Ok(())
}
1 change: 1 addition & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ fn main() -> std::io::Result<()> {
cmds::get_runtime_yaml,
cmds::get_runtime_exists,
cmds::get_runtime_logs,
cmds::uwp::invoke_uwp_tool,
// verge
cmds::get_verge_config,
cmds::patch_verge_config,
Expand Down
16 changes: 16 additions & 0 deletions src/components/setting/setting-clash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import { ClashPortViewer } from "./mods/clash-port-viewer";
import { ControllerViewer } from "./mods/controller-viewer";
import { SettingList, SettingItem } from "./mods/setting-comp";
import { ClashCoreViewer } from "./mods/clash-core-viewer";
import { invoke_uwp_tool } from "@/services/cmds";
import getSystem from "@/utils/get-system";

const isWIN = getSystem() === "windows";

interface Props {
onError: (err: Error) => void;
Expand Down Expand Up @@ -162,6 +166,18 @@ const SettingClash = ({ onError }: Props) => {
>
<Typography sx={{ py: "7px", pr: 1 }}>{version}</Typography>
</SettingItem>
{isWIN && (
<SettingItem label={t("Open UWP tool")}>
<IconButton
color="inherit"
size="small"
sx={{ my: "2px" }}
onClick={invoke_uwp_tool}
>
<ArrowForward />
</IconButton>
</SettingItem>
)}
</SettingList>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"Auto Launch": "Auto Launch",
"Silent Start": "Silent Start",
"System Proxy": "System Proxy",
"Open UWP tool": "UWP工具",
"System Proxy Setting": "System Proxy Setting",
"Proxy Guard": "Proxy Guard",
"Guard Duration": "Guard Duration",
Expand Down
1 change: 1 addition & 0 deletions src/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"Proxy Bypass": "Игнорирование прокси",
"Current System Proxy": "Текущий системный прокси",
"Theme Mode": "Режим темы",
"Open UWP tool": "Открыть UWP инструмент",
"Theme Blur": "Размытие темы",
"Theme Setting": "Настройка темы",
"Hotkey Setting": "Настройка клавиатурных сокращений",
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"Auto Launch": "开机自启",
"Silent Start": "静默启动",
"System Proxy": "系统代理",
"Open UWP tool": "Open UWP tool",
"System Proxy Setting": "系统代理设置",
"Proxy Guard": "系统代理守卫",
"Guard Duration": "代理守卫间隔",
Expand Down
6 changes: 6 additions & 0 deletions src/services/cmds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,9 @@ export async function installService() {
export async function uninstallService() {
return invoke<void>("uninstall_service");
}

export async function invoke_uwp_tool() {
return invoke<void>("invoke_uwp_tool").catch((err) =>
Notice.error(err?.message || err.toString(), 1500)
);
}

0 comments on commit b09331e

Please sign in to comment.