123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- 'use strict'
- import pkg from '../../package.json'
- import usbffi from './main-process/usb-ffi'
- import downloads from './main-process/downloads'
- import updateInstall from './main-process/updateInstall'
- import fileselect from './main-process/file-select'
- import db from '../database/index'
- const path = require('path')
- // const glob = require('glob')
- const electron = require('electron')
- const app = electron.app
- const BrowserWindow = electron.BrowserWindow
- const Menu = electron.Menu
- const autoUpdater = require('./software-update')
- /**
- * Set `__static` path to static files in production
- * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
- */
- if (process.env.NODE_ENV !== 'development') {
- global.__static = path.join(__dirname, '/static').replace(/\\/g, '\\\\')
- }
- let mainWindow
- let winURL = process.env.NODE_ENV === 'development'
- ? `http://localhost:9080`
- : `file://${__dirname}/index.html`
- let firsturl = db.read().get('sc_hadInstall.first').value()
- winURL += firsturl ? '/#/firstopen' : '/#' + db.read().get('sc_hadInstall.url').value()
- function initialize () {
- function createWindow () {
- Menu.setApplicationMenu(null)
- /**
- * Initial window options
- */
- const windowOptions = {
- // width: 900,
- width: 1450,
- height: 564,
- resizable: false,
- show: true,
- frame: false,
- fullscreenable: false,
- center: true,
- transparent: true,
- titleBarStyle: 'hidden',
- backgroundColor: '#fff',
- webPreferences: {
- backgroundThrottling: false
- }
- }
- mainWindow = new BrowserWindow(windowOptions)
- mainWindow.loadURL(winURL)
- // mainWindow.webContents.openDevTools()
- mainWindow.on('closed', () => {
- mainWindow = null
- })
- }
- let shouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory) {
- // 当另一个实例运行的时候,这里将会被调用,我们需要激活应用的窗口
- if (mainWindow) {
- if (mainWindow.isMinimized()) mainWindow.restore()
- mainWindow.focus()
- }
- return true
- })
- // 这个实例是多余的实例,需要退出
- if (shouldQuit) {
- app.quit()
- return
- }
- app.on('ready', function () {
- createWindow()
- loadJS(mainWindow)
- autoUpdater.initialize(mainWindow)
- })
- app.on('window-all-closed', () => {
- if (process.platform !== 'darwin') {
- app.quit()
- }
- })
- app.on('activate', () => {
- if (mainWindow === null) {
- createWindow()
- }
- })
- function loadJS (win) {
- // 无法使用require调用含异步的方法,只能采用import方式,原因不明,坑!
- // require('./main-process/usb-ffi').initialize(win)
- usbffi(win)
- downloads(win)
- updateInstall(win)
- fileselect(win)
- // require('./main-process/downloads').initialize(win)
- // let files = glob.sync(path.join(__dirname, './main-process/*.js'))
- // if (files !== []) {
- // files.forEach(function (file) {
- // require(file)
- // })
- // }
- // require('./main-process/download')
- }
- }
- initialize()
- if (process.platform === 'win32') {
- app.setAppUserModelId(pkg.build.appId)
- }
|