This repository has been archived by the owner on Mar 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
194 lines (164 loc) · 4.73 KB
/
main.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
const electron = require('electron');
const discord = require('discord-rpc')
const path = require('path');
const steam = require('steamworks.js');
const { app, BrowserWindow, Menu } = electron;
let steamAvailable = false;
// Initialize Discord RPC
const discordClientId = "772995176041283615";
discord.register(discordClientId);
const rpc = new discord.Client({ transport: "ipc" });
const startTimestamp = new Date();
let steamClient;
// Load correct flash player
let pluginName = null;
switch (process.platform) {
case 'win32':
switch (process.arch) {
case 'ia32':
case 'x32':
pluginName = 'flashver/pepflashplayer32.dll'
console.log("ran!");
break
case 'x64':
pluginName = 'flashver/pepflashplayer64.dll'
console.log("ran!");
break
}
break
case 'linux':
switch (process.arch) {
case 'ia32':
case 'x32':
break
case 'x64':
pluginName = 'flashver/libpepflashplayer.so'
break
}
app.commandLine.appendSwitch('no-sandbox');
break
case 'darwin':
pluginName = 'flashver/PepperFlashPlayer.plugin'
break
}
app.commandLine.appendSwitch('ppapi-flash-path', path.join(__dirname, pluginName));
//CACHE IS ENABLED but restarted on launch!
let mainWindow;
app.on('ready', function () {
initializeSteamWorks();
// create window
let win = new BrowserWindow({
show: false,
icon: "resources/logo.png",
webPreferences: {
plugins: true,
contextIsolation: false,
nodeIntegration: true
},
title: "Galaxy Life",
autoHideMenuBar: true,
darkTheme: true
})
initializeBrowserMenu(win);
// load default page
win.loadURL("https://game.galaxylifegame.net/game", { userAgent: "GLLauncherSteam" });
win.maximize();
win.webContents.session.clearCache(function () {
//clearCache
});
// login to discord for rpc
rpc.login({ clientId: discordClientId }).catch(console.error);
})
// Set activity every 15 seconds
rpc.on('ready', async () => {
setDiscordActivity();
setInterval(() => {
setDiscordActivity();
}, 15000);
});
app.on('window-all-closed', () => {
// apparently darwins an edge case
if (process.platform !== 'darwin') {
app.quit();
}
});
async function setDiscordActivity() {
// discord failed to setup
if (!rpc) {
return;
}
rpc.setActivity({
details: "Pushing a starling on a swing",
startTimestamp: startTimestamp,
largeImageKey: "gl-icon",
instance: false,
buttons: [
{
label: "Play now!",
url: "https://galaxylifegame.net"
}
]
});
}
function initializeBrowserMenu(win) {
var menu = Menu.buildFromTemplate([
{
label: "Actions",
submenu: [
{
label: "Reload Game",
accelerator: process.platform === "darwin" ? "Cmd+R" : "Ctrl+R",
click() { win.loadURL("https://game.galaxylifegame.net/game", { userAgent: "GLLauncherSteam" }); }
},
{
label: "Reload",
acceleratorWorksWhenHidden: true,
accelerator: "F5",
click() { win.loadURL("https://game.galaxylifegame.net/game", { userAgent: "GLLauncherSteam" }); },
visible: false
}
],
},
{
label: "Options",
submenu: [
{
label: "Fullscreen",
accelerator: "F11",
click() { win.fullScreen = !win.fullScreen; }
}
]
},
]);
Menu.setApplicationMenu(menu);
}
function initializeSteamWorks() {
try {
// work around to make .init() (according to greenworks docs)
process.activateUvLoop();
if (!(steamClient = steam.init(1927780))) {
console.log("Failed to initialize steamworks");
return;
}
steamAvailable = true;
} catch (error) {
console.log(error);
}
}
function isSteamAvailable() {
return steamAvailable;
}
function getSteamFriends() {
if (!steamAvailable) {
return;
}
var friends = greenworks.getFriends(greenworks.FriendFlags.Immediate);
return friends;
}
function getPersonaName() {
if (!steamAvailable) {
return;
}
return greenworks.getSteamId().getPersonaName();
}
require('steamworks.js').electronEnableSteamOverlay();