123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- import { app, BrowserWindow, dialog, ipcMain } from 'electron'
- import { resolve } from 'path'
- import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-assembler'
- import path from 'path'
- import fs from 'fs'
- if (!app.requestSingleInstanceLock()) {
- app.quit()
- process.exit(0)
- }
- // async function createWindow() {
- // const loadingView = new BrowserWindow({
- // width: 520,
- // height: 150,
- // frame: false,
- // icon: path.join(__dirname, './icons/icon.png'),
- // resizable: false,
- // transparent: true,
- // show: true,
- // // webPreferences: {
- // // preload: path.join(__dirname, '../preload/preload'),
- // // },
- // })
- // loadingView.loadFile(resolve(__dirname, 'loading.html'))
- // const mainWin = new BrowserWindow({
- // show: false,
- // width: 1680,
- // height: 900,
- // frame: false,
- // center: true,
- // icon: path.join(__dirname, './icons/icon.png'),
- // resizable: false,
- // fullscreen: app.isPackaged ? true : false,
- // fullscreenable: true,
- // alwaysOnTop: false,
- // useContentSize: true,
- // transparent: true,
- // webPreferences: {
- // devTools: true,
- // nodeIntegration: false,
- // contextIsolation: true,
- // webSecurity: false,
- // experimentalFeatures: true,
- // navigateOnDragDrop: false,
- // disableHtmlFullscreenWindowResize: false,
- // // preload: path.join(__dirname, '../preload/preload'),
- // },
- // })
- // mainWin.setMenu(null)
- // if (!app.isPackaged) {
- // mainWin.webContents.on('before-input-event', (event, input) => {
- // if (input.key === 'F12') {
- // mainWin.webContents.openDevTools()
- // }
- // })
- // }
- // mainWin.on('ready-to-show', () => {
- // loadingView.destroy()
- // mainWin.show()
- // })
- // if (app.isPackaged) {
- // mainWin.loadURL('http://cet-test.markingtool.cn')
- // // mainWin.loadURL('http://192.168.10.177:81')
- // } else {
- // installDevTool(VUEJS_DEVTOOLS)
- // process.env.WEB_DEV_INDEX_URL && mainWin.loadURL(process.env.WEB_DEV_INDEX_URL)
- // }
- // }
- let mainWin: any = null
- async function createWindow() {
- const loadingView = new BrowserWindow({
- width: 520,
- height: 150,
- frame: false,
- icon: path.join(__dirname, './icons/icon.ico'),
- resizable: false,
- transparent: true,
- show: true,
- // webPreferences: {
- // preload: path.join(__dirname, '../preload/preload'),
- // },
- })
- loadingView.loadFile(resolve(__dirname, 'loading.html'))
- // if (!app.isPackaged) {
- // try {
- // await installExtension(VUEJS_DEVTOOLS)
- // } catch (e) {
- // console.error('Vue Devtools failed to install:', e.toString())
- // }
- // }
- mainWin = new BrowserWindow({
- show: false,
- width: 1680,
- height: 900,
- frame: false,
- center: true,
- icon: path.join(__dirname, './icons/icon.ico'),
- resizable: false,
- fullscreen: app.isPackaged ? true : true,
- fullscreenable: true,
- alwaysOnTop: false,
- useContentSize: true,
- transparent: true,
- webPreferences: {
- devTools: true,
- nodeIntegration: false,
- contextIsolation: true,
- webSecurity: false,
- experimentalFeatures: true,
- navigateOnDragDrop: false,
- disableHtmlFullscreenWindowResize: false,
- preload: path.join(__dirname, '../preload/preload'),
- },
- })
- mainWin.setMenu(null)
- // if (!app.isPackaged) {
- mainWin.webContents.on('before-input-event', (event, input) => {
- if (input.key === 'F12' && input.control) {
- mainWin.webContents.openDevTools()
- }
- })
- // }
- mainWin.on('ready-to-show', () => {
- loadingView.destroy()
- mainWin.show()
- })
- if (app.isPackaged) {
- const filePath = path.join(process.env.PORTABLE_EXECUTABLE_DIR as string, 'config.json')
- if (!fs.existsSync(filePath)) {
- dialog.showErrorBox('找不到配置文件', 'config.json文件不存在!')
- app.quit()
- } else {
- fs.readFile(filePath, 'utf-8', function (err, data) {
- if (!err) {
- let da: any = {}
- try {
- da = JSON.parse(data)
- } catch (error) {
- dialog.showErrorBox('错误', '您的config.json文件内容格式可能不正确,请检查!')
- app.quit()
- }
- const url = da.url || ''
- if (!!url) {
- mainWin.loadURL(url)
- }
- } else {
- dialog.showErrorBox('错误', JSON.stringify(err))
- app.quit()
- }
- })
- }
- } else {
- // mainWin.loadURL('http://cet-test.markingtool.cn')
- process.env.WEB_DEV_INDEX_URL && mainWin.loadURL(process.env.WEB_DEV_INDEX_URL)
- }
- }
- ipcMain.on('window-min', () => {
- mainWin.minimize()
- })
- app.on('window-all-closed', () => {
- if (process.platform !== 'darwin') app.quit()
- })
- app.whenReady().then(createWindow)
|