add clear cookies button
This commit is contained in:
1 parent
000447b77c
commit
da571a645b
8 files changed
+76
No files matched your search
@@ -94,6 +94,14 @@
|
||||
<input type="text" id="upstreamUser" placeholder="optional">
|
||||
<label for="upstreamPass">Password</label>
|
||||
<input type="password" id="upstreamPass" placeholder="optional">
|
||||
<h2>Clear cookies</h2>
|
||||
<div class="clear-cookies-row">
|
||||
<button type="button" class="btn-clear-cookies" data-platform="vk">VK</button>
|
||||
<button type="button" class="btn-clear-cookies" data-platform="telemost">Telemost</button>
|
||||
<button type="button" class="btn-clear-cookies" data-platform="wbstream">WBStream</button>
|
||||
<button type="button" class="btn-clear-cookies" data-platform="dion">DION</button>
|
||||
</div>
|
||||
<div class="clear-cookies-status" id="clearCookiesStatus"></div>
|
||||
<div class="popup-buttons">
|
||||
<button class="btn-cancel" id="btnSettingsCancel">Cancel</button>
|
||||
<button class="btn-save" id="btnSettingsSave">Save</button>
|
||||
|
||||
@@ -59,6 +59,7 @@ export enum IPC {
|
||||
START_BOT = 'start-bot',
|
||||
STOP_BOT = 'stop-bot',
|
||||
SET_UPSTREAM_PROXY = 'set-upstream-proxy',
|
||||
CLEAR_COOKIES = 'clear-cookies',
|
||||
EXPORT_COOKIES_ZIP = 'export-cookies-zip',
|
||||
RELAY_LOG = 'relay-log',
|
||||
CREATE_BOT_TAB = 'create-bot-tab',
|
||||
|
||||
@@ -90,6 +90,10 @@ export function registerIpcHandlers(tabManager: TabManager): void {
|
||||
tabManager.setUpstreamProxy(proxy);
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC.CLEAR_COOKIES, (_e, platform: string) => {
|
||||
return tabManager.clearPlatformCookies(platform as Platform);
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC.SEND_BOT_CALL_LINK, (_e, tabId: string, link: string) => {
|
||||
tabManager.sendBotCallLink(tabId, link);
|
||||
});
|
||||
|
||||
@@ -410,6 +410,28 @@ export class TabManager {
|
||||
}
|
||||
}
|
||||
|
||||
async clearPlatformCookies(platform: Platform): Promise<number> {
|
||||
const config = this.headlessConfig(platform);
|
||||
if (!config) return 0;
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const all = await ses.cookies.get({});
|
||||
let removed = 0;
|
||||
for (const cookie of all) {
|
||||
if (!cookie.domain || !config.cookieDomains.some((d) => cookie.domain!.includes(d))) continue;
|
||||
const host = cookie.domain.startsWith('.') ? cookie.domain.slice(1) : cookie.domain;
|
||||
const url = `https://${host}${cookie.path || '/'}`;
|
||||
try {
|
||||
await ses.cookies.remove(url, cookie.name);
|
||||
removed++;
|
||||
} catch (err) {
|
||||
console.log(`[COOKIES] failed to remove ${cookie.name} on ${url}:`, err);
|
||||
}
|
||||
}
|
||||
await fs.unlink(path.join(app.getPath('userData'), `cookies-${platform}.json`)).catch(() => {});
|
||||
console.log(`[COOKIES] cleared ${removed} cookies for ${platform}`);
|
||||
return removed;
|
||||
}
|
||||
|
||||
private waitForLogin(cookieDomains: string[], authCookieName: string): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
|
||||
@@ -26,6 +26,9 @@ import { IPC } from '../constants';
|
||||
setUpstreamProxy(proxy: any) {
|
||||
return ipcRenderer.invoke(IPC.SET_UPSTREAM_PROXY, proxy);
|
||||
},
|
||||
clearCookies(platform: string) {
|
||||
return ipcRenderer.invoke(IPC.CLEAR_COOKIES, platform);
|
||||
},
|
||||
onCreateBotTab(cb: (data: any) => void) {
|
||||
ipcRenderer.on(IPC.CREATE_BOT_TAB, (_e, data) => cb(data));
|
||||
},
|
||||
|
||||
@@ -91,6 +91,19 @@ function bindSettingsEvents(): void {
|
||||
tm.saveUpstreamProxy();
|
||||
closeSettings();
|
||||
});
|
||||
document.querySelectorAll('.btn-clear-cookies').forEach((btn) => {
|
||||
btn.addEventListener('click', async () => {
|
||||
const platform = (btn as HTMLElement).dataset.platform!;
|
||||
const status = document.getElementById('clearCookiesStatus')!;
|
||||
status.textContent = `Clearing ${platform} cookies...`;
|
||||
try {
|
||||
const removed = await window.bridge.clearCookies(platform);
|
||||
status.textContent = `Cleared ${removed} ${platform} cookies. Log in again to use it.`;
|
||||
} catch {
|
||||
status.textContent = `Failed to clear ${platform} cookies.`;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function bindErrorPopup(): void {
|
||||
@@ -161,6 +174,7 @@ function openSettings(): void {
|
||||
(document.getElementById('upstreamSocks') as HTMLInputElement).value = tm.upstreamProxy.socks;
|
||||
(document.getElementById('upstreamUser') as HTMLInputElement).value = tm.upstreamProxy.user;
|
||||
(document.getElementById('upstreamPass') as HTMLInputElement).value = tm.upstreamProxy.pass;
|
||||
document.getElementById('clearCookiesStatus')!.textContent = '';
|
||||
}
|
||||
|
||||
function closeSettings(): void {
|
||||
|
||||
@@ -151,6 +151,7 @@ export interface Bridge {
|
||||
startBot(settings: BotSettings): Promise<void>;
|
||||
stopBot(): Promise<void>;
|
||||
setUpstreamProxy(proxy: UpstreamProxy): Promise<void>;
|
||||
clearCookies(platform: string): Promise<number>;
|
||||
onCreateBotTab(cb: (data: BotTabData) => void): void;
|
||||
getCallCreatorCode(scriptFile: string): Promise<string>;
|
||||
onBotError(cb: (msg: string) => void): void;
|
||||
|
||||
@@ -573,6 +573,29 @@ body {
|
||||
color: #e0e0e0;
|
||||
}
|
||||
|
||||
.clear-cookies-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.btn-clear-cookies {
|
||||
background: #444;
|
||||
color: #e0e0e0;
|
||||
}
|
||||
|
||||
.btn-clear-cookies:hover {
|
||||
background: #5a3030;
|
||||
color: #ffb3b3;
|
||||
}
|
||||
|
||||
.clear-cookies-status {
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
color: #9aa0a6;
|
||||
min-height: 14px;
|
||||
}
|
||||
|
||||
.error-title {
|
||||
color: #dc3545;
|
||||
margin-bottom: 12px;
|
||||
|
||||
Reference in new issue
Block a user