Skip to content

Commit

Permalink
loads of updates
Browse files Browse the repository at this point in the history
  • Loading branch information
danielchatfield committed Jun 18, 2016
1 parent 16fbaab commit 0f35553
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 73 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Name=Trello
Exec=/full/path/to/folder/Trello
Terminal=false
Type=Application
Icon=/full/path/to/folder/Trello/resources/app/media/Icon.png
Icon=/full/path/to/folder/Trello/resources/app/static/Icon.png
```

### Windows
Expand Down
12 changes: 12 additions & 0 deletions config.js
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
}
}
});
175 changes: 113 additions & 62 deletions index.js
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());
}
});
23 changes: 13 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "trello-desktop",
"productName": "Trello",
"desktopName": "Trello",
"version": "0.0.1",
"version": "0.1.0",
"description": "Unofficial Trello desktop app",
"license": "MIT",
"repository": "danielchatfield/trello-desktop",
Expand All @@ -18,28 +18,31 @@
"scripts": {
"test": "xo",
"start": "electron .",
"build": "npm run build-osx && npm run build-linux && npm run build-windows",
"build-osx": "electron-packager . $npm_package_productName --overwrite --out=dist --ignore='^/dist$' --ignore='^/media$' --prune --platform=darwin --arch=x64 --icon=media/Icon.icns --app-bundle-id=com.danielchatfield.trello-desktop --sign='Developer ID Application: Daniel Chatfield (BB2HNG5KBM)' --app-version=$npm_package_version --version=$npm_package_electronVersion && cd ./dist/Trello-darwin-x64 && zip -ryXq9 ../Trello-osx-${npm_package_version}.zip Trello.app",
"build-linux": "electron-packager . $npm_package_productName --overwrite --out=dist --ignore='^/dist$' --ignore='^/media/(?!Icon.png$).*' --prune --platform=linux --arch=x64 --app-bundle-id=com.danielchatfield.trello-desktop --app-version=$npm_package_version --version=$npm_package_electronVersion && cd ./dist/Trello-linux-x64/ && zip -ryq9 ../Trello-linux-\"$npm_package_version\".zip *",
"build-windows": "electron-packager . $npm_package_productName --overwrite --out=dist --ignore='^/dist$' --ignore='^/media/(?!Icon.ico$).*' --prune --platform=win32 --arch=ia32 --icon=media/Icon.ico --version=$npm_package_electronVersion --version-string.ProductName=$npm_package_productName --version-string.ProductVersion=$npm_package_electronVersion && cd ./dist/Trello-win32-ia32/ && zip -ryq9 ../Trello-windows-\"$npm_package_version\".zip *"
"build": "npm run build:macos && npm run build:linux && npm run build:windows",
"build:macos": "electron-packager . --overwrite --asar --out=dist --ignore='^media$' --prune --platform=darwin --arch=x64 --icon=static/Icon.icns --app-bundle-id=com.danielchatfield.trello-desktop --sign='Developer ID Application: Daniel Chatfield (BB2HNG5KBM)' --app-version=$npm_package_version && cd dist/Trello-darwin-x64 && zip -ryXq9 ../Trello-osx-${npm_package_version}.zip Trello.app",
"build:linux": "electron-packager . --overwrite --out=dist --ignore='^media$' --prune --platform=linux --arch=x64 --app-bundle-id=com.danielchatfield.trello-desktop --app-version=$npm_package_version && cd dist/Trello-linux-x64/ && zip -ryq9 ../Trello-linux-${npm_package_version}.zip *",
"build:windows": "electron-packager . --overwrite --asar --out=dist --ignore='^media$' --prune --platform=win32 --arch=ia32 --icon=static/Icon.ico --version-string.ProductName=$npm_package_productName --app-version=$npm_package_version && cd dist/Trello-win32-ia32 && zip -ryq9 ../Trello-windows-${npm_package_version}.zip *"
},
"files": [
"index.js",
"browser.js",
"browser.css",
"media/Icon.icns",
"media/Icon.ico"
"static/Icon.icns",
"static/Icon.ico"
],
"keywords": [
"electron-app",
"trello"
],
"dependencies": {
"electron-debug": "^0.2.1"
"electron-config": "^0.1.1",
"electron-context-menu": "^0.1.0",
"electron-debug": "^1.0.0",
"electron-dl": "^1.0.0"
},
"devDependencies": {
"electron-packager": "^5.1.0",
"electron-prebuilt": "^0.34.3",
"electron-packager": "^7.0.4",
"electron-prebuilt": "^1.2.3",
"xo": "*"
},
"xo": {
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 0f35553

Please sign in to comment.