-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselector.js
83 lines (75 loc) · 2.91 KB
/
selector.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var connection = null
const RPC = require('discord-rpc');
const Swal = require('sweetalert2')
const fs = require('fs')
const { shell } = require('electron')
async function select(name) {
if (connection) if(connection.name === name){
document.getElementById(connection.name).style.backgroundColor = 'transparent'
connection = null
return connection.destroy()
}
Swal.fire({
title: 'Do you want to start ' + name.replace(".json", "").replace(".", "") + '?',
showDenyButton: true,
confirmButtonText: 'Yes',
denyButtonText: `Cancel`,
}).then(async (result) => {
/* Read more about isConfirmed, isDenied below */
if (result.isConfirmed) {
console.log(name)
if(connection){
document.getElementById(connection.name).style.backgroundColor = 'transparent'
connection.destroy()
}
var data = await fs.readFileSync('./rpcs/'+name, 'utf8')
data = JSON.parse(data)
connection = new RPC.Client({ transport: 'ipc' });
connection.login({ clientId: data.clientID });
connection.on('ready', () => {
const activity = {
startTimestamp: Date.now(),
instance: true
}
if(data.detail){
activity.details = data.detail
}
if(data.state){
activity.state = data.state
}
if(data.assets.large_image){
activity.largeImageKey = data.assets.large_image
}
if(data.assets.large_text){
activity.largeImageText = data.assets.large_text
}
if(data.assets.small_image){
activity.smallImageKey = data.assets.small_image
}
if(data.assets.small_text){
activity.smallImageText = data.assets.small_text
}
if(data.buttons[0]) {
activity.buttons = []
activity.buttons[0] = data.buttons[0]
}
if(data.buttons[1]) {
activity.buttons[1] = data.buttons[1]
}
connection.setActivity(activity);
document.getElementById(name).style.backgroundColor = 'rgba(4, 0, 255, 0.295)'
connection.name = name
if(data.run){
var spawn = require("child_process").spawn
spawn(data.run, [], {shell: false})
}
})
} else if (result.isDenied) {
Swal.fire('Canceled', '', 'info')
}
})
}
function openDir(){
let spawn = require("child_process").spawn
shell.openExternal('file://' + process.cwd()+'/rpcs')
}