Skip to content

Commit

Permalink
v6.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sidneys committed Jan 30, 2018
1 parent 47584ed commit df508be
Show file tree
Hide file tree
Showing 10 changed files with 699 additions and 1,261 deletions.
18 changes: 18 additions & 0 deletions RELEASENOTES.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
{
"6.8.1": {
"🍾 features": [
"Adds `Indefinite Snooze` mode to pause all notifications – until disabled manually"
],
"💎 improvements": [
"Improves image quality of automated favicon downloads",
"Augmented heuristics for prioritization / selection of automated icon downloads"
],
"🚨 fixes": [
"Fixes skipped notifications due to upstream back-end migration (https://github.com/mat/besticon)"
],
"👷 internals": [
"Upgrades `electron` to `v1.7.11`",
"Upgrades `node_modules`",
"Upgrades `services`",
"Upgrades `lib`"
]
},
"6.7.7": {
"🍾 features": [
"Adds automatic favicon downloads for IFTTT notifications (https://ifttt.com/pushbullet)",
Expand Down
10 changes: 8 additions & 2 deletions app/scripts/main/components/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ const globals = require(path.join(appRootPath['path'], 'app', 'scripts', 'main',
* Configuration
*/
app.disableHardwareAcceleration();
app.setAppUserModelId(global.manifest.appId);
events.EventEmitter.defaultMaxListeners = Infinity;

// Hotfix for skipped notifications (Windows) (https://github.com/electron/electron/issues/11340)
if (platformTools.isWindows) {
app.setAppUserModelId(global.manifest.appId);
}

// Hotfix for invisible tray icon (Linux)
if (platformTools.isLinux) {
process.env.XDG_CURRENT_DESKTOP = 'Unity';
}
Expand Down Expand Up @@ -107,4 +113,4 @@ if (isSecondInstance) {
logger.warn('Multiple application instances detected', 'Shutting down secondary application instances');

process.exit(0);
}
}
2 changes: 1 addition & 1 deletion app/scripts/main/managers/configuration-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ let configurationItems = {
logger.debug(this.keypath, 'init');
},
get() {
logger.debug(this.keypath, 'get');
// logger.debug(this.keypath, 'get');

return electronSettings.get(this.keypath);
},
Expand Down
8 changes: 8 additions & 0 deletions app/scripts/main/menus/tray-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,14 @@ let createTrayMenuTemplate = () => {
click(menuItem) {
getSnoozerService().startSnooze(480, menuItem);
}
},
{
label: 'Indefinite snooze',
id: 'snooze-infinity',
type: 'checkbox',
click(menuItem) {
getSnoozerService().startSnooze(Infinity, menuItem);
}
}
]
},
Expand Down
9 changes: 7 additions & 2 deletions app/scripts/main/providers/notification-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @constant
*/
const electron = require('electron');
const { Notification } = electron;
const { nativeImage, Notification } = electron;

/**
* Modules
Expand Down Expand Up @@ -37,13 +37,18 @@ const defaultOptions = {
let create = (options) => {
logger.debug('create');

// Support Strings / Numbers
// Accept simple strings as payload
if (!_.isPlainObject(options)) {
options = {
title: options
};
}

// Convert icon string filepath to Electron nativeImage
if (options.icon && _.isString(options.icon)) {
options.icon = nativeImage.createFromPath(options.icon);
}

const notificationOptions = _.defaultsDeep(options, defaultOptions);

return new Notification(notificationOptions);
Expand Down
30 changes: 24 additions & 6 deletions app/scripts/main/services/snoozer-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ class SnoozerService {
ipcMain.emit('snooze', isSnoozing);
}

/**
* Snooze until indefinitely
*
* @private
*/
infinitySnooze() {
logger.debug('infinitySnooze');

this.snoozeUntil = Infinity;
this.onSnooze(true);

const notification = notificationProvider.create({ title: 'Snooze started', subtitle: `Snoozing indefinitely.` });
notification.show();
}

/**
* Schedule snooze
* @param {Number} duration - Snooze duration in minutes
Expand All @@ -63,6 +78,11 @@ class SnoozerService {
scheduleSnooze(duration, menuItem) {
logger.debug('scheduleSnooze');

if (duration === Infinity) {
this.infinitySnooze();
return;
}

let durationMs = Math.round(duration * (60 * 1000));
let durationHours = Math.round(duration / 60);

Expand Down Expand Up @@ -102,15 +122,13 @@ class SnoozerService {
startSnooze(duration, menuItem) {
logger.debug('startSnooze');

let snoozeMenuItemList = menuItem['menu'].items.filter((item) => item.id && item.id.startsWith('snooze') && item.id !== menuItem['id']);
let menuItemList = menuItem['menu'].items.filter((item) => item.id && item.id.startsWith('snooze') && item.id !== menuItem['id']);
let isEnabled = menuItem.checked;

// Reset related menu items
snoozeMenuItemList.forEach((item) => {
item.checked = false;
});
// Disable related menuItems
menuItemList.forEach(item => item.checked = false);

// Abort Snooze
// Exit from all Snooze
if (this.snoozeUntil !== 0) {
this.snoozeUntil = 0;

Expand Down
57 changes: 37 additions & 20 deletions app/scripts/renderer/pushbullet/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const logger = require('@sidneys/logger')({ write: true });
const moment = require('moment');
const opn = require('opn');
const semver = require('semver');
const shortid = require('shortid');

/**
* Modules
Expand All @@ -55,7 +56,7 @@ const platformTools = require('@sidneys/platform-tools');
* @default
*/
const appName = remote.getGlobal('manifest').name;
const appTemporaryDirectory = isDebug ? appRootPath : os.tmpdir();
const appTemporaryDirectory = (isDebug && process.defaultApp) ? appRootPath : os.tmpdir();


/** @namespace Audio */
Expand All @@ -72,6 +73,14 @@ const appTemporaryDirectory = isDebug ? appRootPath : os.tmpdir();
/** @namespace push.notifications */


/**
* Urls
* @constant
*/
const besticonUrl = 'besticon-demo.herokuapp.com';
const pushbulletUrl = 'www.pushbullet.com';
const youtubeUrl = 'img.youtube.com';

/**
* Notifications
* @constant
Expand Down Expand Up @@ -224,15 +233,15 @@ let generateImageUrl = (push) => {

for (let device of pb.api.devices.all) {
if (device['iden'] === deviceId) {
iconDevice = `http://www.pushbullet.com/img/deviceicons/${device.icon}.png`;
iconDevice = `http://${pushbulletUrl}/img/deviceicons/${device.icon}.png`;
}
}

/**
* SMS icon
*/
if (push['type'] === 'sms_changed') {
iconDevice = 'http://www.pushbullet.com/img/deviceicons/phone.png';
iconDevice = `http://${pushbulletUrl}/img/deviceicons/phone.png`;
}

/**
Expand All @@ -252,9 +261,9 @@ let generateImageUrl = (push) => {
if (push['type'] === 'link') {
// YouTube
if (getYouTubeID(push['url'])) {
iconWebsite = `http://img.youtube.com/vi/${getYouTubeID(push['url'])}/hqdefault.jpg`;
iconWebsite = `http://${youtubeUrl}/vi/${getYouTubeID(push['url'])}/hqdefault.jpg`;
} else {
iconWebsite = `http://icons.better-idea.org/icon?fallback_icon_color=4AB367&formats=ico,png&size=1..${faviconImageSize}..200&url=${push['url']}`;
iconWebsite = `https://${besticonUrl}/icon?fallback_icon_color=4AB367&formats=ico,png&size=1..${faviconImageSize}..200&url=${push['url']}`;
}
}

Expand Down Expand Up @@ -552,12 +561,20 @@ let convertPushToNotification = (push) => {
notificationOptions.body = void 0;
}

/**
* Disables icons on Electron pre-1.8.0 on Windows
* Reference: {@link https://github.com/electron/electron/issues/9935}
*/
if (platformTools.isWindows && semver.satisfies(process.versions.electron, '<1.8.0')) {
notificationOptions.icon = void 0;
}

/**
* Reply
*/
if (push.type === 'sms_changed') {
/**
* Disables notification actions on Electron pre-1.8.0 on macOS High Sierra
* Disables actions on Electron pre-1.8.0 on macOS High Sierra
* Reference: {@link https://github.com/electron/electron/pull/10709}
*/
if (platformTools.isMacOS && (Number(os.release().split('.')[0]) >= 17) && semver.satisfies(process.versions.electron, '<1.8.0')) { return; }
Expand All @@ -569,9 +586,9 @@ let convertPushToNotification = (push) => {
/**
* Fetch Favicon
*/
const imageUrl = push.icon || '';
const imageUrl = notificationOptions.icon || '';
const imageProtocol = url.parse(imageUrl).protocol;
const imageFilepath = path.join(appTemporaryDirectory, `${appName}.push.icon.png`);
const imageFilepathTemporary = path.join(appTemporaryDirectory, `${appName}.push.${shortid.generate()}.png`);

/**
* Image: None
Expand All @@ -581,7 +598,6 @@ let convertPushToNotification = (push) => {
playSound(retrievePushbulletSoundFile());
}

notificationOptions.icon = target;
showNotification(notificationOptions, push);

return;
Expand All @@ -591,14 +607,14 @@ let convertPushToNotification = (push) => {
* Image: From DataURI
*/
if (imageProtocol === 'data:') {
writeResizeImage(imageDataURI.decode(imageUrl).dataBuffer, imageFilepath, (error, target) => {
writeResizeImage(imageDataURI.decode(imageUrl).dataBuffer, imageFilepathTemporary, (error, imageFilepathConverted) => {
if (error) { return; }

if (retrievePushbulletSoundEnabled()) {
playSound(retrievePushbulletSoundFile());
}

notificationOptions.icon = target;
notificationOptions.icon = imageFilepathConverted;
showNotification(notificationOptions, push);
});

Expand All @@ -608,29 +624,29 @@ let convertPushToNotification = (push) => {
/**
* Image: From URI
*/
imageDownloader.image({ url: imageUrl, dest: imageFilepath })
.then(({ image }) => {
const imageBuffer = image;
imageDownloader.image({ url: imageUrl, dest: imageFilepathTemporary })
.then((result) => {
const imageFilepathDownloaded = result.filename;
const imageBuffer = result.image;
const imageType = fileType(imageBuffer);
const isIco = ICO.isICO(imageBuffer);
const isPng = imageType.mime === 'image/png';
const isJpeg = imageType.mime === 'image/jpg' || imageType.mime === 'image/jpeg';

logger.debug('convertPushToNotification', 'imageUrl', imageUrl);
logger.debug('convertPushToNotification', 'imageType', imageType);
logger.debug('convertPushToNotification', 'imageDownloader', 'imageUrl:', imageUrl, 'imageFilepathDownloaded:', imageFilepathDownloaded, 'imageType:', imageType);

/**
* .PNG
*/
if (isPng || isJpeg) {
writeResizeImage(imageBuffer, imageFilepath, (error, target) => {
writeResizeImage(imageBuffer, imageFilepathDownloaded, (error, imageFilepathConverted) => {
if (error) { return; }

if (retrievePushbulletSoundEnabled()) {
playSound(retrievePushbulletSoundFile());
}

notificationOptions.icon = target;
notificationOptions.icon = imageFilepathConverted;
showNotification(notificationOptions, push);
});

Expand All @@ -643,13 +659,14 @@ let convertPushToNotification = (push) => {
if (isIco) {
ICO.parse(imageBuffer, 'image/png').then(imageList => {
const imageMaximum = imageList[imageList.length - 1];
writeResizeImage(Buffer.from(imageMaximum.buffer), imageFilepath, (error, target) => {
writeResizeImage(Buffer.from(imageMaximum.buffer), imageFilepathDownloaded, (error, imageFilepathConverted) => {
if (error) { return; }

if (retrievePushbulletSoundEnabled()) {
playSound(retrievePushbulletSoundFile());
}
notificationOptions.icon = target;

notificationOptions.icon = imageFilepathConverted;
showNotification(notificationOptions, push);
});
});
Expand Down
Loading

0 comments on commit df508be

Please sign in to comment.