Skip to content

Commit e2a7c55

Browse files
committed
fix: variables names in main.js. add: package-lock
:P
1 parent 909c8fe commit e2a7c55

File tree

2 files changed

+4878
-124
lines changed

2 files changed

+4878
-124
lines changed

main.js

Lines changed: 124 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ const path = require('path');
33
const fs = require('fs');
44
const Registry = require('winreg');
55

6-
let wnxKjd;
7-
let tryxNoxy = null;
6+
let mainWindow;
7+
let tray = null;
88

9-
function crtWndFksj() {
10-
wnxKjd = new BrowserWindow({
9+
function createWindow() {
10+
mainWindow = new BrowserWindow({
1111
width: 1280,
1212
height: 720,
1313
webPreferences: {
@@ -20,229 +20,229 @@ function crtWndFksj() {
2020
icon: path.join(__dirname, 'src', 'assets', 'logos', 'twl.png'),
2121
});
2222

23-
wnxKjd.loadFile('src/index.html');
24-
wnxKjd.on('close', (evntPqr) => {
25-
evntPqr.preventDefault();
26-
wnxKjd.hide();
23+
mainWindow.loadFile('src/index.html');
24+
mainWindow.on('close', (event) => {
25+
event.preventDefault();
26+
mainWindow.hide();
2727
});
2828

29-
crtTryGhl();
29+
createTray();
3030
}
3131

32-
function gtStmPthJkl() {
33-
return new Promise((rslvMno) => {
34-
const rgKyAbc = new Registry({ hive: Registry.HKCU, key: '\\Software\\Valve\\Steam' });
35-
rgKyAbc.get('SteamPath', (errXyz, itmDef) => {
36-
if (errXyz) {
37-
console.error('Error getting Steam path:', errXyz);
38-
rslvMno(null);
32+
function getSteamPath() {
33+
return new Promise((resolve) => {
34+
const registryKey = new Registry({ hive: Registry.HKCU, key: '\\Software\\Valve\\Steam' });
35+
registryKey.get('SteamPath', (error, item) => {
36+
if (error) {
37+
console.error('Error getting Steam path:', error);
38+
resolve(null);
3939
} else {
40-
rslvMno(itmDef ? itmDef.value : null);
40+
resolve(item ? item.value : null);
4141
}
4242
});
4343
});
4444
}
4545

46-
function prsLbrFldsQwe(stmPthRty) {
46+
function parseLibraryFolders(steamPath) {
4747
try {
48-
const vdfPthUio = path.join(stmPthRty, 'steamapps', 'libraryfolders.vdf');
49-
if (!fs.existsSync(vdfPthUio)) {
50-
console.log('libraryfolders.vdf not found at:', vdfPthUio);
48+
const vdfPath = path.join(steamPath, 'steamapps', 'libraryfolders.vdf');
49+
if (!fs.existsSync(vdfPath)) {
50+
console.log('libraryfolders.vdf not found at:', vdfPath);
5151
return {};
5252
}
5353

54-
const cntntPas = fs.readFileSync(vdfPthUio, 'utf8');
55-
const lbrFldsDfg = {};
56-
let crrntFldrHjk = null;
57-
let inAppsLmn = false;
58-
59-
cntntPas.split('\n').forEach(lnOpq => {
60-
const trmmdRst = lnOpq.trim();
61-
const fldrMtchUvw = trmmdRst.match(/^"(\d+)"$/);
62-
if (fldrMtchUvw && !inAppsLmn) {
63-
crrntFldrHjk = fldrMtchUvw[1];
64-
lbrFldsDfg[crrntFldrHjk] = { path: '', apps: {} };
65-
} else if (crrntFldrHjk && trmmdRst.startsWith('"path"')) {
66-
const pthMtchXyz = trmmdRst.match(/"path"\s+"(.+)"/);
67-
if (pthMtchXyz) lbrFldsDfg[crrntFldrHjk].path = pthMtchXyz[1].replace(/\\\\/g, '\\');
68-
} else if (trmmdRst === '"apps"') {
69-
inAppsLmn = true;
70-
} else if (trmmdRst === '}' && inAppsLmn) {
71-
inAppsLmn = false;
72-
} else if (inAppsLmn && trmmdRst.match(/^"(\d+)"/)) {
73-
const appMtchBcd = trmmdRst.match(/"(\d+)"\s+"(\d+)"/);
74-
if (appMtchBcd) lbrFldsDfg[crrntFldrHjk].apps[appMtchBcd[1]] = appMtchBcd[2];
54+
const content = fs.readFileSync(vdfPath, 'utf8');
55+
const libraryFolders = {};
56+
let currentFolder = null;
57+
let inAppsSection = false;
58+
59+
content.split('\n').forEach(line => {
60+
const trimmedLine = line.trim();
61+
const folderMatch = trimmedLine.match(/^"(\d+)"$/);
62+
if (folderMatch && !inAppsSection) {
63+
currentFolder = folderMatch[1];
64+
libraryFolders[currentFolder] = { path: '', apps: {} };
65+
} else if (currentFolder && trimmedLine.startsWith('"path"')) {
66+
const pathMatch = trimmedLine.match(/"path"\s+"(.+)"/);
67+
if (pathMatch) libraryFolders[currentFolder].path = pathMatch[1].replace(/\\\\/g, '\\');
68+
} else if (trimmedLine === '"apps"') {
69+
inAppsSection = true;
70+
} else if (trimmedLine === '}' && inAppsSection) {
71+
inAppsSection = false;
72+
} else if (inAppsSection && trimmedLine.match(/^"(\d+)"/)) {
73+
const appMatch = trimmedLine.match(/"(\d+)"\s+"(\d+)"/);
74+
if (appMatch) libraryFolders[currentFolder].apps[appMatch[1]] = appMatch[2];
7575
}
7676
});
77-
return lbrFldsDfg;
78-
} catch (errEfg) {
79-
console.error('Error parsing library folders:', errEfg);
77+
return libraryFolders;
78+
} catch (error) {
79+
console.error('Error parsing library folders:', error);
8080
return {};
8181
}
8282
}
8383

84-
async function isStmGmInstldHij(stmPthJkl, appIdMno, gmFldrPqr) {
84+
async function isSteamGameInstalled(steamPath, appId, gameFolder) {
8585
try {
86-
const drctPthStu = path.join(stmPthJkl, 'steamapps', 'common', gmFldrPqr);
87-
if (fs.existsSync(drctPthStu)) return true;
88-
89-
const lbrFldsVwx = prsLbrFldsQwe(stmPthJkl);
90-
for (const fldrYza in lbrFldsVwx) {
91-
if (lbrFldsVwx[fldrYza].apps[appIdMno]) {
92-
const gmPthBcd = path.join(lbrFldsVwx[fldrYza].path, 'steamapps', 'common', gmFldrPqr);
93-
if (fs.existsSync(gmPthBcd)) return true;
86+
const directPath = path.join(steamPath, 'steamapps', 'common', gameFolder);
87+
if (fs.existsSync(directPath)) return true;
88+
89+
const libraryFolders = parseLibraryFolders(steamPath);
90+
for (const folder in libraryFolders) {
91+
if (libraryFolders[folder].apps[appId]) {
92+
const gamePath = path.join(libraryFolders[folder].path, 'steamapps', 'common', gameFolder);
93+
if (fs.existsSync(gamePath)) return true;
9494
}
9595
}
9696
return false;
97-
} catch (errDef) {
98-
console.error('Error checking Steam game installation:', errDef);
97+
} catch (error) {
98+
console.error('Error checking Steam game installation:', error);
9999
return false;
100100
}
101101
}
102102

103-
async function gtGmPthGhi(gmIdJkl) {
104-
const appDtaPthMno = app.getPath('appData');
105-
const gmsPqr = {
103+
async function getGamePath(gameId) {
104+
const appDataPath = app.getPath('appData');
105+
const games = {
106106
'tw': { steamAppId: '380840', steamGameFolder: 'Teeworlds' },
107107
'ddnet': { steamAppId: '412220', steamGameFolder: 'DDraceNetwork' },
108108
'tclient': { clientName: 'TClient' },
109109
'cactus': { clientName: 'Cactus' }
110110
};
111111

112-
const gmDtaStu = gmsPqr[gmIdJkl];
113-
if (!gmDtaStu) return false;
112+
const gameData = games[gameId];
113+
if (!gameData) return false;
114114

115-
if (gmDtaStu.steamAppId) {
116-
const stmPthVwx = await gtStmPthJkl();
117-
if (!stmPthVwx) return false;
118-
return await isStmGmInstldHij(stmPthVwx, gmDtaStu.steamAppId, gmDtaStu.steamGameFolder);
119-
} else if (gmDtaStu.clientName) {
120-
const clntPthYza = path.join(appDtaPthMno, 'TWLauncher', 'clients', gmDtaStu.clientName);
121-
return fs.existsSync(clntPthYza);
115+
if (gameData.steamAppId) {
116+
const steamPath = await getSteamPath();
117+
if (!steamPath) return false;
118+
return await isSteamGameInstalled(steamPath, gameData.steamAppId, gameData.steamGameFolder);
119+
} else if (gameData.clientName) {
120+
const clientPath = path.join(appDataPath, 'TWLauncher', 'clients', gameData.clientName);
121+
return fs.existsSync(clientPath);
122122
}
123123
return false;
124124
}
125125

126-
async function bldTryMnuAbc() {
126+
async function buildTrayMenu() {
127127
try {
128-
const isTwInstldDef = await gtGmPthGhi('tw');
129-
const isDdnetInstldGhi = await gtGmPthGhi('ddnet');
130-
const isTclntInstldJkl = await gtGmPthGhi('tclient');
131-
const isCctsInstldMno = await gtGmPthGhi('cactus');
128+
const isTeeworldsInstalled = await getGamePath('tw');
129+
const isDdnetInstalled = await getGamePath('ddnet');
130+
const isTclientInstalled = await getGamePath('tclient');
131+
const isCactusInstalled = await getGamePath('cactus');
132132

133133
console.log('Building tray menu with status:', {
134-
Teeworlds: isTwInstldDef,
135-
DDraceNetwork: isDdnetInstldGhi,
136-
TClient: isTclntInstldJkl,
137-
Cactus: isCctsInstldMno
134+
Teeworlds: isTeeworldsInstalled,
135+
DDraceNetwork: isDdnetInstalled,
136+
TClient: isTclientInstalled,
137+
Cactus: isCactusInstalled
138138
});
139139

140-
const lnchSubmnuPqr = Menu.buildFromTemplate([
140+
const launchSubmenu = Menu.buildFromTemplate([
141141
{
142142
label: 'Teeworlds',
143143
icon: path.join(__dirname, 'src', 'assets', 'tray', 'tw.png'),
144-
click: () => lnchGmStu('tw'),
145-
enabled: isTwInstldDef
144+
click: () => launchGame('tw'),
145+
enabled: isTeeworldsInstalled
146146
},
147147
{
148148
label: 'DDraceNetwork',
149149
icon: path.join(__dirname, 'src', 'assets', 'tray', 'ddnet.png'),
150-
click: () => lnchGmStu('ddnet'),
151-
enabled: isDdnetInstldGhi
150+
click: () => launchGame('ddnet'),
151+
enabled: isDdnetInstalled
152152
},
153153
{
154154
label: 'TClient',
155155
icon: path.join(__dirname, 'src', 'assets', 'tray', 'tclient.png'),
156-
click: () => lnchGmStu('tclient'),
157-
enabled: isTclntInstldJkl
156+
click: () => launchGame('tclient'),
157+
enabled: isTclientInstalled
158158
},
159159
{
160160
label: 'Cactus',
161161
icon: path.join(__dirname, 'src', 'assets', 'tray', 'cactus.png'),
162-
click: () => lnchGmStu('cactus'),
163-
enabled: isCctsInstldMno
162+
click: () => launchGame('cactus'),
163+
enabled: isCactusInstalled
164164
}
165165
]);
166166

167167
return Menu.buildFromTemplate([
168-
{ label: 'Show App', click: () => wnxKjd.show() },
169-
{ label: 'Launch', submenu: lnchSubmnuPqr },
168+
{ label: 'Show App', click: () => mainWindow.show() },
169+
{ label: 'Launch', submenu: launchSubmenu },
170170
{ label: 'Close App', click: () => {
171-
wnxKjd.destroy();
171+
mainWindow.destroy();
172172
app.quit();
173173
}},
174174
]);
175-
} catch (errVwx) {
176-
console.error('Error building tray menu:', errVwx);
175+
} catch (error) {
176+
console.error('Error building tray menu:', error);
177177
return Menu.buildFromTemplate([
178-
{ label: 'Show App', click: () => wnxKjd.show() },
178+
{ label: 'Show App', click: () => mainWindow.show() },
179179
{ label: 'Close App', click: () => {
180-
wnxKjd.destroy();
180+
mainWindow.destroy();
181181
app.quit();
182182
}}
183183
]);
184184
}
185185
}
186186

187-
function crtTryGhl() {
188-
tryxNoxy = new Tray(path.join(__dirname, 'src', 'assets', 'logos', 'twl.png'));
189-
tryxNoxy.setToolTip('TWLauncher by noxygalaxy');
187+
function createTray() {
188+
tray = new Tray(path.join(__dirname, 'src', 'assets', 'logos', 'twl.png'));
189+
tray.setToolTip('TWLauncher by noxygalaxy');
190190

191-
tryxNoxy.on('right-click', async () => {
191+
tray.on('right-click', async () => {
192192
console.log('Tray right-clicked');
193-
const mnuYza = await bldTryMnuAbc();
194-
tryxNoxy.popUpContextMenu(mnuYza);
193+
const menu = await buildTrayMenu();
194+
tray.popUpContextMenu(menu);
195195
});
196196

197-
bldTryMnuAbc().then(mnuBcd => {
198-
tryxNoxy.setContextMenu(mnuBcd);
197+
buildTrayMenu().then(menu => {
198+
tray.setContextMenu(menu);
199199
});
200200
}
201201

202-
function lnchGmStu(idEfg) {
203-
console.log(`Launching game: ${idEfg}`);
204-
wnxKjd.webContents.send('launch-game', idEfg);
202+
function launchGame(id) {
203+
console.log(`Launching game: ${id}`);
204+
mainWindow.webContents.send('launch-game', id);
205205
}
206206

207207
ipcMain.on('minimize-window', () => {
208-
wnxKjd.minimize();
208+
mainWindow.minimize();
209209
});
210210

211211
ipcMain.on('hide-window', () => {
212-
wnxKjd.hide();
213-
tryxNoxy.displayBalloon({
214-
title:'TWLauncher',
215-
content:'Launcher will work in background, to close it right click on the tray icon',
212+
mainWindow.hide();
213+
tray.displayBalloon({
214+
title: 'TWLauncher',
215+
content: 'Launcher will work in background, to close it right click on the tray icon',
216216
icon: path.join(__dirname, 'src', 'assets', 'logos', 'twl.png'),
217217
});
218218
});
219219

220220
ipcMain.on('launch-game', async () => {
221-
const mnuHij = await bldTryMnuAbc();
222-
tryxNoxy.setContextMenu(mnuHij);
221+
const menu = await buildTrayMenu();
222+
tray.setContextMenu(menu);
223223
});
224224

225225
app.whenReady().then(() => {
226-
const appDtaPthJkl = app.getPath('appData');
227-
const clntsPthMno = path.join(appDtaPthJkl, 'TWLauncher', 'clients');
226+
const appDataPath = app.getPath('appData');
227+
const clientsPath = path.join(appDataPath, 'TWLauncher', 'clients');
228228

229-
if (!fs.existsSync(clntsPthMno)) {
230-
fs.mkdirSync(clntsPthMno, { recursive: true });
229+
if (!fs.existsSync(clientsPath)) {
230+
fs.mkdirSync(clientsPath, { recursive: true });
231231
}
232232

233-
crtWndFksj();
233+
createWindow();
234234

235235
app.on('activate', () => {
236-
if (BrowserWindow.getAllWindows().length === 0) crtWndFksj();
237-
else wnxKjd.show();
236+
if (BrowserWindow.getAllWindows().length === 0) createWindow();
237+
else mainWindow.show();
238238
});
239239
});
240240

241-
app.on('window-all-closed', (ePqr) => {
242-
ePqr.preventDefault();
243-
tryxNoxy.displayBalloon({
244-
title:'TWLauncher',
245-
content:'Goodbye! <3',
241+
app.on('window-all-closed', (event) => {
242+
event.preventDefault();
243+
tray.displayBalloon({
244+
title: 'TWLauncher',
245+
content: 'Goodbye! <3',
246246
icon: path.join(__dirname, 'src', 'assets', 'logos', 'twl.png'),
247247
});
248-
});
248+
});

0 commit comments

Comments
 (0)