Skip to content

Commit

Permalink
better rpc to use real discord app with real assets
Browse files Browse the repository at this point in the history
  • Loading branch information
borisnezlobin committed Jan 11, 2024
1 parent f4ff0c7 commit dc652f7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
38 changes: 22 additions & 16 deletions electron/ipc-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import { ipcMain } from "electron";
import { Notification } from "electron/main";
import DiscordRPC from "discord-rpc";

const clientId = '1015856802748969061';
const clientId = "1194793667337142334"; // this fallback is for an app called "META Now(tm)"... idk
const RPC = new DiscordRPC.Client({ transport: 'ipc' });


var endTime = Date.now() + 3600000;
DiscordRPC.register(clientId);

var currentActivity: DiscordRPC.Presence | null = null;

async function setRPCActivity() {
console.log("starting rpc");
if (!RPC || !currentActivity) return;
console.log(`polling rpc`);
RPC.setActivity(currentActivity);
}

Expand Down Expand Up @@ -58,20 +57,27 @@ function setupIpcController() {
clearRPC();
return;
}
if (args.session.type === "focus") {
currentActivity = {
details: "In a focus session!",
startTimestamp: Date.now(),
endTimestamp: Date.now() + args.session.length,
largeImageKey: 'bell_slash',
largeImageText: "I\'m not available right now, check back later.",
instance: false,
};
} else {
currentActivity = {
details: "On a break!",
startTimestamp: Date.now(),
endTimestamp: Date.now() + args.session.length,
largeImageKey: 'hourglass',
largeImageText: "I'm on a break!",
instance: false,
};
}

let detailsText = "In a focus session!";
if (args.session.type == "break") detailsText = "On a break!";

currentActivity = {
details: detailsText,
startTimestamp: Date.now(),
endTimestamp: Date.now() + args.session.length,
largeImageKey: 'session_img',
largeImageText: args.session.type == "focus" ? 'I\'m not available right now, check back later.' : 'I\'m on a break!',
smallImageKey: 'download-2',
smallImageText: 'I will be back!',
instance: false,
};
console.log("setting rpc for \'" + args.session.type + "\' session");

setRPCActivity();
});
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"@testing-library/user-event": "^13.5.0",
"@types/dompurify": "^3.0.5",
"@types/jest": "^29.5.8",
"@types/node": "^20.9.2",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"discord-rpc": "^4.0.1",
Expand All @@ -33,7 +32,7 @@
"@types/discord-rpc": "^4.0.8",
"@types/electron-devtools-installer": "^2.2.2",
"@types/jest": "^29.5.8",
"@types/node": "^20.9.2",
"@types/node": "^20.10.8",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@types/turndown": "^5.0.3",
Expand Down
6 changes: 3 additions & 3 deletions src/pages/main.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CaretDown, CaretLeft, CaretUp, Pause, Play, Power, TrashSimple, X } from "@phosphor-icons/react"
import { BellSlash, CaretLeft, TrashSimple } from "@phosphor-icons/react"
import { BigText } from "../typography/big-text"
import { TextButton } from "../utils/text-button"
import { TimeLeft } from "../utils/time-left"
import { useContext, useState } from "react"
import { CurrentSessionContext, Session } from "../context"
import { useContext } from "react"
import { CurrentSessionContext } from "../context"
import { Muted } from "../typography/muted"
import NoSession from "./main_components/no-session"
import FocusSession from "./main_components/focus-session"
Expand Down

0 comments on commit dc652f7

Please sign in to comment.