Skip to content

Commit

Permalink
Fixing initial login screen and window size on exit; fix danielchatfi…
Browse files Browse the repository at this point in the history
  • Loading branch information
yurivecchi committed Jun 18, 2017
1 parent 76462aa commit 8060063
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 99 deletions.
201 changes: 105 additions & 96 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,113 +14,122 @@ let mainWindow;
let isQuitting = false;

function createMainWindow() {
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 {
app.quit();
}
}
});

return win;
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/');

win.on('close', e => {
if (!isQuitting) {
e.preventDefault();

if (process.platform === 'darwin') {
app.hide();
} else {
app.quit();
}
} else {
if (!mainWindow.isFullScreen()) {
config.set('lastWindowState', mainWindow.getBounds());
}
}

});

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();
electron.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') {
electron.Dialog.showErrorBox('Download error', 'The download was interrupted');
}
});
});

const template = [{
label: 'Application',
submenu: [
{label: 'About Application', selector: 'orderFrontStandardAboutPanel:'},
{type: 'separator'},
{label: 'Quit', accelerator: 'Command+Q', click: () => {
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 = 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();
electron.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') {
electron.Dialog.showErrorBox('Download error', 'The download was interrupted');
}
});
});

const template = [{
label: 'Application',
submenu: [
{label: 'About Application', selector: 'orderFrontStandardAboutPanel:'},
{type: 'separator'},
{
label: 'Quit', accelerator: 'Command+Q', click: () => {
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));
});

app.on('window-all-closed', () => {
app.quit();
app.quit();
});

app.on('activate', () => {
mainWindow.show();
mainWindow.show();
});

app.on('before-quit', () => {
isQuitting = true;
isQuitting = true;

if (!mainWindow.isFullScreen()) {
config.set('lastWindowState', mainWindow.getBounds());
}
if (!mainWindow.isFullScreen()) {
config.set('lastWindowState', mainWindow.getBounds());
}
});
6 changes: 3 additions & 3 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.1.2",
"version": "0.1.3",
"description": "Unofficial Trello desktop app",
"license": "MIT",
"repository": "danielchatfield/trello-desktop",
Expand Down Expand Up @@ -42,8 +42,8 @@
"electron-dl": "^1.0.0"
},
"devDependencies": {
"electron-packager": "^7.0.4",
"electron-prebuilt": "^1.2.3",
"electron-packager": "^8.7.1",
"electron": "^1.7.3",
"xo": "*"
},
"xo": {
Expand Down

0 comments on commit 8060063

Please sign in to comment.