578 lines
26 KiB
JavaScript
578 lines
26 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const electron_1 = require("electron");
|
|
const path_1 = __importDefault(require("path"));
|
|
const electron_store_1 = __importDefault(require("electron-store"));
|
|
const child_process_1 = require("child_process");
|
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
const axios_1 = __importDefault(require("axios"));
|
|
const fs_1 = __importDefault(require("fs"));
|
|
const url_1 = require("url");
|
|
const steam_web_1 = require("./services/steam-web");
|
|
const scraper_1 = require("./services/scraper");
|
|
const steam_client_1 = require("./services/steam-client");
|
|
const backend_1 = require("./services/backend");
|
|
// Reliable isDev check
|
|
const isDev = !electron_1.app.isPackaged;
|
|
electron_1.app.name = "Ultimate Ban Tracker";
|
|
// Load environment variables
|
|
dotenv_1.default.config({ path: path_1.default.join(electron_1.app.getAppPath(), '..', '.env') });
|
|
// --- App State ---
|
|
let mainWindow = null;
|
|
let tray = null;
|
|
let backend = null;
|
|
electron_1.app.isQuitting = false;
|
|
const store = new electron_store_1.default({
|
|
defaults: {
|
|
accounts: [],
|
|
serverConfig: { url: 'https://ultimate-ban-tracker.narl.io', enabled: false }
|
|
}
|
|
});
|
|
// --- Avatar Cache Logic ---
|
|
const AVATAR_DIR = path_1.default.join(electron_1.app.getPath('userData'), 'avatars');
|
|
if (!fs_1.default.existsSync(AVATAR_DIR))
|
|
fs_1.default.mkdirSync(AVATAR_DIR, { recursive: true });
|
|
const downloadAvatar = async (steamId, url) => {
|
|
if (!url)
|
|
return undefined;
|
|
const localPath = path_1.default.join(AVATAR_DIR, `${steamId}.jpg`);
|
|
try {
|
|
const response = await axios_1.default.get(url, { responseType: 'arraybuffer', timeout: 5000 });
|
|
fs_1.default.writeFileSync(localPath, Buffer.from(response.data));
|
|
return localPath;
|
|
}
|
|
catch (e) {
|
|
return undefined;
|
|
}
|
|
};
|
|
// --- Backend ---
|
|
const initBackend = () => {
|
|
const config = store.get('serverConfig');
|
|
if (config && config.enabled && config.url) {
|
|
backend = new backend_1.BackendService(config.url, config.token);
|
|
}
|
|
else {
|
|
backend = null;
|
|
}
|
|
};
|
|
// --- System Tray ---
|
|
const createTray = () => {
|
|
const assetsDir = path_1.default.join(__dirname, '..', 'assets-build');
|
|
const possibleIcons = ['icon.svg', 'icon.png'];
|
|
let iconPath = '';
|
|
for (const name of possibleIcons) {
|
|
const fullPath = path_1.default.join(assetsDir, name);
|
|
if (fs_1.default.existsSync(fullPath)) {
|
|
iconPath = fullPath;
|
|
break;
|
|
}
|
|
}
|
|
console.log(`[Tray] Attempting to initialize with icon: ${iconPath || 'NONE FOUND'}`);
|
|
if (!iconPath) {
|
|
console.warn(`[Tray] FAILED: No valid icon found in ${assetsDir}`);
|
|
return;
|
|
}
|
|
try {
|
|
const icon = electron_1.nativeImage.createFromPath(iconPath).resize({ width: 16, height: 16 });
|
|
tray = new electron_1.Tray(icon);
|
|
tray.setToolTip('Ultimate Ban Tracker');
|
|
tray.on('click', () => {
|
|
if (mainWindow) {
|
|
mainWindow.show();
|
|
mainWindow.focus();
|
|
}
|
|
});
|
|
updateTrayMenu();
|
|
console.log(`[Tray] Successfully initialized`);
|
|
}
|
|
catch (e) {
|
|
console.error(`[Tray] Critical error during initialization: ${e.message}`);
|
|
}
|
|
};
|
|
const updateTrayMenu = () => {
|
|
if (!tray)
|
|
return;
|
|
const accounts = store.get('accounts');
|
|
const config = store.get('serverConfig');
|
|
const contextMenu = electron_1.Menu.buildFromTemplate([
|
|
{ label: `Ultimate Ban Tracker v${electron_1.app.getVersion()}`, enabled: false },
|
|
{ type: 'separator' },
|
|
{
|
|
label: 'Switch Account',
|
|
submenu: accounts.length > 0 ? accounts.map(acc => ({
|
|
label: `${acc.personaName} ${acc.loginName ? `(${acc.loginName})` : ''}`,
|
|
enabled: !!acc.loginName,
|
|
click: () => handleSwitchAccount(acc.loginName)
|
|
})) : [{ label: 'No accounts found', enabled: false }]
|
|
},
|
|
{
|
|
label: 'Sync Now',
|
|
enabled: !!config?.enabled,
|
|
click: () => syncAccounts()
|
|
},
|
|
{ type: 'separator' },
|
|
{ label: 'Show Dashboard', click: () => { if (mainWindow)
|
|
mainWindow.show(); } },
|
|
{ label: 'Quit', click: () => { electron_1.app.isQuitting = true; electron_1.app.quit(); } }
|
|
]);
|
|
tray.setContextMenu(contextMenu);
|
|
};
|
|
// --- Steam Logic ---
|
|
const killSteam = async () => {
|
|
return new Promise((resolve) => {
|
|
const command = process.platform === 'win32' ? 'taskkill /f /im steam.exe' : 'pkill -9 steam';
|
|
(0, child_process_1.exec)(command, () => setTimeout(resolve, 1000));
|
|
});
|
|
};
|
|
const startSteam = () => {
|
|
const command = process.platform === 'win32' ? 'start steam://open/main' : 'steam &';
|
|
(0, child_process_1.exec)(command);
|
|
};
|
|
const handleSwitchAccount = async (loginName) => {
|
|
if (!loginName)
|
|
return false;
|
|
try {
|
|
await killSteam();
|
|
const accounts = store.get('accounts');
|
|
const account = accounts.find(a => a.loginName === loginName);
|
|
if (process.platform === 'win32') {
|
|
const regCommand = `reg add "HKCU\\Software\\Valve\\Steam" /v AutoLoginUser /t REG_SZ /d "${loginName}" /f`;
|
|
const rememberCommand = `reg add "HKCU\\Software\\Valve\\Steam" /v RememberPassword /t REG_DWORD /d 1 /f`;
|
|
await new Promise((res, rej) => (0, child_process_1.exec)(`${regCommand} && ${rememberCommand}`, (e) => e ? rej(e) : res()));
|
|
if (account && account.loginConfig)
|
|
steam_client_1.steamClient.injectAccountConfig(loginName, account.loginConfig);
|
|
}
|
|
else if (process.platform === 'linux') {
|
|
await steam_client_1.steamClient.setAutoLoginUser(loginName, account?.loginConfig, account?.steamId);
|
|
}
|
|
startSteam();
|
|
return true;
|
|
}
|
|
catch (e) {
|
|
return false;
|
|
}
|
|
};
|
|
// --- Sync Worker ---
|
|
const syncAccounts = async () => {
|
|
initBackend();
|
|
let accounts = store.get('accounts');
|
|
let hasChanges = false;
|
|
if (backend) {
|
|
try {
|
|
const shared = await backend.getSharedAccounts();
|
|
for (const s of shared) {
|
|
const exists = accounts.find(a => a.steamId === s.steamId);
|
|
if (!exists) {
|
|
accounts.push({
|
|
_id: `shared_${s.steamId}`,
|
|
steamId: s.steamId, personaName: s.personaName, avatar: s.avatar, profileUrl: s.profileUrl,
|
|
vacBanned: s.vacBanned, gameBans: s.gameBans, cooldownExpiresAt: s.cooldownExpiresAt,
|
|
loginName: s.loginName || '', steamLoginSecure: s.steamLoginSecure, loginConfig: s.loginConfig,
|
|
sessionUpdatedAt: s.sessionUpdatedAt, autoCheckCooldown: !!s.steamLoginSecure,
|
|
status: (s.vacBanned || s.gameBans > 0) ? 'banned' : 'none', lastBanCheck: new Date().toISOString()
|
|
});
|
|
hasChanges = true;
|
|
}
|
|
else {
|
|
const sDate = s.sessionUpdatedAt ? new Date(s.sessionUpdatedAt) : new Date(0);
|
|
const lDate = exists.sessionUpdatedAt ? new Date(exists.sessionUpdatedAt) : new Date(0);
|
|
if (sDate > lDate) {
|
|
if (s.loginName)
|
|
exists.loginName = s.loginName;
|
|
if (s.loginConfig)
|
|
exists.loginConfig = s.loginConfig;
|
|
if (s.steamLoginSecure) {
|
|
exists.steamLoginSecure = s.steamLoginSecure;
|
|
exists.autoCheckCooldown = true;
|
|
exists.authError = false;
|
|
}
|
|
exists.sessionUpdatedAt = s.sessionUpdatedAt;
|
|
hasChanges = true;
|
|
}
|
|
if (s.cooldownExpiresAt && (!exists.cooldownExpiresAt || new Date(s.cooldownExpiresAt) > new Date(exists.cooldownExpiresAt))) {
|
|
exists.cooldownExpiresAt = s.cooldownExpiresAt;
|
|
hasChanges = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (e) { }
|
|
}
|
|
if (hasChanges) {
|
|
store.set('accounts', accounts);
|
|
if (mainWindow)
|
|
mainWindow.webContents.send('accounts-updated', accounts);
|
|
updateTrayMenu();
|
|
}
|
|
if (accounts.length === 0)
|
|
return;
|
|
const updatedAccounts = [...accounts];
|
|
let scrapeChanges = false;
|
|
for (const account of updatedAccounts) {
|
|
try {
|
|
const now = new Date();
|
|
const lastCheck = account.lastBanCheck ? new Date(account.lastBanCheck) : new Date(0);
|
|
if ((now.getTime() - lastCheck.getTime()) / 3600000 > 6 || !account.personaName) {
|
|
const profile = await (0, steam_web_1.fetchProfileData)(account.steamId, account.steamLoginSecure);
|
|
const bans = await (0, steam_web_1.scrapeBanStatus)(profile.profileUrl, account.steamLoginSecure);
|
|
account.personaName = profile.personaName;
|
|
account.profileUrl = profile.profileUrl;
|
|
account.vacBanned = bans.vacBanned;
|
|
account.gameBans = bans.gameBans;
|
|
account.status = (bans.vacBanned || bans.gameBans > 0) ? 'banned' : 'none';
|
|
account.lastBanCheck = now.toISOString();
|
|
if (profile.avatar && (!account.localAvatar || profile.avatar !== account.avatar)) {
|
|
account.avatar = profile.avatar;
|
|
const localPath = await downloadAvatar(account.steamId, profile.avatar);
|
|
if (localPath)
|
|
account.localAvatar = localPath;
|
|
}
|
|
if (account.loginName) {
|
|
const config = steam_client_1.steamClient.extractAccountConfig(account.loginName);
|
|
if (config) {
|
|
account.loginConfig = config;
|
|
account.sessionUpdatedAt = new Date().toISOString();
|
|
}
|
|
}
|
|
if (backend)
|
|
await backend.shareAccount(account);
|
|
scrapeChanges = true;
|
|
}
|
|
if (account.autoCheckCooldown && account.steamLoginSecure) {
|
|
if (account.cooldownExpiresAt && new Date(account.cooldownExpiresAt) > now)
|
|
continue;
|
|
const lastScrape = account.lastScrapeTime ? new Date(account.lastScrapeTime) : new Date(0);
|
|
if ((now.getTime() - lastScrape.getTime()) / 3600000 > 8) {
|
|
await new Promise(r => setTimeout(r, Math.floor(Math.random() * 60000) + 5000));
|
|
try {
|
|
const result = await (0, scraper_1.scrapeCooldown)(account.steamId, account.steamLoginSecure);
|
|
account.authError = false;
|
|
account.lastScrapeTime = new Date().toISOString();
|
|
if (result.isActive) {
|
|
account.cooldownExpiresAt = result.expiresAt ? result.expiresAt.toISOString() : new Date(Date.now() + 86400000).toISOString();
|
|
if (backend)
|
|
await backend.pushCooldown(account.steamId, account.cooldownExpiresAt);
|
|
}
|
|
else if (account.cooldownExpiresAt) {
|
|
account.cooldownExpiresAt = undefined;
|
|
if (backend)
|
|
await backend.pushCooldown(account.steamId, undefined);
|
|
}
|
|
scrapeChanges = true;
|
|
}
|
|
catch (e) {
|
|
if (e.message.includes('cookie') || e.message.includes('Sign In')) {
|
|
account.authError = true;
|
|
scrapeChanges = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (error) { }
|
|
}
|
|
if (scrapeChanges) {
|
|
store.set('accounts', updatedAccounts);
|
|
if (mainWindow)
|
|
mainWindow.webContents.send('accounts-updated', updatedAccounts);
|
|
updateTrayMenu();
|
|
}
|
|
};
|
|
const scheduleNextSync = () => {
|
|
setTimeout(async () => { await syncAccounts(); scheduleNextSync(); }, isDev ? 120000 : 1800000);
|
|
};
|
|
// --- Discovery ---
|
|
const addingAccounts = new Set();
|
|
const handleLocalAccountsFound = async (localAccounts) => {
|
|
const currentAccounts = store.get('accounts');
|
|
let hasChanges = false;
|
|
for (const local of localAccounts) {
|
|
if (addingAccounts.has(local.steamId))
|
|
continue;
|
|
const exists = currentAccounts.find(a => a.steamId === local.steamId);
|
|
if (exists) {
|
|
if (!exists.loginName && local.accountName) {
|
|
exists.loginName = local.accountName;
|
|
hasChanges = true;
|
|
}
|
|
}
|
|
else {
|
|
addingAccounts.add(local.steamId);
|
|
try {
|
|
const profile = await (0, steam_web_1.fetchProfileData)(local.steamId);
|
|
const bans = await (0, steam_web_1.scrapeBanStatus)(profile.profileUrl);
|
|
const localPath = await downloadAvatar(profile.steamId, profile.avatar);
|
|
currentAccounts.push({
|
|
_id: Date.now().toString() + Math.random().toString().slice(2, 5),
|
|
steamId: local.steamId, personaName: profile.personaName || local.accountName,
|
|
loginName: local.accountName, autoCheckCooldown: false, avatar: profile.avatar,
|
|
localAvatar: localPath, profileUrl: profile.profileUrl,
|
|
status: (bans.vacBanned || bans.gameBans > 0) ? 'banned' : 'none',
|
|
vacBanned: bans.vacBanned, gameBans: bans.gameBans, lastBanCheck: new Date().toISOString()
|
|
});
|
|
hasChanges = true;
|
|
}
|
|
catch (e) { }
|
|
addingAccounts.delete(local.steamId);
|
|
}
|
|
}
|
|
if (hasChanges) {
|
|
store.set('accounts', currentAccounts);
|
|
if (mainWindow)
|
|
mainWindow.webContents.send('accounts-updated', currentAccounts);
|
|
updateTrayMenu();
|
|
}
|
|
};
|
|
// --- Main Window Creation ---
|
|
function createWindow() {
|
|
mainWindow = new electron_1.BrowserWindow({
|
|
width: 1280, height: 800, title: "Ultimate Ban Tracker", backgroundColor: '#171a21', autoHideMenuBar: true,
|
|
webPreferences: { preload: path_1.default.join(__dirname, 'preload.js'), nodeIntegration: false, contextIsolation: true }
|
|
});
|
|
mainWindow.setMenu(null);
|
|
mainWindow.on('close', (event) => {
|
|
if (!electron_1.app.isQuitting) {
|
|
event.preventDefault();
|
|
mainWindow?.hide();
|
|
}
|
|
return false;
|
|
});
|
|
if (isDev)
|
|
mainWindow.loadURL('http://localhost:5173');
|
|
else
|
|
mainWindow.loadFile(path_1.default.join(__dirname, '..', 'dist', 'index.html'));
|
|
}
|
|
// --- App Lifecycle ---
|
|
electron_1.app.whenReady().then(() => {
|
|
electron_1.protocol.handle('steam-resource', (request) => {
|
|
let rawPath = decodeURIComponent(request.url.replace('steam-resource://', ''));
|
|
if (process.platform !== 'win32' && !rawPath.startsWith('/'))
|
|
rawPath = '/' + rawPath;
|
|
const absolutePath = path_1.default.isAbsolute(rawPath) ? rawPath : path_1.default.resolve(rawPath);
|
|
if (!fs_1.default.existsSync(absolutePath))
|
|
return new Response('Not Found', { status: 404 });
|
|
try {
|
|
return electron_1.net.fetch((0, url_1.pathToFileURL)(absolutePath).toString());
|
|
}
|
|
catch (e) {
|
|
return new Response('Error', { status: 500 });
|
|
}
|
|
});
|
|
createWindow();
|
|
createTray();
|
|
initBackend();
|
|
setTimeout(syncAccounts, 5000);
|
|
scheduleNextSync();
|
|
steam_client_1.steamClient.startWatching(handleLocalAccountsFound);
|
|
});
|
|
electron_1.app.on('window-all-closed', () => { if (process.platform !== 'darwin' && electron_1.app.isQuitting)
|
|
electron_1.app.quit(); });
|
|
electron_1.app.on('activate', () => { if (electron_1.BrowserWindow.getAllWindows().length === 0)
|
|
createWindow();
|
|
else
|
|
mainWindow?.show(); });
|
|
// --- IPC Handlers ---
|
|
electron_1.ipcMain.handle('get-accounts', () => store.get('accounts'));
|
|
electron_1.ipcMain.handle('get-server-config', () => store.get('serverConfig'));
|
|
electron_1.ipcMain.handle('update-server-config', (event, config) => {
|
|
const current = store.get('serverConfig');
|
|
const updated = { ...current, ...config };
|
|
store.set('serverConfig', updated);
|
|
initBackend();
|
|
return updated;
|
|
});
|
|
electron_1.ipcMain.handle('login-to-server', async () => {
|
|
initBackend();
|
|
const config = store.get('serverConfig');
|
|
if (!config.url)
|
|
return false;
|
|
return new Promise((resolve) => {
|
|
const authWindow = new electron_1.BrowserWindow({
|
|
width: 800, height: 700, parent: mainWindow || undefined, modal: true, title: 'Login to Ban Tracker Server',
|
|
webPreferences: { nodeIntegration: false, contextIsolation: true }
|
|
});
|
|
authWindow.loadURL(`${config.url}/auth/steam`);
|
|
let captured = false;
|
|
const saveServerAuth = (token) => {
|
|
if (captured)
|
|
return;
|
|
captured = true;
|
|
let serverSteamId = undefined;
|
|
try {
|
|
const payload = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString());
|
|
serverSteamId = payload.steamId;
|
|
}
|
|
catch (e) { }
|
|
const current = store.get('serverConfig');
|
|
store.set('serverConfig', { ...current, token, serverSteamId, enabled: true });
|
|
initBackend();
|
|
authWindow.close();
|
|
resolve(true);
|
|
};
|
|
const filter = { urls: [`${config.url}/*`] };
|
|
authWindow.webContents.session.webRequest.onHeadersReceived(filter, (details, callback) => {
|
|
const headers = details.responseHeaders || {};
|
|
const authToken = headers['x-ubt-auth-token']?.[0] || headers['X-UBT-Auth-Token']?.[0];
|
|
if (authToken)
|
|
saveServerAuth(authToken);
|
|
callback({ cancel: false });
|
|
});
|
|
authWindow.on('page-title-updated', (event, title) => {
|
|
if (title.includes('AUTH_TOKEN:')) {
|
|
const token = title.split('AUTH_TOKEN:')[1];
|
|
if (token)
|
|
saveServerAuth(token);
|
|
}
|
|
});
|
|
authWindow.on('closed', () => resolve(false));
|
|
});
|
|
});
|
|
electron_1.ipcMain.handle('get-server-user-info', () => ({ steamId: store.get('serverConfig').serverSteamId }));
|
|
electron_1.ipcMain.handle('sync-now', async () => { await syncAccounts(); return true; });
|
|
electron_1.ipcMain.handle('add-account', async (event, { identifier }) => {
|
|
try {
|
|
initBackend();
|
|
if (backend) {
|
|
const shared = await backend.getCommunityAccounts();
|
|
const existing = shared.find((s) => s.steamId === identifier || s.profileUrl.includes(identifier));
|
|
if (existing) {
|
|
const accounts = store.get('accounts');
|
|
if (accounts.find(a => a.steamId === existing.steamId))
|
|
throw new Error('Account already tracked');
|
|
const newAccount = {
|
|
_id: `shared_${existing.steamId}`, steamId: existing.steamId, personaName: existing.personaName,
|
|
avatar: existing.avatar, profileUrl: existing.profileUrl, vacBanned: existing.vacBanned,
|
|
gameBans: existing.gameBans, cooldownExpiresAt: existing.cooldownExpiresAt,
|
|
loginName: existing.loginName || '', steamLoginSecure: existing.steamLoginSecure,
|
|
loginConfig: existing.loginConfig, sessionUpdatedAt: existing.sessionUpdatedAt,
|
|
autoCheckCooldown: !!existing.steamLoginSecure, status: (existing.vacBanned || existing.gameBans > 0) ? 'banned' : 'none',
|
|
lastBanCheck: new Date().toISOString()
|
|
};
|
|
store.set('accounts', [...accounts, newAccount]);
|
|
updateTrayMenu();
|
|
return newAccount;
|
|
}
|
|
}
|
|
const profile = await (0, steam_web_1.fetchProfileData)(identifier);
|
|
const bans = await (0, steam_web_1.scrapeBanStatus)(profile.profileUrl);
|
|
const localAvatar = await downloadAvatar(profile.steamId, profile.avatar);
|
|
const accounts = store.get('accounts');
|
|
const newAccount = {
|
|
_id: Date.now().toString(), steamId: profile.steamId, personaName: profile.personaName,
|
|
loginName: '', avatar: profile.avatar, localAvatar: localAvatar, profileUrl: profile.profileUrl,
|
|
autoCheckCooldown: false, vacBanned: bans.vacBanned, gameBans: bans.gameBans,
|
|
status: (bans.vacBanned || bans.gameBans > 0) ? 'banned' : 'none', lastBanCheck: new Date().toISOString()
|
|
};
|
|
store.set('accounts', [...accounts, newAccount]);
|
|
updateTrayMenu();
|
|
return newAccount;
|
|
}
|
|
catch (error) {
|
|
throw error;
|
|
}
|
|
});
|
|
electron_1.ipcMain.handle('update-account', (event, id, data) => {
|
|
const accounts = store.get('accounts');
|
|
const index = accounts.findIndex((a) => a._id === id);
|
|
if (index !== -1) {
|
|
accounts[index] = { ...accounts[index], ...data };
|
|
store.set('accounts', accounts);
|
|
updateTrayMenu();
|
|
return accounts[index];
|
|
}
|
|
return null;
|
|
});
|
|
electron_1.ipcMain.handle('delete-account', (event, id) => {
|
|
const accounts = store.get('accounts');
|
|
store.set('accounts', accounts.filter((a) => a._id !== id));
|
|
updateTrayMenu();
|
|
return true;
|
|
});
|
|
electron_1.ipcMain.handle('share-account-with-user', async (event, steamId, targetSteamId) => {
|
|
initBackend();
|
|
if (backend) {
|
|
const accounts = store.get('accounts');
|
|
const account = accounts.find(a => a.steamId === steamId);
|
|
if (account)
|
|
await backend.shareAccount(account);
|
|
return await backend.shareWithUser(steamId, targetSteamId);
|
|
}
|
|
throw new Error('Backend not configured');
|
|
});
|
|
electron_1.ipcMain.handle('revoke-account-access', async (event, steamId, targetSteamId) => {
|
|
initBackend();
|
|
if (backend)
|
|
return await backend.revokeAccess(steamId, targetSteamId);
|
|
throw new Error('Backend not configured');
|
|
});
|
|
electron_1.ipcMain.handle('revoke-all-account-access', async (event, steamId) => {
|
|
initBackend();
|
|
if (backend)
|
|
return await backend.revokeAllAccess(steamId);
|
|
throw new Error('Backend not configured');
|
|
});
|
|
electron_1.ipcMain.handle('get-community-accounts', async () => { initBackend(); return backend ? await backend.getCommunityAccounts() : []; });
|
|
electron_1.ipcMain.handle('get-server-users', async () => { initBackend(); return backend ? await backend.getServerUsers() : []; });
|
|
electron_1.ipcMain.handle('switch-account', async (event, loginName) => await handleSwitchAccount(loginName));
|
|
electron_1.ipcMain.handle('open-external', (event, url) => electron_1.shell.openExternal(url));
|
|
electron_1.ipcMain.handle('open-steam-login', async (event, expectedSteamId) => {
|
|
const loginSession = electron_1.session.fromPartition('persist:steam-login');
|
|
// Removed: automatic clearStorageData to allow cookie persistence
|
|
return new Promise((resolve) => {
|
|
const loginWindow = new electron_1.BrowserWindow({
|
|
width: 800, height: 700, parent: mainWindow || undefined, modal: true, title: 'Login to Steam',
|
|
webPreferences: { nodeIntegration: false, contextIsolation: true, partition: 'persist:steam-login' }
|
|
});
|
|
loginWindow.loadURL('https://steamcommunity.com/login/home/?goto=my/gcpd/730');
|
|
const checkCookie = setInterval(async () => {
|
|
try {
|
|
const cookies = await loginSession.cookies.get({ domain: 'steamcommunity.com' });
|
|
const secureCookie = cookies.find(c => c.name === 'steamLoginSecure');
|
|
if (secureCookie) {
|
|
const steamId = decodeURIComponent(secureCookie.value).split('|')[0];
|
|
if (steamId) {
|
|
if (expectedSteamId && steamId !== expectedSteamId)
|
|
return;
|
|
clearInterval(checkCookie);
|
|
const cookieString = cookies.map(c => `${c.name}=${c.value}`).join('; ');
|
|
const accounts = store.get('accounts');
|
|
const accountIndex = accounts.findIndex(a => a.steamId === steamId);
|
|
if (accountIndex !== -1) {
|
|
const account = accounts[accountIndex];
|
|
account.steamLoginSecure = cookieString;
|
|
account.autoCheckCooldown = true;
|
|
account.authError = false;
|
|
account.sessionUpdatedAt = new Date().toISOString();
|
|
if (account.loginName) {
|
|
const config = steam_client_1.steamClient.extractAccountConfig(account.loginName);
|
|
if (config)
|
|
account.loginConfig = config;
|
|
}
|
|
try {
|
|
const result = await (0, scraper_1.scrapeCooldown)(account.steamId, cookieString);
|
|
account.lastScrapeTime = new Date().toISOString();
|
|
account.cooldownExpiresAt = result.isActive && result.expiresAt ? result.expiresAt.toISOString() : undefined;
|
|
}
|
|
catch (e) { }
|
|
initBackend();
|
|
if (backend)
|
|
await backend.shareAccount(account);
|
|
store.set('accounts', accounts);
|
|
if (mainWindow)
|
|
mainWindow.webContents.send('accounts-updated', accounts);
|
|
updateTrayMenu();
|
|
loginWindow.close();
|
|
resolve(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (error) { }
|
|
}, 1000);
|
|
loginWindow.on('closed', () => { clearInterval(checkCookie); resolve(false); });
|
|
});
|
|
});
|