mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 21:20:29 +08:00
fix auto update profile
This commit is contained in:
parent
6edb0a6653
commit
2b62a2f1e1
@ -56,10 +56,6 @@ export async function createOverride(item: Partial<IOverrideItem>): Promise<IOve
|
|||||||
switch (newItem.type) {
|
switch (newItem.type) {
|
||||||
case 'remote': {
|
case 'remote': {
|
||||||
if (!item.url) {
|
if (!item.url) {
|
||||||
dialog.showErrorBox(
|
|
||||||
'URL is required for remote script',
|
|
||||||
'URL is required for remote script'
|
|
||||||
)
|
|
||||||
throw new Error('URL is required for remote script')
|
throw new Error('URL is required for remote script')
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -81,10 +77,6 @@ export async function createOverride(item: Partial<IOverrideItem>): Promise<IOve
|
|||||||
}
|
}
|
||||||
case 'local': {
|
case 'local': {
|
||||||
if (!item.file) {
|
if (!item.file) {
|
||||||
dialog.showErrorBox(
|
|
||||||
'File is required for local script',
|
|
||||||
'File is required for local script'
|
|
||||||
)
|
|
||||||
throw new Error('File is required for local script')
|
throw new Error('File is required for local script')
|
||||||
}
|
}
|
||||||
const data = item.file
|
const data = item.file
|
||||||
|
|||||||
@ -119,10 +119,6 @@ export async function createProfile(item: Partial<IProfileItem>): Promise<IProfi
|
|||||||
switch (newItem.type) {
|
switch (newItem.type) {
|
||||||
case 'remote': {
|
case 'remote': {
|
||||||
if (!item.url) {
|
if (!item.url) {
|
||||||
dialog.showErrorBox(
|
|
||||||
'URL is required for remote profile',
|
|
||||||
'URL is required for remote profile'
|
|
||||||
)
|
|
||||||
throw new Error('URL is required for remote profile')
|
throw new Error('URL is required for remote profile')
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -152,7 +148,7 @@ export async function createProfile(item: Partial<IProfileItem>): Promise<IProfi
|
|||||||
if (headers['subscription-userinfo']) {
|
if (headers['subscription-userinfo']) {
|
||||||
newItem.extra = parseSubinfo(headers['subscription-userinfo'])
|
newItem.extra = parseSubinfo(headers['subscription-userinfo'])
|
||||||
}
|
}
|
||||||
setProfileStr(id, data)
|
await setProfileStr(id, data)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
dialog.showErrorBox('Failed to fetch remote profile', `${e}\nurl: ${item.url}`)
|
dialog.showErrorBox('Failed to fetch remote profile', `${e}\nurl: ${item.url}`)
|
||||||
throw new Error(`Failed to fetch remote profile ${e}`)
|
throw new Error(`Failed to fetch remote profile ${e}`)
|
||||||
@ -161,14 +157,10 @@ export async function createProfile(item: Partial<IProfileItem>): Promise<IProfi
|
|||||||
}
|
}
|
||||||
case 'local': {
|
case 'local': {
|
||||||
if (!item.file) {
|
if (!item.file) {
|
||||||
dialog.showErrorBox(
|
|
||||||
'File is required for local profile',
|
|
||||||
'File is required for local profile'
|
|
||||||
)
|
|
||||||
throw new Error('File is required for local profile')
|
throw new Error('File is required for local profile')
|
||||||
}
|
}
|
||||||
const data = item.file
|
const data = item.file
|
||||||
setProfileStr(id, data)
|
await setProfileStr(id, data)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import axios, { AxiosInstance } from 'axios'
|
|||||||
import { getAppConfig, getControledMihomoConfig } from '../config'
|
import { getAppConfig, getControledMihomoConfig } from '../config'
|
||||||
import WebSocket from 'ws'
|
import WebSocket from 'ws'
|
||||||
import { window } from '..'
|
import { window } from '..'
|
||||||
import { dialog } from 'electron'
|
|
||||||
|
|
||||||
let axiosIns: AxiosInstance = null!
|
let axiosIns: AxiosInstance = null!
|
||||||
let mihomoTrafficWs: WebSocket | null = null
|
let mihomoTrafficWs: WebSocket | null = null
|
||||||
@ -189,8 +188,6 @@ const mihomoTraffic = (): void => {
|
|||||||
if (trafficRetry) {
|
if (trafficRetry) {
|
||||||
trafficRetry--
|
trafficRetry--
|
||||||
mihomoTraffic()
|
mihomoTraffic()
|
||||||
} else {
|
|
||||||
dialog.showErrorBox('External controller traffic error', 'Retry limit reached')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,8 +231,6 @@ const mihomoMemory = (): void => {
|
|||||||
if (memoryRetry) {
|
if (memoryRetry) {
|
||||||
memoryRetry--
|
memoryRetry--
|
||||||
mihomoMemory()
|
mihomoMemory()
|
||||||
} else {
|
|
||||||
dialog.showErrorBox('External controller memory error', 'Retry limit reached')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,8 +276,6 @@ const mihomoLogs = (): void => {
|
|||||||
if (logsRetry) {
|
if (logsRetry) {
|
||||||
logsRetry--
|
logsRetry--
|
||||||
mihomoLogs()
|
mihomoLogs()
|
||||||
} else {
|
|
||||||
dialog.showErrorBox('External controller logs error', 'Retry limit reached')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,8 +321,6 @@ const mihomoConnections = (): void => {
|
|||||||
if (connectionsRetry) {
|
if (connectionsRetry) {
|
||||||
connectionsRetry--
|
connectionsRetry--
|
||||||
mihomoConnections()
|
mihomoConnections()
|
||||||
} else {
|
|
||||||
dialog.showErrorBox('External controller connections error', 'Retry limit reached')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,34 +1,42 @@
|
|||||||
import { addProfileItem, getProfileConfig, getProfileItem } from '../config'
|
import { addProfileItem, getCurrentProfileItem, getProfileConfig, getProfileItem } from '../config'
|
||||||
|
|
||||||
const intervalPool: Record<string, NodeJS.Timeout> = {}
|
const intervalPool: Record<string, NodeJS.Timeout> = {}
|
||||||
|
|
||||||
export function initProfileUpdater(): void {
|
export async function initProfileUpdater(): Promise<void> {
|
||||||
const { items } = getProfileConfig()
|
const { items, current } = getProfileConfig()
|
||||||
|
const currentItem = getCurrentProfileItem()
|
||||||
for (const item of items) {
|
for (const item of items.filter((i) => i.id !== current)) {
|
||||||
if (item.type === 'remote' && item.interval) {
|
if (item.type === 'remote' && item.interval) {
|
||||||
addProfileItem(getProfileItem(item.id))
|
await addProfileItem(item)
|
||||||
intervalPool[item.id] = setInterval(
|
intervalPool[item.id] = setInterval(
|
||||||
() => {
|
async () => {
|
||||||
addProfileItem(getProfileItem(item.id))
|
await addProfileItem(item)
|
||||||
},
|
},
|
||||||
item.interval * 60 * 1000
|
item.interval * 60 * 1000
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (currentItem.type === 'remote' && currentItem.interval) {
|
||||||
|
await addProfileItem(currentItem)
|
||||||
|
intervalPool[currentItem.id] = setInterval(
|
||||||
|
async () => {
|
||||||
|
await addProfileItem(currentItem)
|
||||||
|
},
|
||||||
|
currentItem.interval * 60 * 1000 + 10000 // +10s
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addProfileUpdater(id: string): void {
|
export function addProfileUpdater(id: string): void {
|
||||||
const { items } = getProfileConfig()
|
const item = getProfileItem(id)
|
||||||
const item = items.find((i) => i.id === id)
|
|
||||||
|
|
||||||
if (item?.type === 'remote' && item.interval) {
|
if (item.type === 'remote' && item.interval) {
|
||||||
if (intervalPool[id]) {
|
if (intervalPool[id]) {
|
||||||
clearInterval(intervalPool[id])
|
clearInterval(intervalPool[id])
|
||||||
}
|
}
|
||||||
intervalPool[id] = setInterval(
|
intervalPool[id] = setInterval(
|
||||||
() => {
|
async () => {
|
||||||
addProfileItem(getProfileItem(id))
|
await addProfileItem(item)
|
||||||
},
|
},
|
||||||
item.interval * 60 * 1000
|
item.interval * 60 * 1000
|
||||||
)
|
)
|
||||||
|
|||||||
@ -74,7 +74,6 @@ const buildContextMenu = (): Menu => {
|
|||||||
window?.webContents.send('appConfigUpdated')
|
window?.webContents.send('appConfigUpdated')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setAppConfig({ sysProxy: { enable: !enable } })
|
setAppConfig({ sysProxy: { enable: !enable } })
|
||||||
console.error(e)
|
|
||||||
} finally {
|
} finally {
|
||||||
updateTrayMenu()
|
updateTrayMenu()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,9 +59,9 @@ if (!gotTheLock) {
|
|||||||
// Set app user model id for windows
|
// Set app user model id for windows
|
||||||
electronApp.setAppUserModelId('party.mihomo.app')
|
electronApp.setAppUserModelId('party.mihomo.app')
|
||||||
startCore().then(() => {
|
startCore().then(() => {
|
||||||
setTimeout(() => {
|
setTimeout(async () => {
|
||||||
initProfileUpdater()
|
await initProfileUpdater()
|
||||||
}, 30000)
|
}, 60000)
|
||||||
})
|
})
|
||||||
// Default open or close DevTools by F12 in development
|
// Default open or close DevTools by F12 in development
|
||||||
// and ignore CommandOrControl + R in production.
|
// and ignore CommandOrControl + R in production.
|
||||||
|
|||||||
@ -116,7 +116,7 @@ export function registerIpcMainHandlers(): void {
|
|||||||
function getFilePath(ext: string[]): string[] | undefined {
|
function getFilePath(ext: string[]): string[] | undefined {
|
||||||
return dialog.showOpenDialogSync({
|
return dialog.showOpenDialogSync({
|
||||||
title: '选择订阅文件',
|
title: '选择订阅文件',
|
||||||
filters: [{ name: 'Yaml Files', extensions: ext }],
|
filters: [{ name: `${ext} file`, extensions: ext }],
|
||||||
properties: ['openFile']
|
properties: ['openFile']
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,12 +19,8 @@ const SysproxySwitcher: React.FC = () => {
|
|||||||
id: 'sysproxy'
|
id: 'sysproxy'
|
||||||
})
|
})
|
||||||
const onChange = async (enable: boolean): Promise<void> => {
|
const onChange = async (enable: boolean): Promise<void> => {
|
||||||
try {
|
await triggerSysProxy(enable)
|
||||||
await triggerSysProxy(enable)
|
await patchAppConfig({ sysProxy: { enable } })
|
||||||
await patchAppConfig({ sysProxy: { enable } })
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -90,9 +90,8 @@ const Sysproxy: React.FC = () => {
|
|||||||
try {
|
try {
|
||||||
await triggerSysProxy(true)
|
await triggerSysProxy(true)
|
||||||
await patchAppConfig({ sysProxy: { enable: true } })
|
await patchAppConfig({ sysProxy: { enable: true } })
|
||||||
} catch (e) {
|
} catch {
|
||||||
await patchAppConfig({ sysProxy: { enable: false } })
|
await patchAppConfig({ sysProxy: { enable: false } })
|
||||||
console.error(e)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user