Feat:双击文件打开应用时不打开工作台页面

This commit is contained in:
街角小林 2024-03-13 16:58:55 +08:00
parent 910bfb23d4
commit 5b701f5333
2 changed files with 14 additions and 9 deletions

View File

@ -16,6 +16,11 @@ protocol.registerSchemesAsPrivileged([
// 创建主页面
let mainWindow = null
async function createMainWindow() {
createProtocol('app')
// 如果是双击smm文件打开的话那么不用加载工作台页面
if (initOpenFileQueue.length > 0) {
return
}
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
@ -37,7 +42,6 @@ async function createMainWindow() {
)
// if (!process.env.IS_TEST) mainWindow.webContents.openDevTools()
} else {
createProtocol('app')
// 非开发环境时加载index.html
mainWindow.loadURL('app://./index.html/#/workbenche')
}
@ -46,8 +50,13 @@ async function createMainWindow() {
// 绑定事件
let openFile = null
const bindEvent = () => {
let res = bindFileHandleEvent({ mainWindow, initOpenFileQueue })
const res = bindFileHandleEvent({ mainWindow })
openFile = res.openFile
// 直接双击文件打开应用时,需要直接打开该文件编辑
initOpenFileQueue.forEach(file => {
openFile(null, file)
})
initOpenFileQueue = []
bindOtherHandleEvent()
}
@ -71,7 +80,7 @@ app.on('activate', () => {
// https://stackoverflow.com/questions/62420427/how-do-i-make-my-electron-app-the-default-for-opening-files
// https://github.com/rchrd2/example-electron-file-association
// https://www.jianshu.com/p/a32542277b83
const initOpenFileQueue = []
let initOpenFileQueue = []
app.on('will-finish-launching', () => {
// Event fired When someone drags files onto the icon while your app is running
if (process.platform == 'win32') {

View File

@ -11,9 +11,10 @@ import {
} from './storage'
import { v4 as uuid } from 'uuid'
export const bindFileHandleEvent = ({ mainWindow, initOpenFileQueue }) => {
export const bindFileHandleEvent = ({ mainWindow }) => {
// 通知主页面刷新最近文件列表
const notifyMainWindowRefreshRecentFileList = () => {
if (!mainWindow) return
mainWindow.webContents.send('refreshRecentFileList')
}
@ -264,11 +265,6 @@ export const bindFileHandleEvent = ({ mainWindow, initOpenFileQueue }) => {
})
})
// 直接双击文件打开应用时,需要直接打开该文件编辑
initOpenFileQueue.forEach(file => {
openFile(null, file)
})
return {
openFile
}