Skip to content

Commit

Permalink
silent mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hitman249 committed Jun 16, 2021
1 parent 97e8f9b commit 17523b5
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 44 deletions.
50 changes: 50 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow, remote, protocol, ipcMain } = require('electron');

const process = require('process');
const path = require('path');
const fs = require('fs');
const fetch = require('node-fetch');
Expand All @@ -13,6 +14,51 @@ global.fs = fs;
global.formData = formData;
global.blob = blob;

global.getArguments = () => {
let args = JSON.parse(JSON.stringify(process.argv));
args.shift();

let params = {};
let field = null;

const append = (field, value) => {
if (undefined === params[field]) {
params[field] = value;
} else if (Array.isArray(params[field])) {
params[field].push(value);
} else {
params[field] = [ params[field], value ];
}
};

args.forEach(arg => {
if (arg.substring(0, 2) === '--') {
if (null === field) {
field = arg.substring(2);
} else {
append(field, '');
field = arg.substring(2);
}
} else {
if (null !== field) {
append(field, arg);
field = null;
}
}
});

if (null !== field) {
append(field, '');
field = null;
}

if (undefined !== params['game'] && !Array.isArray(params['game'])) {
params['game'] = [ params['game'] ];
}

return params;
};

app.allowRendererProcessReuse = true;
app.disableHardwareAcceleration();

Expand All @@ -21,8 +67,12 @@ function createWindow() {
callback({ path: decodeURIComponent(request.url).substring(8).split('?')[0] });
});

let args = global.getArguments();
let show = (undefined === args['autostart'] && undefined === args['hide']);

// Create the browser window.
const mainWindow = new BrowserWindow({
show,
icon: __dirname + '/build/icons/512.png',
minWidth: 800,
minHeight: 600,
Expand Down
45 changes: 2 additions & 43 deletions src/src/modules/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Utils from "./utils";

const child_process = require('child_process');
const { remote } = require('electron');
const getArguments = remote.getGlobal('getArguments');

export default class Command {

Expand Down Expand Up @@ -425,48 +426,6 @@ export default class Command {
* @return {{}}
*/
getArguments() {
let args = remote.process.argv;
args.shift();

let params = {};

let field = null;

const append = (field, value) => {
if (undefined === params[field]) {
params[field] = value;
} else if (Array.isArray(params[field])) {
params[field].push(value);
} else {
params[field] = [ params[field], value ];
}
};

args.forEach(arg => {
if (_.startsWith(arg, '--')) {
if (null === field) {
field = arg.substring(2);
} else {
append(field, '');
field = arg.substring(2);
}
} else {
if (null !== field) {
append(field, arg);
field = null;
}
}
});

if (null !== field) {
append(field, '');
field = null;
}

if (undefined !== params['game'] && !Array.isArray(params['game'])) {
params['game'] = [ params['game'] ];
}

return params;
return getArguments();
}
}
4 changes: 4 additions & 0 deletions src/src/modules/prefix.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,10 @@ export default class Prefix {
* @return {boolean}
*/
isSound() {
if (this.system.isSilent()) {
return false;
}

return Boolean(_.get(this.config, 'app.sound'));
}

Expand Down
8 changes: 8 additions & 0 deletions src/src/modules/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,4 +761,12 @@ export default class System {
window() {
return mainWindow;
}

/**
* @return {boolean}
*/
isSilent() {
let args = this.command.getArguments();
return (undefined !== args['autostart'] && undefined !== args['hide']);
}
}
2 changes: 1 addition & 1 deletion src/src/modules/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const fs = require('fs');

export default class Update {

version = '1.4.50';
version = '1.4.51';

/**
* @type {string}
Expand Down

0 comments on commit 17523b5

Please sign in to comment.