summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSin <[email protected]>2020-06-22 17:08:12 -0700
committerFuwn <[email protected]>2020-06-22 17:08:12 -0700
commit012a831e6db48a8dbf8f6bbd4f6b971266b1371b (patch)
treebee40e5abf870d94d4efb84a2aeb017647d2b0ca
parentwoah :star: (diff)
parentadd discord rich presence :star2: (diff)
downloadmonkey-type-desktop-012a831e6db48a8dbf8f6bbd4f6b971266b1371b.tar.xz
monkey-type-desktop-012a831e6db48a8dbf8f6bbd4f6b971266b1371b.zip
Merge pull request #1 from 8cy/test
add discord rich presence :star2:
-rw-r--r--README.MD5
-rw-r--r--config.js18
-rw-r--r--index.js67
-rw-r--r--test/config.js36
4 files changed, 114 insertions, 12 deletions
diff --git a/README.MD b/README.MD
index 839678d..27722dc 100644
--- a/README.MD
+++ b/README.MD
@@ -5,6 +5,11 @@ Basically title.
- [Original Monkey Type open source repository](https://github.com/Miodec/monkey-type)
- [Monkey Type Website](https://monkey-type.com/)
+## Discord Rich Presence
+The full config.js example for the Discord RPC is available in the `test/` folder. Additionally, more information can be found here; https://github.com/8cy/pydii#config-explained.
+
+You can set your own rich presence values with that information.
+
## Development Usage
1. Clone or download repository.
2. `$ yarn` or `$ npm i` to install dependencies.
diff --git a/config.js b/config.js
index 4d0f3f3..bc8359f 100644
--- a/config.js
+++ b/config.js
@@ -4,6 +4,22 @@ const Store = require('electron-store');
module.exports = new Store({
defaults: {
debugEnable: false,
- menuEnable: true
+ menuEnable: true,
+ configCookieOverwrite: "",
+ discordRPC: {
+ clientId: "722389325483999243",
+ RPC: {
+ details: "Typing on Monkey Type",
+ state: "Desktop Application Beta",
+ smallImageText: "",
+ smallImageKey: "",
+ largeImageText: "Monkey Type",
+ largeImageKey: "icon",
+ refreshTime: 15,
+ }
+ },
+ dontTouch: {
+ updateCounter: 0
+ }
}
});
diff --git a/index.js b/index.js
index 19a6b58..d2de876 100644
--- a/index.js
+++ b/index.js
@@ -1,8 +1,10 @@
+/* jshint esversion: 9 */
+
'use strict';
const path = require('path');
const { app, BrowserWindow, Menu, session } = require('electron');
-/// const {autoUpdater} = require('electron-updater');
-const {is} = require('electron-util');
+const { autoUpdater } = require('electron-updater');
+const { is } = require('electron-util');
const unhandled = require('electron-unhandled');
const debug = require('electron-debug');
const contextMenu = require('electron-context-menu');
@@ -11,6 +13,9 @@ const config = require('./config');
const menuEnable = config.get('menuEnable');
const menu = require('./menu');
+const DiscordRPC = require('discord-rpc');
+const { start } = require('repl');
+
unhandled();
contextMenu();
@@ -22,14 +27,14 @@ app.setAppUserModelId('com.sin.monkey-type-desktop');
// Uncomment this before publishing your first version.
// It's commented out as it throws an error if there are no published versions.
-// if (!is.development) {
-// const FOUR_HOURS = 1000 * 60 * 60 * 4;
-// setInterval(() => {
-// autoUpdater.checkForUpdates();
-// }, FOUR_HOURS);
-//
-// autoUpdater.checkForUpdates();
-// }
+if (!is.development) {
+ const FOUR_HOURS = 1000 * 60 * 60 * 4;
+ setInterval(() => {
+ autoUpdater.checkForUpdates();
+ }, FOUR_HOURS);
+
+ autoUpdater.checkForUpdates();
+}
// Prevent window from being garbage collected
let mainWindow;
@@ -85,10 +90,50 @@ app.on('activate', async () => {
}
});
+const clientId = config.get('discordRPC').clientId;
+const rpc = new DiscordRPC.Client({ transport: 'ipc' });
+const startTimestamp = new Date();
+
+async function setActivity() {
+ if (!rpc || !mainWindow) {
+ return;
+ }
+
+ // You can add your own presence application or presence data in the config.
+ // If you wanted to, you could try to get data from monkey type time left value and set this as the endTimestamp value.
+ rpc.setActivity({
+ details: config.get('discordRPC').RPC.details,
+ state: config.get('discordRPC').RPC.state,
+ largeImageKey: config.get('discordRPC').RPC.largeImageKey,
+ largeImageText: config.get('discordRPC').RPC.largeImageText,
+ //smallImageKey: config.get('discordRPC').RPC.smallImageKey,
+ //smallImageText: config.get('discordRPC').RPC.smallImageText,
+ startTimestamp: startTimestamp
+ });
+}
+
+rpc.on('ready', () => {
+ setActivity();
+ console.log('initial set');
+
+ setInterval(() => {
+ setActivity();
+ console.log('refresh set');
+ }, 15e3);
+});
+
+rpc.login({ clientId }).catch(console.error);
+
(async () => {
await app.whenReady();
menuEnable ? Menu.setApplicationMenu(menu) : Menu.setApplicationMenu(null);
mainWindow = await createMainWindow();
+
+ //session.defaultSession.cookies.get({}).then(cookies => console.log(cookies));
- session.defaultSession.cookies.get({}).then(cookies => console.log(cookies));
+ // A more complete and custom config system will be implemented but at the moment you can just transfer your config cookie.
+ if (config.get('configCookieOverwrite').length > 50) {
+ let configCookie = { name: 'config', value: config.get('configCookieOverwrite') };
+ session.defaultSession.cookies.set(configCookie).then(() => {}, (error) => console.error(error));
+ }
})();
diff --git a/test/config.js b/test/config.js
new file mode 100644
index 0000000..6f3081c
--- /dev/null
+++ b/test/config.js
@@ -0,0 +1,36 @@
+'use strict';
+const Store = require('electron-store');
+
+// You can set these values pretty easily in the index.js, you just need to add the corresponding data types to the setActivity function.
+// You can also find a complete list of all of the types and what they do here; https://github.com/8cy/pydii/blob/master/README.MD#config-explained
+
+module.exports = new Store({
+ defaults: {
+ debugEnable: false,
+ menuEnable: true,
+ discordRPC: {
+ clientId: "722389325483999243",
+ timeEnable: true,
+ RPC: {
+ details: "Typing on Monkey Type",
+ state: "Desktop Application Beta",
+ startTimestamp: 0,
+ endTimestamp: 0,
+ smallImageText: "",
+ smallImageKey: "",
+ largeImageText: "Monkey Type",
+ largeImageKey: "icon",
+ refreshTime: 15,
+ instance: true,
+ match: "",
+ party: "",
+ partyMax: "",
+ join: "",
+ spectate: ""
+ }
+ },
+ dontTouch: {
+ updateCounter: 0
+ }
+ }
+});