-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16fbaab
commit 0f35553
Showing
6 changed files
with
139 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
const Config = require('electron-config'); | ||
|
||
module.exports = new Config({ | ||
defaults: { | ||
zoomFactor: 1, | ||
lastWindowState: { | ||
width: 800, | ||
height: 600 | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,139 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const app = require('app'); | ||
const BrowserWindow = require('browser-window'); | ||
const Dialog = require('dialog'); | ||
const shell = require('shell'); | ||
const electron = require('electron'); | ||
const config = require('./config') | ||
|
||
const app = electron.app; | ||
|
||
require('electron-debug')(); | ||
require('crash-reporter').start(); | ||
require('electron-dl')(); | ||
require('electron-context-menu')(); | ||
|
||
let mainWindow; | ||
let isQuitting = false; | ||
|
||
function updateBadge(title) { | ||
if (!app.dock) { | ||
return; | ||
} | ||
if (!app.dock) { | ||
return; | ||
} | ||
|
||
if (title.indexOf('Messenger') === -1) { | ||
return; | ||
} | ||
if (title.indexOf('Messenger') === -1) { | ||
return; | ||
} | ||
|
||
const messageCount = (/\(([0-9]+)\)/).exec(title); | ||
app.dock.setBadge(messageCount ? messageCount[1] : ''); | ||
const messageCount = (/\(([0-9]+)\)/).exec(title); | ||
app.dock.setBadge(messageCount ? messageCount[1] : ''); | ||
} | ||
|
||
function createMainWindow() { | ||
const win = new BrowserWindow({ | ||
'title': app.getName(), | ||
'show': false, | ||
'width': 800, | ||
'height': 600, | ||
'icon': process.platform === 'linux' && path.join(__dirname, 'media', 'Icon.png'), | ||
'min-width': 400, | ||
'min-height': 200, | ||
'title-bar-style': 'hidden-inset', | ||
'web-preferences': { | ||
// fails without this because of CommonJS script detection | ||
'node-integration': false, | ||
|
||
'preload': path.join(__dirname, 'browser.js'), | ||
|
||
// required for Facebook active ping thingy | ||
'web-security': false, | ||
|
||
'plugins': true | ||
const lastWindowState = config.get('lastWindowState'); | ||
const win = new electron.BrowserWindow({ | ||
title: app.getName(), | ||
show: false, | ||
x: lastWindowState.x, | ||
y: lastWindowState.y, | ||
width: lastWindowState.width, | ||
height: lastWindowState.height, | ||
icon: process.platform === 'linux' && path.join(__dirname, 'static', 'Icon.png'), | ||
minWidth: 400, | ||
minHeight: 200, | ||
titleBarStyle: 'hidden-inset', | ||
autoHideMenuBar: true, | ||
webPreferences: { | ||
nodeIntegration: false, | ||
preload: path.join(__dirname, 'browser.js'), | ||
plugins: true | ||
} | ||
}); | ||
|
||
if (process.platform === 'darwin') { | ||
win.setSheetOffset(40); | ||
} | ||
|
||
win.loadURL('https://trello.com/login'); | ||
win.on('close', e => { | ||
if (!isQuitting) { | ||
e.preventDefault(); | ||
|
||
if (process.platform === 'darwin') { | ||
app.hide(); | ||
} else { | ||
win.hide(); | ||
} | ||
} | ||
}); | ||
//win.on('page-title-updated', (e, title) => updateBadge(title)); | ||
|
||
win.loadUrl('https://trello.com/login'); | ||
win.on('closed', app.quit); | ||
//win.on('page-title-updated', (e, title) => updateBadge(title)); | ||
|
||
return win; | ||
return win; | ||
} | ||
|
||
app.on('ready', () => { | ||
|
||
mainWindow = createMainWindow(); | ||
|
||
const page = mainWindow.webContents; | ||
|
||
page.on('dom-ready', () => { | ||
page.insertCSS(fs.readFileSync(path.join(__dirname, 'browser.css'), 'utf8')); | ||
mainWindow.show(); | ||
}); | ||
|
||
page.on('new-window', (e, url) => { | ||
e.preventDefault(); | ||
shell.openExternal(url); | ||
}); | ||
mainWindow = createMainWindow(); | ||
|
||
const page = mainWindow.webContents; | ||
|
||
page.on('dom-ready', () => { | ||
page.insertCSS(fs.readFileSync(path.join(__dirname, 'browser.css'), 'utf8')); | ||
mainWindow.show(); | ||
}); | ||
|
||
page.on('new-window', (e, url) => { | ||
e.preventDefault(); | ||
shell.openExternal(url); | ||
}); | ||
|
||
mainWindow.webContents.session.on('will-download', (event, item) => { | ||
const totalBytes = item.getTotalBytes(); | ||
|
||
item.on('updated', () => { | ||
mainWindow.setProgressBar(item.getReceivedBytes() / totalBytes); | ||
}); | ||
|
||
item.on('done', (e, state) => { | ||
mainWindow.setProgressBar(-1); | ||
|
||
if (state === 'interrupted') { | ||
Dialog.showErrorBox('Download error', 'The download was interrupted'); | ||
} | ||
}); | ||
}); | ||
|
||
var template = [{ | ||
label: "Application", | ||
submenu: [ | ||
{ label: "About Application", selector: "orderFrontStandardAboutPanel:" }, | ||
{ type: "separator" }, | ||
{ label: "Quit", accelerator: "Command+Q", click: function() { app.quit(); }} | ||
]}, { | ||
label: "Edit", | ||
submenu: [ | ||
{ label: "Undo", accelerator: "CmdOrCtrl+Z", selector: "undo:" }, | ||
{ label: "Redo", accelerator: "Shift+CmdOrCtrl+Z", selector: "redo:" }, | ||
{ type: "separator" }, | ||
{ label: "Cut", accelerator: "CmdOrCtrl+X", selector: "cut:" }, | ||
{ label: "Copy", accelerator: "CmdOrCtrl+C", selector: "copy:" }, | ||
{ label: "Paste", accelerator: "CmdOrCtrl+V", selector: "paste:" }, | ||
{ label: "Select All", accelerator: "CmdOrCtrl+A", selector: "selectAll:" } | ||
]} | ||
]; | ||
|
||
electron.Menu.setApplicationMenu(electron.Menu.buildFromTemplate(template)); | ||
}); | ||
|
||
mainWindow.webContents.session.on('will-download', (event, item) => { | ||
const totalBytes = item.getTotalBytes(); | ||
app.on("window-all-closed", function(){ | ||
app.quit(); | ||
}); | ||
|
||
item.on('updated', () => { | ||
mainWindow.setProgressBar(item.getReceivedBytes() / totalBytes); | ||
}); | ||
app.on('activate', () => { | ||
mainWindow.show(); | ||
}); | ||
|
||
item.on('done', (e, state) => { | ||
mainWindow.setProgressBar(-1); | ||
app.on('before-quit', () => { | ||
isQuitting = true; | ||
|
||
if (state === 'interrupted') { | ||
Dialog.showErrorBox('Download error', 'The download was interrupted'); | ||
} | ||
}); | ||
}); | ||
if (!mainWindow.isFullScreen()) { | ||
config.set('lastWindowState', mainWindow.getBounds()); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.