mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 21:20:29 +08:00
creat shortcut
This commit is contained in:
parent
0252ad58e2
commit
4b0a467d8e
@ -1,9 +1,7 @@
|
||||
### New Features
|
||||
|
||||
- 自动删除过期日志与更新缓存
|
||||
- 添加更新内核功能
|
||||
- 支持创建没有UAC弹窗的启动快捷方式
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- 修复接管dns后自定义hosts无法删除的问题
|
||||
- 删除退出应用全局快捷键(仅支持应用内CommandOrCtrl+Q退出)
|
||||
- 修复节点排序无法恢复默认的问题
|
||||
|
||||
@ -126,3 +126,63 @@ export async function disableAutoRun(): Promise<void> {
|
||||
await rm(desktopFilePath)
|
||||
}
|
||||
}
|
||||
|
||||
const shortcutTaskXml = `<?xml version="1.0" encoding="UTF-16"?>
|
||||
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
|
||||
<RegistrationInfo>
|
||||
<Date>${new Date().toISOString()}</Date>
|
||||
<Author>${process.env.USERNAME}</Author>
|
||||
</RegistrationInfo>
|
||||
<Triggers />
|
||||
<Principals>
|
||||
<Principal id="Author">
|
||||
<LogonType>InteractiveToken</LogonType>
|
||||
<RunLevel>HighestAvailable</RunLevel>
|
||||
</Principal>
|
||||
</Principals>
|
||||
<Settings>
|
||||
<MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
|
||||
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
|
||||
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
|
||||
<AllowHardTerminate>false</AllowHardTerminate>
|
||||
<StartWhenAvailable>false</StartWhenAvailable>
|
||||
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
|
||||
<IdleSettings>
|
||||
<StopOnIdleEnd>false</StopOnIdleEnd>
|
||||
<RestartOnIdle>false</RestartOnIdle>
|
||||
</IdleSettings>
|
||||
<AllowStartOnDemand>true</AllowStartOnDemand>
|
||||
<Enabled>true</Enabled>
|
||||
<Hidden>false</Hidden>
|
||||
<RunOnlyIfIdle>false</RunOnlyIfIdle>
|
||||
<WakeToRun>false</WakeToRun>
|
||||
<ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
|
||||
<Priority>7</Priority>
|
||||
</Settings>
|
||||
<Actions Context="Author">
|
||||
<Exec>
|
||||
<Command>${exePath()}</Command>
|
||||
</Exec>
|
||||
</Actions>
|
||||
</Task>
|
||||
`
|
||||
|
||||
export async function createShortcut(): Promise<void> {
|
||||
if (process.platform === 'win32') {
|
||||
const execPromise = promisify(exec)
|
||||
const taskFilePath = path.join(dataDir(), `${appName}-run.xml`)
|
||||
await writeFile(taskFilePath, Buffer.from(`\ufeff${shortcutTaskXml}`, 'utf-16le'))
|
||||
await execPromise(`schtasks /create /tn "${appName}-run" /xml "${taskFilePath}" /f`)
|
||||
const createShortcutCommand = `
|
||||
$shortcutPath = [System.IO.Path]::Combine([System.Environment]::GetFolderPath("Desktop"), "Mihomo Party.lnk")
|
||||
$wshell = New-Object -ComObject WScript.Shell
|
||||
$shortcut = $wshell.CreateShortcut($shortcutPath)
|
||||
$shortcut.TargetPath = "C:\\Windows\\System32\\schtasks.exe"
|
||||
$shortcut.Arguments = "/run /tn ${appName}-run"
|
||||
$shortcut.Description = "Start Mihomo Party without UAC Prompt"
|
||||
$shortcut.IconLocation = "${exePath()}"
|
||||
$shortcut.WindowStyle = 7
|
||||
$shortcut.Save()`
|
||||
await execPromise(createShortcutCommand, { shell: 'powershell' })
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ import {
|
||||
stopMihomoConnections,
|
||||
stopMihomoLogs
|
||||
} from '../core/mihomoApi'
|
||||
import { checkAutoRun, disableAutoRun, enableAutoRun } from '../sys/autoRun'
|
||||
import { checkAutoRun, createShortcut, disableAutoRun, enableAutoRun } from '../sys/autoRun'
|
||||
import {
|
||||
getAppConfig,
|
||||
patchAppConfig,
|
||||
@ -165,6 +165,7 @@ export function registerIpcMainHandlers(): void {
|
||||
ipcMain.handle('registerShortcut', (_e, oldShortcut, newShortcut, action) =>
|
||||
ipcErrorWrapper(registerShortcut)(oldShortcut, newShortcut, action)
|
||||
)
|
||||
ipcMain.handle('createShortcut', ipcErrorWrapper(createShortcut))
|
||||
ipcMain.handle('setNativeTheme', (_e, theme) => {
|
||||
setNativeTheme(theme)
|
||||
})
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import React, { Key } from 'react'
|
||||
import React, { Key, useState } from 'react'
|
||||
import SettingCard from '../base/base-setting-card'
|
||||
import SettingItem from '../base/base-setting-item'
|
||||
import { Button, Select, SelectItem, Switch, Tab, Tabs } from '@nextui-org/react'
|
||||
@ -7,6 +7,7 @@ import useSWR from 'swr'
|
||||
import {
|
||||
checkAutoRun,
|
||||
copyEnv,
|
||||
createShortcut,
|
||||
disableAutoRun,
|
||||
enableAutoRun,
|
||||
isPortable,
|
||||
@ -22,6 +23,7 @@ const GeneralConfig: React.FC = () => {
|
||||
const { data: enable, mutate: mutateEnable } = useSWR('checkAutoRun', checkAutoRun)
|
||||
const { data: portable, mutate: mutatePortable } = useSWR('isPortable', isPortable)
|
||||
const { appConfig, patchAppConfig } = useAppConfig()
|
||||
const [creating, setCreating] = useState(false)
|
||||
const { setTheme } = useTheme()
|
||||
const {
|
||||
silentStart = false,
|
||||
@ -164,6 +166,26 @@ const GeneralConfig: React.FC = () => {
|
||||
</>
|
||||
)}
|
||||
{platform === 'win32' && (
|
||||
<>
|
||||
<SettingItem title="创建无UAC弹窗快捷方式" divider>
|
||||
<Button
|
||||
size="sm"
|
||||
color="primary"
|
||||
isLoading={creating}
|
||||
onClick={async () => {
|
||||
try {
|
||||
setCreating(true)
|
||||
await createShortcut()
|
||||
} catch (e) {
|
||||
alert(e)
|
||||
} finally {
|
||||
setCreating(false)
|
||||
}
|
||||
}}
|
||||
>
|
||||
创建快捷方式
|
||||
</Button>
|
||||
</SettingItem>
|
||||
<SettingItem title="数据存储路径" divider>
|
||||
<Select
|
||||
className="w-[150px]"
|
||||
@ -183,6 +205,7 @@ const GeneralConfig: React.FC = () => {
|
||||
<SelectItem key="portable">安装目录</SelectItem>
|
||||
</Select>
|
||||
</SettingItem>
|
||||
</>
|
||||
)}
|
||||
<SettingItem title="背景色" divider={appTheme !== 'system'}>
|
||||
<Tabs
|
||||
|
||||
@ -287,6 +287,10 @@ export async function quitApp(): Promise<void> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('quitApp'))
|
||||
}
|
||||
|
||||
export async function createShortcut(): Promise<void> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('createShortcut'))
|
||||
}
|
||||
|
||||
export async function setNativeTheme(theme: 'system' | 'light' | 'dark'): Promise<void> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('setNativeTheme', theme))
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user