Skip to content

Commit

Permalink
Merge branch 'master' into 'release'
Browse files Browse the repository at this point in the history
Version 0.4.0

See merge request kirbo/slothy!4
  • Loading branch information
Kirbo committed Apr 23, 2019
2 parents 19a87fd + 73ae696 commit 1da6ebd
Show file tree
Hide file tree
Showing 12 changed files with 265 additions and 91 deletions.
2 changes: 0 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ cache:
.release-common: &release-common
<<: *general
stage: release
environment:
name: ${CI_COMMIT_REF_NAME}
cache:
policy: pull
paths:
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Crash reporter.

## [0.4.0] - 2019-04-23
### Added
- New option: `Check updates at launch`.
- New option: `Launch application minimised`.
- New option: `Minimise application on quit`.
- More logging for debugging.

### Changed
- Default value for `Update Slack workspaces` set from 5 to 15 minutes.

## [0.3.8] - 2019-04-23
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
react: nodemon -w config-overrides.js --exec yarn react-dev
electron: nodemon -w public/electron.js -w public/utils.js -w public/config.js --exec yarn electron-dev
electron: nodemon -w public/electron.js -w public/lib --exec yarn electron-dev
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.3.8",
"version": "0.4.0",
"name": "slothy",
"description": "Changes your Slack status based on the SSID you're currently connected to.",
"productName": "Slothy",
Expand All @@ -11,7 +11,8 @@
"Pages": "https://kirbo.gitlab.io/slothy/",
"Slack": "https://join.slack.com/t/slothy-app/shared_invite/enQtNjE1NTcxMzY1MTU4LTcyMzhhZmMwNzdlMjkwZTQ4NzNkYjc3NWI0NWY5YWVjNDg3NTg5MTlhNGQ2ZGQ4NDZjMGMxM2YxNGQxOTBhOTc",
"ClientId": "613360590693.615573455494",
"Protocol": "slothy"
"Protocol": "slothy",
"CrashReportUrl": ""
},
"author": "Kirbo (https://gitlab.com/kirbo)",
"private": true,
Expand Down
125 changes: 75 additions & 50 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ const {
getAppConfigurations,
setAppConfigurations,
updateStatuses,
} = require('./utils.js');
// crashReporter,
} = require('./lib/helpers');

// crashReporter();

const protocol = packageJson.product.Protocol;

Expand All @@ -46,7 +49,7 @@ const cached = {
slackInstances: null,
};

const setAutoUpdates = async () => {
const setAutoUpdater = async () => {
config = await getAppConfigurations();

Object.keys(config.updates).forEach(key => {
Expand All @@ -57,8 +60,6 @@ const setAutoUpdates = async () => {
autoUpdater.logger.transports.file.level = 'info';
}

setAutoUpdates();

const hideDock = () => {
if (app.dock) {
app.dock.hide();
Expand Down Expand Up @@ -296,38 +297,6 @@ const createWindow = async () => {
});
Menu.setApplicationMenu(Menu.buildFromTemplate(MENU_TEMPLATE));

if (!tray) {
tray = new Tray(nativeImage.createFromPath(iconPath));

const contextMenu = Menu.buildFromTemplate([
{
label: `Open ${packageJson.productName}`, click: () => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
mainWindow.show();
mainWindow.focus();
showDock();
} else {
createWindow();
}
}
},
{
label: 'Quit', click: () => {
quit = true;
app.quit();
}
},
]);
tray.setToolTip(packageJson.productName);
tray.setContextMenu(contextMenu);
tray.on('click', () => {
mainWindow.isVisible() ? mainWindow.hide() : mainWindow.show();
});
}

mainWindow
.once('ready-to-show', () => {
mainWindow.show();
Expand Down Expand Up @@ -358,7 +327,7 @@ const createWindow = async () => {
mainWindow.hide();
})
.on('close', event => {
if (!quit) {
if (config.app.closeToTray && !quit) {
event.preventDefault();
}
if (mainWindow) {
Expand All @@ -378,7 +347,39 @@ const createWindow = async () => {
});
}

const createTray = async () => {
if (!tray) {
tray = new Tray(nativeImage.createFromPath(iconPath));

const contextMenu = Menu.buildFromTemplate([
{
label: `Open ${packageJson.productName}`, click: () => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
mainWindow.show();
mainWindow.focus();
showDock();
} else {
createWindow();
}
}
},
{
label: 'Quit', click: () => {
quit = true;
app.quit();
}
},
]);
tray.setToolTip(packageJson.productName);
tray.setContextMenu(contextMenu);
tray.on('click', () => {
mainWindow.isVisible() ? mainWindow.hide() : mainWindow.show();
});
}
}

if (!app.requestSingleInstanceLock()) {
app.quit();
Expand Down Expand Up @@ -409,9 +410,17 @@ app
mainWindow.focus();
}
})
.on('ready', () => {
createWindow();
showDock();
.on('ready', async () => {
createTray();
config = await getAppConfigurations();
setAutoUpdater();

if (!config.app.launchMinimised) {
createWindow();
} else {
hideDock();
}

electron.powerMonitor
.on('suspend', () => computerRunning = false)
.on('resume', () => computerRunning = true);
Expand All @@ -424,7 +433,7 @@ app
hideDock();
})
.on('will-quit', event => {
if (!quit) {
if (config.app.closeToTray && !quit) {
event.preventDefault();

if (mainWindow) {
Expand All @@ -443,11 +452,14 @@ app

ipc
.on('initialize', async () => {
ifCachedSend('appConfigurations', getAppConfigurations);
const appConfigurations = await getAppConfigurations();
ifCachedSend('appConfigurations', () => appConfigurations);
ifCachedSend('configurations', getConfigurations);
ifCachedSend('connections', getConnections);
ifCachedSend('slackInstances', getSlackInstances);
autoUpdater.checkForUpdates();
if (appConfigurations.updates.checkUpdatesOnLaunch) {
autoUpdater.checkForUpdates();
}
})
.on('getConnections', async (event, data) => sendIfMainWindow('connections', getConnections))
.on('removeSlackInstance', async (event, data) => sendIfMainWindow('slackInstances', removeSlackInstance, data))
Expand All @@ -466,13 +478,13 @@ ipc
await setStatus(data);
sendIfMainWindow('slackInstances', getSlackInstances);
})
.on('saveAppConfigurationsTimers', async (event, data) => {
const appConfigurations = await setAppConfigurations(data);
await startTimers(false);
await sendIfMainWindow('appConfigurations', () => appConfigurations);
})
.on('saveAppConfigurationsUpdates', async (event, data) => {
const appConfigurations = await setAppConfigurations(data);
.on('saveAppConfigurations', async (event, data) => {
const appConfigurations = await setAppConfigurations(data.appConfigurations);
if (data.property === 'timers') {
await startTimers(false);
}
config = appConfigurations;
setAutoUpdater();
await sendIfMainWindow('appConfigurations', () => appConfigurations);
})
.on('checkUpdates', () => autoUpdater.checkForUpdates())
Expand Down Expand Up @@ -562,3 +574,16 @@ autoUpdater
onConfirm: 'installUpdate',
}));
});

process
.on('unhandledRejection', (reason, p) => {
log.error('Unhandled Rejection at:', p, 'reason:', reason);
})
.on('uncaughtException', error => {
log.error('uncaughtException', error);
})
.on('warning', (warning) => {
log.warn(warning.name);
log.warn(warning.message);
log.warn(warning.stack);
});
12 changes: 9 additions & 3 deletions public/config.js → public/lib/config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
module.exports = {
// Timers are in seconds
timers: {
slackInstances: 300,
connections: 60,
updateStatus: 300,
connections: 60,
slackInstances: 900,
},
updates: {
autoDownload: false,
autoInstallOnAppQuit: true,
allowPrerelease: false,
allowDowngrade: false,
fullChangelog: false,
}

checkUpdatesOnLaunch: true,
},
app: {
closeToTray: true,
launchMinimised: false,
},
};
44 changes: 26 additions & 18 deletions public/utils.js → public/lib/helpers.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
const electron = require('electron');
const storage = require('electron-json-storage');
const slack = require('slack');
const wifi = require('node-wifi');
const url = require('url');
const request = require('request');
const log = require('electron-log');

const packageJson = require('../package.json');
const packageJson = require('../../package.json');
const appConfigs = require('./config');

const {
mergeDeep,
recursiveObject,
} = require('./utils');

const protocol = packageJson.product.Protocol;

wifi.init({
Expand Down Expand Up @@ -478,10 +484,10 @@ const getAppConfigurations = async () => (
reject(error);
}

resolve({
...appConfigs,
...data,
});
const merged = mergeDeep(appConfigs, data);
const mergedStripped = recursiveObject(appConfigs, merged);

resolve(mergedStripped);
});
})
)
Expand All @@ -494,28 +500,28 @@ const setAppConfigurations = async appConfigurations => (
reject(error);
}

const recursiveObject = (config, newConfig) => (
Object.keys(config).reduce((newConfigObject, key) => {
if (typeof config[key] === 'object') {
newConfigObject[key] = recursiveObject(config[key], newConfig[key]);
return newConfigObject;
}
newConfigObject[key] = newConfig[key];
return newConfigObject;
}, {})
);

storage.set('appConfigs', recursiveObject(appConfigs, appConfigurations), async (error, data) => {
const merged = recursiveObject(appConfigs, appConfigurations);
storage.set('appConfigs', merged, async (error, data) => {
if (error) {
log.error('setAppConfigurations.appConfigs', error);
reject(error);
}
resolve(appConfigurations);
resolve(merged);
});
});
})
)


const crashReporter = async () => {
electron.crashReporter.start({
companyName: packageJson.author,
productName: packageJson.productName,
submitURL: packageJson.product.CrashReportUrl,
uploadToServer: true,
})
}

module.exports = {
getSlackInstances,
updateSlackInstance,
Expand All @@ -541,4 +547,6 @@ module.exports = {
getAppConfigurations,
setAppConfigurations,
updateStatuses,

crashReporter,
};
Loading

0 comments on commit 1da6ebd

Please sign in to comment.