mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-16 03:32:17 +08:00
0.2.0
This commit is contained in:
parent
fd86c0dba4
commit
8093aa95bb
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "mihomo-party",
|
||||
"version": "0.1.6",
|
||||
"version": "0.2.0",
|
||||
"description": "Mihomo Party",
|
||||
"main": "./out/main/index.js",
|
||||
"author": "mihomo-party",
|
||||
|
|
|
@ -35,6 +35,7 @@ import { triggerSysProxy } from '../resolve/sysproxy'
|
|||
import { checkUpdate } from '../resolve/autoUpdater'
|
||||
import { exePath, mihomoCorePath } from './dirs'
|
||||
import { execSync } from 'child_process'
|
||||
import fs from 'fs'
|
||||
|
||||
export function registerIpcMainHandlers(): void {
|
||||
ipcMain.handle('mihomoVersion', mihomoVersion)
|
||||
|
@ -70,6 +71,8 @@ export function registerIpcMainHandlers(): void {
|
|||
ipcMain.handle('triggerSysProxy', (_e, enable) => triggerSysProxy(enable))
|
||||
ipcMain.handle('isEncryptionAvailable', isEncryptionAvailable)
|
||||
ipcMain.handle('encryptString', (_e, str) => safeStorage.encryptString(str))
|
||||
ipcMain.handle('getFilePath', getFilePath)
|
||||
ipcMain.handle('readTextFile', (_e, filePath) => readTextFile(filePath))
|
||||
ipcMain.handle('checkUpdate', () => checkUpdate())
|
||||
ipcMain.handle('getVersion', () => app.getVersion())
|
||||
ipcMain.handle('platform', () => process.platform)
|
||||
|
@ -77,6 +80,18 @@ export function registerIpcMainHandlers(): void {
|
|||
ipcMain.handle('quitApp', () => app.quit())
|
||||
}
|
||||
|
||||
function getFilePath(): string[] | undefined {
|
||||
return dialog.showOpenDialogSync({
|
||||
title: '选择订阅文件',
|
||||
filters: [{ name: 'Yaml Files', extensions: ['yml', 'yaml'] }],
|
||||
properties: ['openFile']
|
||||
})
|
||||
}
|
||||
|
||||
function readTextFile(filePath: string): string {
|
||||
return fs.readFileSync(filePath, 'utf8')
|
||||
}
|
||||
|
||||
async function setupFirewall(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const removeCommand = `
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Button, Input } from '@nextui-org/react'
|
|||
import BasePage from '@renderer/components/base/base-page'
|
||||
import ProfileItem from '@renderer/components/profiles/profile-item'
|
||||
import { useProfileConfig } from '@renderer/hooks/use-profile-config'
|
||||
import { getFilePath, readTextFile } from '@renderer/utils/ipc'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { MdContentPaste } from 'react-icons/md'
|
||||
|
||||
|
@ -40,22 +41,18 @@ const Profiles: React.FC = () => {
|
|||
e.stopPropagation()
|
||||
setFileOver(false)
|
||||
})
|
||||
pageRef.current?.addEventListener('drop', (event) => {
|
||||
pageRef.current?.addEventListener('drop', async (event) => {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
if (event.dataTransfer?.files) {
|
||||
const file = event.dataTransfer.files[0]
|
||||
if (file.name.endsWith('.yml') || file.name.endsWith('.yaml')) {
|
||||
const reader = new FileReader()
|
||||
reader.onload = async (e): Promise<void> => {
|
||||
const content = e.target?.result as string
|
||||
const content = await readTextFile(file.path)
|
||||
try {
|
||||
await addProfileItem({ name: file.name, type: 'local', file: content })
|
||||
} finally {
|
||||
setFileOver(false)
|
||||
}
|
||||
}
|
||||
reader.readAsText(file)
|
||||
} else {
|
||||
alert('不支持的文件类型')
|
||||
}
|
||||
|
@ -74,7 +71,6 @@ const Profiles: React.FC = () => {
|
|||
<div className="sticky top-[48px] z-40 backdrop-blur bg-background/40 flex p-2">
|
||||
<Input
|
||||
variant="bordered"
|
||||
className="mr-2"
|
||||
size="sm"
|
||||
value={url}
|
||||
onValueChange={setUrl}
|
||||
|
@ -96,12 +92,29 @@ const Profiles: React.FC = () => {
|
|||
<Button
|
||||
size="sm"
|
||||
color="primary"
|
||||
className="ml-2"
|
||||
isDisabled={url === ''}
|
||||
isLoading={importing}
|
||||
onPress={handleImport}
|
||||
>
|
||||
导入
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
color="primary"
|
||||
className="ml-2"
|
||||
onPress={() => {
|
||||
getFilePath().then(async (files) => {
|
||||
if (files?.length) {
|
||||
const content = await readTextFile(files[0])
|
||||
const fileName = files[0].split('/').pop()?.split('\\').pop()
|
||||
await addProfileItem({ name: fileName, type: 'local', file: content })
|
||||
}
|
||||
})
|
||||
}}
|
||||
>
|
||||
打开
|
||||
</Button>
|
||||
</div>
|
||||
<div
|
||||
className={`${fileOver ? 'blur-sm' : ''} grid sm:grid-cols-2 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-2 mx-2`}
|
||||
|
|
|
@ -131,6 +131,14 @@ export async function encryptString(str: string): Promise<Buffer> {
|
|||
return await window.electron.ipcRenderer.invoke('encryptString', str)
|
||||
}
|
||||
|
||||
export async function getFilePath(): Promise<string[] | undefined> {
|
||||
return await window.electron.ipcRenderer.invoke('getFilePath')
|
||||
}
|
||||
|
||||
export async function readTextFile(filePath: string): Promise<string> {
|
||||
return await window.electron.ipcRenderer.invoke('readTextFile', filePath)
|
||||
}
|
||||
|
||||
export async function checkUpdate(): Promise<string | undefined> {
|
||||
return await window.electron.ipcRenderer.invoke('checkUpdate')
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user