Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Add settings option
Browse files Browse the repository at this point in the history
  • Loading branch information
igor725 committed Jun 3, 2024
1 parent 7005dee commit f6c5094
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
22 changes: 20 additions & 2 deletions libs/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const STATES = [
];

module.exports.DRPC = class DRPC {
#enabled = false;
#status = {
state: ' ',
details: STATES[0],
Expand All @@ -19,14 +20,16 @@ module.exports.DRPC = class DRPC {
instance: false
};

constructor() {
constructor(enabled = false) {
this.#status.startTimestamp = Date.now();
this.#enabled = enabled;

rpcClient.on('ready', () => {
this.renderStatus();

setInterval(() => {
this.renderStatus();
if (this.#enabled)
this.renderStatus();
}, 15e3);
});

Expand All @@ -42,4 +45,19 @@ module.exports.DRPC = class DRPC {
};

renderStatus = async () => rpcClient.setActivity(this.#status);

set state(b) {
if (b === false) {
this.#enabled = false;
rpcClient.clearActivity();
return;
}

this.#enabled = true;
this.renderStatus();
}

get state() {
return this.#enabled;
}
};
1 change: 1 addition & 0 deletions libs/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports.Config = class Config {
update_channel: 'release',
update_freq: 'weekly',
inpadcolor: '#3B3E95',
discord_rpc: true,
first_launch: true,
dblcl_run: false,
dblcl_ask: true,
Expand Down
7 changes: 5 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ let gameproc = undefined;
let updateWorker = undefined;
let compatWorker = undefined;
let binname = 'psoff.exe';

const discordRPC = new DRPC();
let discordRPC;

const converter = new Convert({
newline: true
Expand Down Expand Up @@ -384,6 +383,7 @@ const commandHandler = (channel, cmd, info) => {
const main = (userdir = __dirname) => {
fs.mkdirSync(userdir, { recursive: true });
config = new Config(userdir);
discordRPC = new DRPC(config.getValue('discord_rpc'));

const emupath = config.getValue('emu_path');

Expand Down Expand Up @@ -664,6 +664,9 @@ const main = (userdir = __dirname) => {

config.addCallback('launcher', (key, value) => {
switch (key) {
case 'discord_rpc':
discordRPC.state = value;
return;
case 'scan_dirs':
gdirchanged = true;
return;
Expand Down
1 change: 1 addition & 0 deletions webroot/langs/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
}
},
"doubleclick": "Doubleclick will run the game",
"drpc": "Enable Discord Rich Presence",
"gsd": {
"label": "Game scan directories:",
"buttons": {
Expand Down
1 change: 1 addition & 0 deletions webroot/langs/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
}
},
"doubleclick": "Двойное нажатие запускает игру",
"drpc": "Включить Discord Rich Presence",
"gsd": {
"label": "Папки с играми:",
"buttons": {
Expand Down
4 changes: 4 additions & 0 deletions webroot/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<label for="dblcl" eo-translator="settings.launcher.doubleclick"></label>
<input type="checkbox" data-cfgfacility="launcher" data-cfgkey="dblcl_run" />
</div>
<div class="row">
<label for="drpc" eo-translator="settings.launcher.drpc"></label>
<input id="drpc" data-cfgfacility="launcher" data-cfgkey="discord_rpc" type="checkbox" />
</div>
<label for="gsd" eo-translator="settings.launcher.gsd.label"></label>
<div class="row">
<select id="gsd" size="4"></select>
Expand Down

0 comments on commit f6c5094

Please sign in to comment.