初始提交
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
const { mainOn } = require('../../common/icp')
|
||||
const { app } = require('electron')
|
||||
const { name: defaultName } = require('../../../package.json')
|
||||
|
||||
|
||||
mainOn('appName', (event, params) => {
|
||||
if (params == null) {
|
||||
app.setName(defaultName)
|
||||
} else {
|
||||
app.setName(params.name)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
require('./request')
|
||||
require('./appName')
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
const { mainOn } = require('../../common/icp')
|
||||
|
||||
module.exports = win => {
|
||||
mainOn('progress', (event, params) => {
|
||||
// console.log(params)
|
||||
win.setProgressBar(params.status, {
|
||||
mode: params.mode || 'normal',
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
const request = require('request')
|
||||
|
||||
const { mainOn } = require('../../common/icp')
|
||||
|
||||
const tasks = []
|
||||
|
||||
mainOn('request', (event, options) => {
|
||||
// console.log(args)
|
||||
if (!options) return
|
||||
let index = fatchData(options, (err, resp) => {
|
||||
tasks[index] = null
|
||||
if (err) {
|
||||
console.log(err)
|
||||
event.sender.send('response', err.message, null)
|
||||
return
|
||||
}
|
||||
event.sender.send('response', null, resp.body)
|
||||
})
|
||||
event.returnValue = index
|
||||
})
|
||||
|
||||
mainOn('cancelRequest', (event, index) => {
|
||||
if (index == null) return
|
||||
let r = tasks[index]
|
||||
if (r == null) return
|
||||
r.abort()
|
||||
tasks[index] = null
|
||||
})
|
||||
|
||||
const fatchData = (options, callback) => pushTask(tasks, request(options.url, {
|
||||
method: options.method,
|
||||
headers: options.headers,
|
||||
Origin: options.origin,
|
||||
}, (err, resp) => {
|
||||
if (err) return callback(err, null)
|
||||
callback(null, resp)
|
||||
}))
|
||||
|
||||
const pushTask = (tasks, newTask) => {
|
||||
for (const [index, task] of tasks.entries()) {
|
||||
if (task == null) {
|
||||
return tasks[index].push(newTask)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
const { mainOn } = require('../../common/icp')
|
||||
const { dialog } = require('electron')
|
||||
|
||||
module.exports = win => {
|
||||
mainOn('selectPath', (event, params) => {
|
||||
let path = dialog.showOpenDialog(win, params.options)
|
||||
if (path === undefined) return
|
||||
event.sender.send(params.eventName, path)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
const { mainOn } = require('../../common/icp')
|
||||
|
||||
module.exports = win => {
|
||||
mainOn('min', event => {
|
||||
if (win) {
|
||||
win.minimize()
|
||||
}
|
||||
})
|
||||
// mainOn('max', event => {
|
||||
// if (win) {
|
||||
// win.maximize()
|
||||
// }
|
||||
// })
|
||||
mainOn('close', event => {
|
||||
if (win) {
|
||||
win.close()
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* This file is used specifically and only for development. It installs
|
||||
* `electron-debug` & `vue-devtools`. There shouldn't be any need to
|
||||
* modify this file, but it can be used to extend your development
|
||||
* environment.
|
||||
*/
|
||||
const electron = require('electron')
|
||||
const electronDebug = require('electron-debug')
|
||||
const { default: installExtension, VUEJS_DEVTOOLS } = require('electron-devtools-installer')
|
||||
// Install `electron-debug` with `devtron`
|
||||
electronDebug({
|
||||
showDevTools: true,
|
||||
devToolsMode: 'undocked',
|
||||
})
|
||||
|
||||
// Install `vue-devtools`
|
||||
electron.app.on('ready', () => {
|
||||
installExtension(VUEJS_DEVTOOLS)
|
||||
.then(name => console.log(`Added Extension: ${name}`))
|
||||
.catch(err => console.log('An error occurred: ', err))
|
||||
})
|
||||
|
||||
// Require `main` process to boot app
|
||||
require('./index')
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
const { app, BrowserWindow } = require('electron')
|
||||
const path = require('path')
|
||||
|
||||
require('./events')
|
||||
const progressBar = require('./events/progressBar')
|
||||
const trafficLight = require('./events/trafficLight')
|
||||
const autoUpdate = require('./utils/autoUpdate')
|
||||
|
||||
const isDev = process.env.NODE_ENV !== 'production'
|
||||
|
||||
/**
|
||||
* Set `__static` path to static files in production
|
||||
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
|
||||
*/
|
||||
|
||||
let mainWindow
|
||||
let winURL
|
||||
|
||||
if (isDev) {
|
||||
global.__static = path.join(__dirname, '../static')
|
||||
winURL = `http://localhost:9080`
|
||||
} else {
|
||||
global.__static = path.join(__dirname, '/static')
|
||||
winURL = `file://${__dirname}/index.html`
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
/**
|
||||
* Initial window options
|
||||
*/
|
||||
mainWindow = new BrowserWindow({
|
||||
height: 590,
|
||||
useContentSize: true,
|
||||
width: 920,
|
||||
frame: false,
|
||||
transparent: true,
|
||||
icon: path.join(global.__static, 'icons/lunch.ico'),
|
||||
resizable: false,
|
||||
maximizable: false,
|
||||
fullscreenable: false,
|
||||
webPreferences: {
|
||||
// contextIsolation: true,
|
||||
webSecurity: !isDev,
|
||||
nodeIntegration: true,
|
||||
},
|
||||
})
|
||||
|
||||
mainWindow.loadURL(winURL)
|
||||
|
||||
mainWindow.on('closed', () => {
|
||||
mainWindow = null
|
||||
})
|
||||
|
||||
// mainWindow.webContents.openDevTools()
|
||||
|
||||
trafficLight(mainWindow)
|
||||
progressBar(mainWindow)
|
||||
if (!isDev) autoUpdate(mainWindow)
|
||||
}
|
||||
|
||||
app.once('ready', createWindow)
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
||||
app.on('activate', () => {
|
||||
if (mainWindow === null) {
|
||||
createWindow()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
const log = require('electron-log')
|
||||
const { autoUpdater } = require('electron-updater')
|
||||
const { mainOn } = require('../../common/icp')
|
||||
|
||||
autoUpdater.logger = log
|
||||
autoUpdater.logger.transports.file.level = 'info'
|
||||
log.info('App starting...')
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Open a window that displays the version
|
||||
//
|
||||
// THIS SECTION IS NOT REQUIRED
|
||||
//
|
||||
// This isn't required for auto-updates to work, but it's easier
|
||||
// for the app to show a window than to have to click "About" to see
|
||||
// that updates are working.
|
||||
// -------------------------------------------------------------------
|
||||
// let win
|
||||
|
||||
function sendStatusToWindow(text) {
|
||||
log.info(text)
|
||||
// win.webContents.send('message', text)
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Auto updates
|
||||
//
|
||||
// For details about these events, see the Wiki:
|
||||
// https://github.com/electron-userland/electron-builder/wiki/Auto-Update#events
|
||||
//
|
||||
// The app doesn't need to listen to any events except `update-downloaded`
|
||||
//
|
||||
// Uncomment any of the below events to listen for them. Also,
|
||||
// look in the previous section to see them being used.
|
||||
// -------------------------------------------------------------------
|
||||
// autoUpdater.on('checking-for-update', () => {
|
||||
// })
|
||||
// autoUpdater.on('update-available', (ev, info) => {
|
||||
// })
|
||||
// autoUpdater.on('update-not-available', (ev, info) => {
|
||||
// })
|
||||
// autoUpdater.on('error', (ev, err) => {
|
||||
// })
|
||||
// autoUpdater.on('download-progress', (ev, progressObj) => {
|
||||
// })
|
||||
// autoUpdater.on('update-downloaded', (ev, info) => {
|
||||
// // Wait 5 seconds, then quit and install
|
||||
// // In your application, you don't need to wait 5 seconds.
|
||||
// // You could call autoUpdater.quitAndInstall(); immediately
|
||||
// // setTimeout(function() {
|
||||
// // autoUpdater.quitAndInstall()
|
||||
// // }, 5000)
|
||||
|
||||
// })
|
||||
|
||||
|
||||
module.exports = win => {
|
||||
autoUpdater.on('checking-for-update', () => {
|
||||
sendStatusToWindow('Checking for update...')
|
||||
})
|
||||
autoUpdater.on('update-available', (ev, info) => {
|
||||
sendStatusToWindow('Update available.')
|
||||
})
|
||||
autoUpdater.on('update-not-available', (ev, info) => {
|
||||
sendStatusToWindow('Update not available.')
|
||||
})
|
||||
autoUpdater.on('error', (ev, err) => {
|
||||
sendStatusToWindow('Error in auto-updater.')
|
||||
})
|
||||
autoUpdater.on('download-progress', (ev, progressObj) => {
|
||||
sendStatusToWindow('Download progress...')
|
||||
})
|
||||
autoUpdater.on('update-downloaded', (ev, info) => {
|
||||
sendStatusToWindow('Update downloaded.')
|
||||
win.webContents.send('update-downloaded')
|
||||
})
|
||||
mainOn('quit-update', () => {
|
||||
setTimeout(() => {
|
||||
autoUpdater.quitAndInstall(true, true)
|
||||
}, 1000)
|
||||
})
|
||||
|
||||
autoUpdater.checkForUpdates()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user