Skip to content

Commit

Permalink
chore: clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
Aetherinox committed Jul 19, 2024
1 parent dfe4457 commit 205f5a2
Showing 1 changed file with 52 additions and 66 deletions.
118 changes: 52 additions & 66 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,6 @@ const prompt = require('custom-electron-prompt');

console.log(process.argv);

/*
App > Top Menu
*/

function menu_AddDev(menu) {
let menu_devTools = new MenuItem(
{
label: 'Toggle Dev Tools',
accelerator: process.platform === 'darwin' ? 'ALT+CMD+I' : 'CTRL+SHIFT+I',
click: () => {
winMain.webContents.toggleDevTools();
}
},
{
type: 'separator'
})
menu.insert(2, menu_devTools)
}

/*
Menu > Main
Expand Down Expand Up @@ -296,6 +277,7 @@ Menu.setApplicationMenu(header_menu);
*/

function ready() {

/*
New Window
*/
Expand All @@ -308,12 +290,55 @@ function ready() {
backgroundColor: '#212121'
});

/*
Load default url to main window
*/

winMain.loadURL(store.get('instanceURL'));

/*
Event > Page Title Update
*/

winMain.on('page-title-updated', (e) => {
e.preventDefault();
});

/*
Event > Close
if --quit cli argument specified, app will completely quit when close pressed.
otherwise; app will hide
*/

winMain.on('close', function (e) {
if (!app.isQuiting) {
e.preventDefault();
if (bQuitOnClose == 1) {
app.isQuiting = true;
app.quit();
} else {
winMain.hide();
}
}

return false;
});

/*
Event > Closed
*/

winMain.on('closed', () => {
winMain = null;
});

/*
Event > New Window
buttons leading to external websites should open in user browser
*/

winMain.webContents.on('new-window', (e, url) => {
e.preventDefault();
require('electron').shell.openExternal(url);
Expand All @@ -324,50 +349,41 @@ function ready() {
*/

winMain.webContents.on('before-input-event', (e, input) => {
/*
Input > Refresh Page

Binds : CTRL + r
/*
Input > Refresh Page (CTRL + r)
*/

if (input.type === 'keyDown' && input.control && input.key === 'r') {
winMain.webContents.reload();
}

/*
Input > Zoom In
Binds : CTRL + =
Input > Zoom In (CTRL + =)
*/

if (input.type === 'keyDown' && input.control && input.key === '=') {
winMain.webContents.zoomFactor += 0.1;
}

/*
Input > Zoom Out
Binds : CTRL + -
Input > Zoom Out (CTRL + -)
*/

if (input.type === 'keyDown' && input.control && input.key === '-') {
winMain.webContents.zoomFactor -= 0.1;
}

/*
Input > Zoom Reset
Binds : CTRL + 0
Input > Zoom Reset (CTRL + 0)
*/

if (input.type === 'keyDown' && input.control && input.key === '0') {
winMain.webContents.zoomFactor = 1;
}

/*
Input > Quit
Binds : CTRL + q
Input > Quit (CTRL + q)
*/

if (input.type === 'keyDown' && input.control && input.key === 'q') {
Expand All @@ -376,9 +392,7 @@ function ready() {
}

/*
Input > Minimize to tray
Binds : CTRL + m
Input > Minimize to tray (CTRL + m)
*/

if (input.type === 'keyDown' && input.control && input.key === 'm') {
Expand All @@ -387,10 +401,7 @@ function ready() {
}

/*
Input > Dev Tools
Binds : CTRL + SHIFT + I
F12
Input > Dev Tools (CTRL + SHIFT + I || F12)
*/

if ((input.control && input.shift) || input.key === 'F12') {
Expand Down Expand Up @@ -554,31 +565,6 @@ function ready() {
return json;
}

winMain.on('page-title-updated', (e) => {
e.preventDefault();
});

/*
Close Button
if --quit cli argument specified, app will completely quit when close pressed.
otherwise; app will hide
*/

winMain.on('close', function (e) {
if (!app.isQuiting) {
e.preventDefault();
if (bQuitOnClose == 1) {
app.isQuiting = true;
app.quit();
} else {
winMain.hide();
}
}

return false;
});

/*
Loop args
Expand Down

0 comments on commit 205f5a2

Please sign in to comment.