Skip to content

Commit

Permalink
Fixed issue causing imported config to not reset HID or shortcuts.
Browse files Browse the repository at this point in the history
  • Loading branch information
aredden committed Jan 8, 2021
1 parent fdcddc7 commit a12000b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
14 changes: 10 additions & 4 deletions electron/src/IPCEvents/ConfigLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import is_dev from 'electron-is-dev';
import getLogger from '../Logger';
import path from 'path';
import { app } from 'electron';
import { browserWindow, getConfig, setG14Config } from '../electron';
import {
browserWindow,
getConfig,
setG14Config,
setupElectronReload,
} from '../electron';

dotenv.config();

Expand Down Expand Up @@ -79,7 +84,7 @@ export const writeConfig = async (config: G14Config) => {
};

export const buildConfigLoaderListeners = (ipc: IpcMain) => {
ipc.handle('loadConfig', async (event, args) => {
ipc.handle('loadConfig', async (_event, _args) => {
let config = await loadConfig().catch((err) => {
LOGGER.info(`Error loading config:\n${err}`);
});
Expand All @@ -91,7 +96,7 @@ export const buildConfigLoaderListeners = (ipc: IpcMain) => {
return false;
}
});
ipc.handle('saveConfig', async (event, config: G14Config) => {
ipc.handle('saveConfig', async (_event, config: G14Config) => {
LOGGER.info('Attempting to save config.');
setG14Config(config);
let result = writeConfig(config);
Expand All @@ -114,7 +119,7 @@ export const buildConfigLoaderListeners = (ipc: IpcMain) => {
if (val.canceled) {
return;
}
if (val.filePaths) {
if (val.filePaths && val.filePaths.length > 0) {
let path2file = val.filePaths[0];
fs.readFile(path2file, 'utf-8', (err, datas) => {
if (err) {
Expand All @@ -124,6 +129,7 @@ export const buildConfigLoaderListeners = (ipc: IpcMain) => {
writeConfig(JSON.parse(datas) as G14Config).then((ok) => {
if (ok) {
browserWindow.reload();
setupElectronReload(JSON.parse(datas) as G14Config);
} else {
LOGGER.info('Issue writing new configuration file.');
}
Expand Down
28 changes: 28 additions & 0 deletions electron/src/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,34 @@ export async function createWindow(
return { tray, browserWindow, g14Config, trayContext };
}

export const setupElectronReload = (config: G14Config) => {
let { shortcuts, rogKey } = config.current;

// Register global shortcut (example: ctrl + space)
if (shortcuts.minmax.enabled) {
globalShortcut.unregisterAll();
let registered = globalShortcut.register(
shortcuts.minmax.accelerator,
minMaxFunc
);
if (registered) {
LOGGER.info('Show app shortcut registered.');
} else {
LOGGER.info('Error registering shortcut.');
}
}

if (rogKey.enabled && !hid) {
let hdd = setUpNewG14ControlKey(mapperBuilder);
if (hdd) {
setHidMain(hdd);
LOGGER.info('ROG key HID built and listening.');
} else {
LOGGER.info('There was an issue setting up ROG HID');
}
}
};

powerMonitor.on('shutdown', () => {
LOGGER.info('Windows is shutting down (sent from powermonitor)');
globalShortcut.unregisterAll();
Expand Down

0 comments on commit a12000b

Please sign in to comment.