in progress: move webtorrent into background BrowserWindow
This commit is contained in:
43
index.js
43
index.js
@@ -1,7 +1,11 @@
|
||||
require('debug/browser')
|
||||
|
||||
var debug = require('debug')('index')
|
||||
var electron = require('electron')
|
||||
var path = require('path')
|
||||
|
||||
var app = electron.app
|
||||
var ipc = electron.ipcMain
|
||||
|
||||
// report crashes
|
||||
// require('crash-reporter').start({
|
||||
@@ -14,11 +18,12 @@ var app = electron.app
|
||||
// adds debug features like hotkeys for triggering dev tools and reload
|
||||
require('electron-debug')()
|
||||
|
||||
// prevent window being garbage collected
|
||||
var mainWindow
|
||||
// prevent windows from being garbage collected
|
||||
var mainWindow, backgroundWindow // eslint-disable-line no-unused-vars
|
||||
|
||||
app.on('ready', function () {
|
||||
mainWindow = createMainWindow()
|
||||
backgroundWindow = createBackgroundWindow()
|
||||
})
|
||||
|
||||
app.on('activate', function () {
|
||||
@@ -29,15 +34,43 @@ app.on('window-all-closed', function () {
|
||||
if (process.platform !== 'darwin') app.quit()
|
||||
})
|
||||
|
||||
ipc.on('action', function (event, action, ...args) {
|
||||
debug('action %s', action)
|
||||
backgroundWindow.webContents.send('action', action, ...args)
|
||||
})
|
||||
|
||||
function createMainWindow () {
|
||||
const win = new electron.BrowserWindow({
|
||||
var win = new electron.BrowserWindow({
|
||||
width: 600,
|
||||
height: 400,
|
||||
titleBarStyle: 'hidden'
|
||||
title: 'WebTorrent',
|
||||
// titleBarStyle: 'hidden',
|
||||
show: false
|
||||
})
|
||||
win.loadURL('file://' + path.join(__dirname, 'main.html'))
|
||||
win.webContents.on('did-finish-load', function () {
|
||||
win.show()
|
||||
})
|
||||
win.loadURL('file://' + path.join(__dirname, 'index.html'))
|
||||
win.once('closed', function () {
|
||||
mainWindow = null
|
||||
})
|
||||
return win
|
||||
}
|
||||
|
||||
function createBackgroundWindow () {
|
||||
var opts = debug.enabled
|
||||
? { width: 600, height: 400, x: 0, y: 0 }
|
||||
: { width: 0, height: 0, show: false }
|
||||
var win = new electron.BrowserWindow(opts)
|
||||
win.loadURL('file://' + path.join(__dirname, 'background.html'))
|
||||
win.once('closed', function () {
|
||||
backgroundWindow = null
|
||||
})
|
||||
return win
|
||||
}
|
||||
|
||||
// var progress = 0
|
||||
// setInterval(function () {
|
||||
// progress += 0.1
|
||||
// mainWindow.setProgressBar(progress)
|
||||
// }, 1000)
|
||||
|
||||
Reference in New Issue
Block a user