This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
222 lines (212 loc) · 7.33 KB
/
index.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
const {
app,
Tray,
Menu,
dialog,
shell,
BrowserWindow,
Notification,
nativeImage,
} = require("electron");
const { exec } = require("child_process");
const fs = require("fs");
const path = require("path");
const https = require("https");
app.setAppUserModelId("Oculus Dummy");
app.disableHardwareAcceleration();
Menu.setApplicationMenu(null);
let tray = null,
body = "",
response = "",
updateAvailable = false,
getLatest = "",
version = require("./package.json").version,
getIconNotif = (name) => {
if (name == "alert") {
return path.join(__dirname, "./alert.ico");
} else if (!name) {
return path.join(__dirname, "./icon.ico");
}
};
const lockInstance = !app.requestSingleInstanceLock(),
createWindow = () => {
const win = new BrowserWindow({
title: "Just a sec..",
width: 300,
height: 200,
frame: false,
transparent: true,
resizable: false,
});
win.on("close", (e) => {
e.preventDefault();
win.hide();
});
win.close();
},
exitDialog = {
type: "warning",
buttons: ["Yes", "No"],
title: "Oculus Dummy",
message:
"Are you sure you want to close Oculus Dummy?\n\nOnly close it when you're not in VR, attempting to do so will close SteamVR and any active SteamVR or Oculus games. This might lead to losing your progress and you may be required to restart the OVRService if you run into issues with Oculus Link.\nTo be safe and avoid these issues, it's recommended you only do so when not in VR."
};
https
.get("https://kckarnige.github.io/OculusDummy/latestVersion.json", (res) => {
res.on("data", (chunk) => {
body += chunk;
});
res.on("end", (body) => {
response = JSON.parse(body);
getLatest = response.version + "";
if (response.version > version) {
updateAvailable = true;
}
});
})
.on("error", (e) => {
console.log(e);
});
function getIcon(num) {
icon = nativeImage.createFromPath(path.join(__dirname, "icon.ico"))
if (num) {
return icon.resize({ height: num })
} else {
return icon
}
}
app.whenReady().then(() => {
if (lockInstance) {
app.quit();
process.exit();
}
shell.openItem(
process.env.OculusBase + "Support\\oculus-runtime\\OVRServer_x64.exe"
);
setTimeout(() => {
// Better update notif
if (updateAvailable == true) {
let notif = new Notification({
icon: getIconNotif("alert"),
title: "Time to get you up-to-date",
body: `You're using v${version}, but v${getLatest} is available!`
});
notif.on("click", () => {
shell.openExternal(
"https://github.com/kckarnige/OculusDummy/releases"
);
});
notif.show();
}
}, 1000);
createWindow(); // Fuck you garbage collection
let startupNotif = new Notification({
icon: getIconNotif(),
title: `Oculus Dummy ${version}`,
body: 'You can close it by right-clicking the icon in your system tray then clicking "Exit".'
});
let restartNotif = new Notification({
icon: getIconNotif(),
title: `Attempting to restart OVRService...`,
body: 'Please be patient..'
});
let restartSuccessNotif = new Notification({
icon: getIconNotif(),
title: `OVRService will restart shortly...`,
body: 'Please be patient..'
});
let restartFailedNotif = new Notification({
icon: getIconNotif(),
title: `Unable to restart OVRService`,
body: `Make sure to choose "Yes" on the UAC dialog, let PowerShell do it's thing!`
});
startupNotif.show();
setTimeout(() => {
startupNotif.close();
}, 4000);
tray = new Tray(getIcon());
tray.setToolTip(`Oculus Dummy ${version}`);
tray.setIgnoreDoubleClickEvents(true);
contextMenu = (xtr) => {
return (
Menu.buildFromTemplate([
{
label: `Oculus Dummy ${version}`,
icon: getIcon(16),
click() {
shell.openExternal(
"https://github.com/kckarnige/OculusDummy"
);
},
},
{ type: "separator" },
xtr,
{
label: "Restart OVRService",
click() {
restartNotif.show();
restartService = exec(
`powershell Start-Process powershell -WindowStyle hidden -ArgumentList 'Restart-Service','"OVRService"' -Verb RunAs`,
(err, stdout, stderr) => {
if (err) {
console.log(stderr);
restartNotif.close();
restartFailedNotif.show();
setTimeout(() => {
restartFailedNotif.close();
}, 8000);
} else {
console.log(stdout);
restartNotif.close();
restartSuccessNotif.show();
setTimeout(() => {
restartSuccessNotif.close();
}, 8000);
}
}
);
},
},
{
label: "Open Debug Tool",
click() {
shell.openItem(
process.env.OculusBase + "Support\\oculus-diagnostics\\OculusDebugTool.exe"
);
},
},
{ type: "separator" },
{
label: "Exit",
click() {
dialog.showMessageBox(null, exitDialog, (r) => {
if (r == 0) {
app.quit();
process.exit();
}
});
},
},
]))
}
tray.setContextMenu(contextMenu({ visible: false, enabled: false }));
let xrsetruntimePath = path.join(__dirname, "../", "xrsetruntime.exe") + "";
fs.stat(xrsetruntimePath, (err) => {
if (err) {
console.log("Damn that sucks")
console.log(xrsetruntimePath)
} else {
console.log("Exists!")
tray.setContextMenu(contextMenu(
{
label: "Oculus OpenXR Runtime",
click() {
console.log("RAN")
exec(
`powershell Start-Process '${xrsetruntimePath}' -ArgumentList '-Oculus' -Verb RunAs`
)
}
}));
}
});
});