Skip to content
This repository was archived by the owner on Jul 17, 2024. It is now read-only.
/ Linux Public archive

Commit 7562754

Browse files
committed
🎨 [REL] 2.2.17
1 parent 7a3e439 commit 7562754

File tree

8 files changed

+260
-261
lines changed

8 files changed

+260
-261
lines changed

src/index.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,30 @@ export let trayManager: TrayManager;
1111
//* When app is ready
1212
export let updateCheckerInterval = null;
1313
app.whenReady().then(async () => {
14-
trayManager = new TrayManager();
14+
trayManager = new TrayManager();
1515

16-
await initAutoLaunch();
17-
await initSocket();
16+
await initAutoLaunch();
17+
await initSocket();
1818

19-
if (app.isPackaged && app.name.includes("Portable")) {
20-
await checkForUpdate(true);
21-
updateCheckerInterval = setInterval(() => {
22-
checkForUpdate(true);
23-
}, 15 * 1000 * 60);
24-
}
19+
if (app.isPackaged && app.name.includes("Portable")) {
20+
await checkForUpdate(true);
21+
updateCheckerInterval = setInterval(() => {
22+
checkForUpdate(true);
23+
}, 15 * 1000 * 60);
24+
}
2525
});
2626

2727
//* If second instance started, close old one
2828
app.on("second-instance", () => app.exit(0));
2929

3030
//* Send errors from app to extension
3131
process.on("unhandledRejection", rejection => {
32-
console.error(rejection);
33-
if (socket && socket.connected) socket.emit("unhandledRejection", rejection);
32+
console.error(rejection);
33+
if (socket && socket.connected) socket.emit("unhandledRejection", rejection);
3434
});
3535

3636
// TODO Find better way to log
3737
process.on("uncaughtException", err => {
38-
dialog.showErrorBox(err.name, err.stack);
39-
app.exit(0);
38+
dialog.showErrorBox(err.name, err.stack);
39+
app.exit(0);
4040
});

src/managers/discordManager.ts

Lines changed: 87 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -8,113 +8,112 @@ import PresenceData from "../../@types/PreMiD/PresenceData";
88
export let rpcClients: Array<RPCClient> = [];
99

1010
class RPCClient {
11-
clientId: string;
12-
currentPresence: PresenceData;
13-
client: Client;
14-
clientReady: boolean = false;
15-
16-
constructor(clientId: string) {
17-
rpcClients.push(this);
18-
19-
this.clientId = clientId;
20-
this.client = new Client({
21-
transport: "ipc"
22-
});
23-
24-
this.client.once("ready", () => {
25-
this.clientReady = true;
26-
this.setActivity();
27-
});
28-
29-
this.client.once(
30-
// @ts-ignore
31-
"disconnected",
32-
() =>
33-
(rpcClients = rpcClients.filter(
34-
client => client.clientId !== this.clientId
35-
))
36-
);
37-
38-
this.client.login({ clientId: this.clientId }).catch(() => this.destroy());
39-
40-
console.log(`Create RPC client (${this.clientId})`);
41-
}
42-
43-
setActivity(presenceData?: PresenceData) {
44-
presenceData = presenceData ? presenceData : this.currentPresence;
45-
46-
if (!this.clientReady || !presenceData) return;
47-
48-
// Workaround
49-
if (
50-
presenceData.presenceData.largeImageText &&
51-
presenceData.presenceData.largeImageText.includes("PreMiD")
52-
)
53-
presenceData.presenceData.largeImageText =
54-
`PreMiD 🐧 v${app.getVersion()}`;
55-
56-
this.client
57-
.setActivity(presenceData.presenceData)
58-
.catch(() => this.destroy());
59-
}
60-
61-
clearActivity() {
62-
this.currentPresence = null;
63-
64-
if (!this.clientReady) return;
65-
66-
this.client.clearActivity().catch(() => this.destroy());
67-
}
68-
69-
async destroy() {
70-
try {
71-
console.log(`Destroy RPC client (${this.clientId})`);
72-
this.client.clearActivity();
73-
this.client.destroy();
74-
75-
rpcClients = rpcClients.filter(
76-
client => client.clientId !== this.clientId
77-
);
78-
} catch (err) {}
79-
}
11+
clientId: string;
12+
currentPresence: PresenceData;
13+
client: Client;
14+
clientReady: boolean = false;
15+
16+
constructor(clientId: string) {
17+
rpcClients.push(this);
18+
19+
this.clientId = clientId;
20+
this.client = new Client({
21+
transport: "ipc"
22+
});
23+
24+
this.client.once("ready", () => {
25+
this.clientReady = true;
26+
this.setActivity();
27+
});
28+
29+
this.client.once(
30+
// @ts-ignore
31+
"disconnected",
32+
() =>
33+
(rpcClients = rpcClients.filter(
34+
client => client.clientId !== this.clientId
35+
))
36+
);
37+
38+
this.client.login({ clientId: this.clientId }).catch(() => this.destroy());
39+
40+
console.log(`Create RPC client (${this.clientId})`);
41+
}
42+
43+
setActivity(presenceData?: PresenceData) {
44+
presenceData = presenceData ? presenceData : this.currentPresence;
45+
46+
if (!this.clientReady || !presenceData) return;
47+
48+
// Workaround
49+
if (
50+
presenceData.presenceData.largeImageText &&
51+
presenceData.presenceData.largeImageText.includes("PreMiD")
52+
)
53+
presenceData.presenceData.largeImageText = `PreMiD 🐧 v${app.getVersion()}`;
54+
55+
this.client
56+
.setActivity(presenceData.presenceData)
57+
.catch(() => this.destroy());
58+
}
59+
60+
clearActivity() {
61+
this.currentPresence = null;
62+
63+
if (!this.clientReady) return;
64+
65+
this.client.clearActivity().catch(() => this.destroy());
66+
}
67+
68+
async destroy() {
69+
try {
70+
console.log(`Destroy RPC client (${this.clientId})`);
71+
this.client.clearActivity();
72+
this.client.destroy();
73+
74+
rpcClients = rpcClients.filter(
75+
client => client.clientId !== this.clientId
76+
);
77+
} catch (err) {}
78+
}
8079
}
8180

8281
/**
8382
* Sets the user's activity
8483
* @param presence PresenceData to set activity
8584
*/
8685
export function setActivity(presence: PresenceData) {
87-
let client = rpcClients.find(c => c.clientId === presence.clientId);
86+
let client = rpcClients.find(c => c.clientId === presence.clientId);
8887

89-
if (!client) {
90-
client = new RPCClient(presence.clientId);
91-
client.currentPresence = presence;
92-
} else client.setActivity(presence);
88+
if (!client) {
89+
client = new RPCClient(presence.clientId);
90+
client.currentPresence = presence;
91+
} else client.setActivity(presence);
9392
}
9493

9594
/**
9695
* Clear a user's activity
9796
* @param clientId clientId of presence to clear
9897
*/
9998
export function clearActivity(clientId: string = undefined) {
100-
if (clientId) {
101-
let client = rpcClients.find(c => c.clientId === clientId);
102-
console.log("Clear activity");
103-
client.clearActivity();
104-
} else {
105-
rpcClients.forEach(c => c.clearActivity());
106-
console.log("Clear all activity");
107-
}
99+
if (clientId) {
100+
let client = rpcClients.find(c => c.clientId === clientId);
101+
console.log("Clear activity");
102+
client.clearActivity();
103+
} else {
104+
rpcClients.forEach(c => c.clearActivity());
105+
console.log("Clear all activity");
106+
}
108107
}
109108

110109
export async function getDiscordUser() {
111-
const user = await new Client({ transport: "ipc" }).login({
112-
clientId: "503557087041683458"
113-
});
114-
return user.user;
110+
const user = await new Client({ transport: "ipc" }).login({
111+
clientId: "503557087041683458"
112+
});
113+
return user.user;
115114
}
116115

117116
app.once(
118-
"will-quit",
119-
async () => await Promise.all(rpcClients.map(c => c.destroy()))
117+
"will-quit",
118+
async () => await Promise.all(rpcClients.map(c => c.destroy()))
120119
);

src/managers/launchManager.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ import { settings } from "./settingsManager";
44

55
//* Create autoLaunch object
66
let autoLaunch = new AutoLaunch({
7-
name: app.name,
8-
isHidden: true
7+
name: app.name,
8+
isHidden: true
99
});
1010

1111
/**
1212
* Updates autoLaunch
1313
*/
1414
export async function update() {
15-
//* If app not packaged return
16-
//* Either enable/disable autolaunch
17-
if (!app.isPackaged || (app.isPackaged && app.name.includes("Portable"))) {
18-
//* Return
19-
console.log(
20-
(app.isPackaged
21-
? "Portable version detected,"
22-
: "Debug version detected,") + " skipping autoLaunch"
23-
);
24-
return;
25-
}
26-
if (settings.get("autoLaunch", true))
27-
//* Enable if not enabled
28-
autoLaunch.enable();
29-
//* Disable if enabled
30-
else autoLaunch.disable();
15+
//* If app not packaged return
16+
//* Either enable/disable autolaunch
17+
if (!app.isPackaged || (app.isPackaged && app.name.includes("Portable"))) {
18+
//* Return
19+
console.log(
20+
(app.isPackaged
21+
? "Portable version detected,"
22+
: "Debug version detected,") + " skipping autoLaunch"
23+
);
24+
return;
25+
}
26+
if (settings.get("autoLaunch", true))
27+
//* Enable if not enabled
28+
autoLaunch.enable();
29+
//* Disable if enabled
30+
else autoLaunch.disable();
3131
}

0 commit comments

Comments
 (0)