Skip to content

Commit

Permalink
Add Log and Fix icon path
Browse files Browse the repository at this point in the history
  • Loading branch information
KlutzyBubbles committed Feb 5, 2022
1 parent 483b91c commit 7739607
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 17 deletions.
3 changes: 2 additions & 1 deletion forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ const package = require('./package.json');

module.exports = {
packagerConfig: {
asar: true,
asar: false,
executableName: 'controlpad',
appCopyright: `Copyright (C) ${new Date().getFullYear()} KlutzyBubbles`,
extraResource: path.resolve(rootDir, 'assets', 'icon.ico'),
},
makers: [
{
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"@mui/material": "^5.3.1",
"@mui/styles": "^5.3.0",
"@nut-tree/nut-js": "^2.0.1",
"electron-log": "^4.4.5",
"electron-squirrel-startup": "^1.0.0",
"electron-store": "^8.0.1",
"fast-deep-equal": "^3.1.3",
Expand Down
52 changes: 37 additions & 15 deletions src/main/App.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,44 @@
import { app, BrowserWindow } from 'electron';
import { createAppWindow } from './AppWindow';
// import log from 'electron-log';

if (require('electron-squirrel-startup')) {
app.quit();
}

app.on('ready', () => {
createAppWindow();
});

app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createAppWindow();
var handleStartupEvent = () => {
if (process.platform !== 'win32') {
return false;
}
});

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
var squirrelCommand = process.argv[1];
switch (squirrelCommand) {
case '--squirrel-install':
case '--squirrel-updated':
setTimeout(app.quit, 2000);
return true;
case '--squirrel-uninstall':
setTimeout(app.quit, 2000);
return true;
case '--squirrel-obsolete':
setTimeout(app.quit, 2000);
return true;
}
});
};

if (!handleStartupEvent()) {
app.on('ready', () => {
createAppWindow();
});

app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createAppWindow();
}
});

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
}


3 changes: 2 additions & 1 deletion src/main/AppWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import path from 'path';
import { registerTitlebarIpc } from '@main/ipc/TitlebarIPC';
import registerConfigIPC from './ipc/ConfigIPC';
import registerKeyboardIPC from './ipc/KeyboardIPC';
// import log from 'electron-log';

declare const APP_WINDOW_WEBPACK_ENTRY: string;
declare const APP_WINDOW_PRELOAD_WEBPACK_ENTRY: string;

const iconPath = path.resolve('assets/icon.ico');
const iconPath = app.isPackaged ? path.resolve('./resources/icon.ico') : path.resolve('./assets/icon.ico');
let appWindow: BrowserWindow;
let appTray: Tray;

Expand Down
1 change: 1 addition & 0 deletions src/renderer/Preload.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import '@src/window/WindowPreload';
import './preload/config/ConfigPreload';
import './preload/keyboard/KeyboardPreload';
import './preload/log/LogPreload';

console.log('[CP] : Preload execution started');
1 change: 1 addition & 0 deletions src/renderer/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Launchpad from '@common/Launchpad';
import Chip from '@mui/material/Chip';
import Paper from '@mui/material/Paper';
import { hasKeyCombo } from '@common/Utils';
// import logContext from '@preload/log/LogContextApi';

export interface SelectedButton {
section: Section;
Expand Down
7 changes: 7 additions & 0 deletions src/renderer/preload/log/ElectronLog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import log from 'electron-log';

const electronLog = {
log: log.functions,
}

export default electronLog;
12 changes: 12 additions & 0 deletions src/renderer/preload/log/LogContextApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import electronLog from './ElectronLog';
import log from 'electron-log';

type AddedProps = {
electron_log: typeof electronLog;
}

type CombinedWindow = typeof window & AddedProps;

const context: typeof log.functions = (window as CombinedWindow).electron_log.log;

export default context;
6 changes: 6 additions & 0 deletions src/renderer/preload/log/LogPreload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { contextBridge } from 'electron';
import log from 'electron-log';

contextBridge.exposeInMainWorld('electron_log', {
log: log.functions,
});

0 comments on commit 7739607

Please sign in to comment.