mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-06-08 17:10:20 +08:00
add executable file basic check
This commit is contained in:
@@ -2,6 +2,7 @@ import { BrowserWindow, dialog, ipcMain, shell } from 'electron'
|
||||
import gtag from './gtag'
|
||||
import buildInfo from '../../common/build-info.json'
|
||||
import os from 'node:os'
|
||||
import fs from 'node:fs'
|
||||
import {
|
||||
ensureStorageFileExist,
|
||||
readStorageFile,
|
||||
@@ -85,4 +86,28 @@ export default function initPublicIpc() {
|
||||
return dialog.showOpenDialog(win, fileChooserConfig)
|
||||
}
|
||||
})
|
||||
ipcMain.handle('check-executable-file', (ev, filePath: string) => {
|
||||
if (!filePath?.trim()) {
|
||||
return {
|
||||
message: '文件名无效'
|
||||
}
|
||||
}
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return {
|
||||
message: '文件不存在'
|
||||
}
|
||||
}
|
||||
if (!fs.statSync(filePath).isFile()) {
|
||||
const messageSeg = ['文件不是可执行文件']
|
||||
if (os.platform() === 'darwin') {
|
||||
messageSeg.push(
|
||||
'macOS 平台,可执行文件位于“App包.app/Contents/MacOS/ 文件夹下”,而不是“App包.app”文件夹整体'
|
||||
)
|
||||
}
|
||||
return {
|
||||
message: messageSeg.join(';')
|
||||
}
|
||||
}
|
||||
return null
|
||||
})
|
||||
}
|
||||
|
||||
@@ -124,15 +124,19 @@ const formData = ref({
|
||||
|
||||
const rules = {
|
||||
browserPath: {
|
||||
validator: (_, value, callback) => {
|
||||
validator: async (_, value, callback) => {
|
||||
if (!value?.trim()) {
|
||||
callback(new Error('请输入浏览器可执行文件路径'))
|
||||
return
|
||||
}
|
||||
// TODO: 检查文件是否存在
|
||||
else {
|
||||
const err = await ipcRenderer.invoke('check-executable-file', value)
|
||||
if (err) {
|
||||
callback(err?.message ?? '文件无效 - 未知原因')
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
},
|
||||
trigger: 'blur'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user