Skip to content

Commit

Permalink
Merge pull request #10 from arturock/update
Browse files Browse the repository at this point in the history
  • Loading branch information
artrz authored Aug 10, 2020
2 parents e509872 + 8a85086 commit 561ff90
Show file tree
Hide file tree
Showing 12 changed files with 655 additions and 1,100 deletions.
20 changes: 12 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
module.exports = {
"extends": [
"airbnb-base",
env: {
browser: true,
node: true,
},
extends: [
'airbnb-base',
],
settings: {
'import/core-modules': [
'electron',
],
"settings": {
"import/core-modules": [
"electron",
],
},
}
},
};
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.3.0] - 2020-08-10
### Added
- Version checker.
- Configure menu visibility.

### Changed
- Use notifications from main process.

### Updated
- Update electron and electron packager packages.

## [0.2.0] - 2020-08-07
### Added
- Add Back / Forward actions.
Expand Down
119 changes: 66 additions & 53 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ const {
shell,
Tray,
} = require('electron');
const path = require('path');
const settings = require('electron-settings');
const appPackage = require('./package.json');
const icon = require('./icon');
const menus = require('./menus');
const notification = require('./notification');
const settings = require('./settings');
const versionChecker = require('./versionChecker');

const ELECTRON_VERSION = process.versions.electron;
const APP_NAME = app.name;
const APP_VERSION = app.getVersion();
const APP_DESCRIPTION = 'Unofficial Basecamp GNU/Linux Desktop Client.';
const APP_DESCRIPTION = appPackage.description;
const BASECAMP_URL = 'https://launchpad.37signals.com';
const ICONS_PATH = path.join(app.getAppPath(), '..', 'assets', 'icons');
const DEFAULTS = {
iconScheme: 'white',
showBadge: true,
};

/** @type {BrowserWindow} */
let win;
let tray;
let unreadsNotified = false;
Expand All @@ -36,28 +35,30 @@ const basecamp = {
this.addTrayIcon();
this.setIcons();
this.addWindowEvents();
this.bootstrap();
},

/**
* Creates the app window.
*/
createWindow(url) {
win = new BrowserWindow({
y: settings.getSync('posY', 0),
x: settings.getSync('posX', 0),
width: settings.getSync('width', 770),
height: settings.getSync('height', 700),
const config = {
y: settings.get('posY'),
x: settings.get('posX'),
width: settings.get('width'),
height: settings.get('height'),
title: APP_NAME,
icon: this.getIcon('icon'),
autoHideMenuBar: true,
backgroundColor: '#f5efe6',
icon: icon('icon'),
autoHideMenuBar: settings.get('autoHideMenu'),
backgroundColor: settings.get('appBackgroundColor'),
webPreferences: {
nodeIntegration: false,
preload: `${__dirname}/integration.js`,
},
});
};

win = new BrowserWindow(config);

if (settings.getSync('isMaximized', false)) {
if (settings.get('isMaximized')) {
win.maximize();
}

Expand All @@ -68,11 +69,11 @@ const basecamp = {
win
.on('close', () => {
const bounds = win.getBounds();
settings.setSync('posX', bounds.x);
settings.setSync('posY', bounds.y);
settings.setSync('width', bounds.width);
settings.setSync('height', bounds.height);
settings.setSync('isMaximized', win.isMaximized());
settings.set('posX', bounds.x);
settings.set('posY', bounds.y);
settings.set('width', bounds.width);
settings.set('height', bounds.height);
settings.set('isMaximized', win.isMaximized());
})
.on('closed', () => {
tray = null;
Expand Down Expand Up @@ -104,11 +105,32 @@ const basecamp = {
return win;
},

bootstrap() {
if (settings.get('checkNewVersion')) {
this.checkNewVersion();
}
},

/**
* Checks for new versions.
*/
checkNewVersion(notifyLatest) {
versionChecker.check().then((check) => {
if (check.comparison === 1) {
notification(`New version available ${check.repoVersion}`);
} else if (notifyLatest === true) {
notification(check.comparison === 0
? `${check.appVersion} is the latest version`
: `Dev version ${check.appVersion} (latest is ${check.repoVersion})`);
}
});
},

/**
* Adds the app menu.
*/
addAppMenu() {
Menu.setApplicationMenu(menus.forApp(basecamp, settings, DEFAULTS));
Menu.setApplicationMenu(menus.forApp(this));
},

/**
Expand All @@ -129,7 +151,7 @@ const basecamp = {
* Adds the tray icon.
*/
addTrayIcon() {
tray = new Tray(this.getIcon('tray'));
tray = new Tray(icon('tray'));
tray.setToolTip(APP_NAME);
tray.setContextMenu(menus.forTray());
tray.on('click', () => {
Expand All @@ -141,6 +163,16 @@ const basecamp = {
});
},

/**
* Enables or disables menu auto hiding
*/
switchAutoHideMenu() {
const isAutoHide = !settings.get('autoHideMenu');
win.setAutoHideMenuBar(isAutoHide);
win.setMenuBarVisibility(!isAutoHide);
settings.set('autoHideMenu', isAutoHide);
},

/**
* Go to previous page on history.
*/
Expand Down Expand Up @@ -182,7 +214,7 @@ const basecamp = {
showAboutDialog() {
dialog.showMessageBox(win, {
type: 'info',
icon: this.getIcon('logo'),
icon: icon('logo'),
buttons: ['Ok'],
defaultId: 0,
title: 'About',
Expand All @@ -208,7 +240,7 @@ const basecamp = {
}
}

win.webContents.executeJavaScript('typeof BC === \'undefined\' ? 0 : BC.unreads.all', false, result => (result)).then((result) => {
win.webContents.executeJavaScript('typeof BC === \'undefined\' ? 0 : BC.unreads.all', false, (result) => (result)).then((result) => {
const unreads = result.length;

win.setTitle(unreads > 0 ? `${fixedTitle}${unreads}` : fixedTitle);
Expand All @@ -217,18 +249,11 @@ const basecamp = {

if (unreads > 0) {
if (!unreadsNotified) {
const notification = `
new Notification(
'${APP_NAME}',
{ body: 'You have ${unreads} unread notifications' }
);`;

win.webContents.executeJavaScript(notification);

notification(`You have ${unreads} unread notifications`);
unreadsNotified = true;
}

if (settings.getSync('showBadge', DEFAULTS.showBadge)) {
if (settings.get('showBadge')) {
this.setIcons(`-unreads-${(unreads > 10 ? '10p' : unreads)}`);
} else {
this.setIcons('-unreads');
Expand All @@ -243,20 +268,8 @@ const basecamp = {
* Sets the app & tray icons.
*/
setIcons(suffix) {
win.setIcon(this.getIcon(`icon${suffix ? '-unreads' : ''}`));
tray.setImage(this.getIcon(`tray${suffix || ''}`));
},

/**
* Gets the corresponding icon path.
*
* @param {string} icon
*
* @return {string}
*/
getIcon(icon) {
const iconScheme = settings.getSync('iconScheme') || DEFAULTS.iconScheme;
return `${ICONS_PATH}/${iconScheme}/${icon}.png`;
win.setIcon(icon(`icon${suffix ? '-unreads' : ''}`));
tray.setImage(icon(`tray${suffix || ''}`));
},

/**
Expand All @@ -277,7 +290,7 @@ const basecamp = {
* @param {string} color
*/
configureIconScheme(color) {
settings.setSync('iconScheme', color);
settings.set('iconScheme', color);
win.reload();
},

Expand All @@ -287,7 +300,7 @@ const basecamp = {
* @param {string} color
*/
configureShowBadge(config) {
settings.setSync('showBadge', config);
settings.set('showBadge', config);
win.reload();
},
};
Expand Down
9 changes: 9 additions & 0 deletions app/icon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { app } = require('electron');
const path = require('path');
const settings = require('./settings');

module.exports = (icon) => {
const iconsPath = path.join(app.getAppPath(), '..', 'assets', 'icons');
const iconScheme = settings.get('iconScheme');
return `${iconsPath}/${iconScheme}/${icon}.png`;
};
20 changes: 0 additions & 20 deletions app/integration.js

This file was deleted.

Loading

0 comments on commit 561ff90

Please sign in to comment.