Skip to content

Commit

Permalink
Add settings options and overlay buttons (#10)
Browse files Browse the repository at this point in the history
* Add force refresh button, settings button on overlay, overlay sizes and setting for refresh interval
  • Loading branch information
theoarav authored Aug 21, 2020
1 parent 565a711 commit 18c9aba
Show file tree
Hide file tree
Showing 7 changed files with 737 additions and 851 deletions.
42 changes: 39 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
// Vendor
const {app, BrowserWindow} = require('electron');
const {app, BrowserWindow, ipcMain} = require('electron');
const settings = require('electron-settings');

// Constants
const DEVTOOL_OPTIONS = {mode: 'detach'};

const OVERLAY_SIZE = {
large: {
height: 70,
width: 460
},
medium: {
height: 60,
width: 400
},
small: {
height: 50,
width: 350
}
};

let overlayWindow;
let settingsWindow;
let debug = process.argv[2] === 'debug';
Expand All @@ -19,9 +34,15 @@ function createOverlayWindow() {
resizable: false,
webPreferences: {
nodeIntegration: true
}
},
};

if (settings.has('overlay.size')) {
const {height, width} = OVERLAY_SIZE[settings.get('overlay.size')];
windowOptions.height = height;
windowOptions.width = width;
}

if (settings.has('position')) {
windowOptions.x = settings.get('position.x');
windowOptions.y = settings.get('position.y');
Expand Down Expand Up @@ -60,7 +81,10 @@ function createSettingsWindow() {

settingsWindow.setMenu(null);

settingsWindow.on('closed', () => overlayWindow.send('forceChaosRecipeRefresh'));
settingsWindow.on('closed', () => {
overlayWindow.send('forceChaosRecipeRefresh')
settingsWindow = null;
});

if (debug) settingsWindow.webContents.openDevTools(DEVTOOL_OPTIONS);
}
Expand All @@ -71,3 +95,15 @@ app.on('ready', () => {
});

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

ipcMain.on('overlay-size-changed', () => {
const {height, width} = OVERLAY_SIZE[settings.get('overlay.size')];
overlayWindow.setBounds({width, height});
});

ipcMain.on('open-options', () => {
if (!settingsWindow) {
createSettingsWindow();
settingsWindow.show();
}
});
Loading

0 comments on commit 18c9aba

Please sign in to comment.