diff --git a/browser/App.vue b/browser/App.vue index fd521821..b11e835a 100644 --- a/browser/App.vue +++ b/browser/App.vue @@ -30,7 +30,7 @@ watchImmediate(currentScreen, async (name) => { whenever(isDeimosReady, async () => { if (gameOriginRegex.test(location.origin)) { const responseTime = await Deimos.invoke('get-response-time'); - ipcSend('update-response-time', responseTime); + ipcSend('browser:update-response-time', responseTime); aresStore.responseTime = responseTime; }; }); diff --git a/browser/components/TheCaptchaObserver.vue b/browser/components/TheCaptchaObserver.vue index ad37f299..d40e0ee7 100644 --- a/browser/components/TheCaptchaObserver.vue +++ b/browser/components/TheCaptchaObserver.vue @@ -12,7 +12,7 @@ const aresStore = useAresStore(); const { captcha } = storeToRefs(aresStore); captcha.value = thereIsBotCheck(); -watchSyncEffect(() => ipcSend('update-captcha-status', captcha.value)); +watchSyncEffect(() => ipcSend('captcha:update-status', captcha.value)); const content = ref(document.querySelector('table#contentContainer')); const options: UseMutationObserverOptions = { diff --git a/browser/events/plunder/index.ts b/browser/events/plunder/index.ts index 2f083b4e..ebb5ade1 100644 --- a/browser/events/plunder/index.ts +++ b/browser/events/plunder/index.ts @@ -1,7 +1,13 @@ +import { ipcRenderer } from 'electron'; +import { usePlunderConfigStore } from '$renderer/stores/plunder'; import { setPlunderConfigEvents } from '$browser/events/plunder/config'; import { setPlunderNavigationEvents } from '$browser/events/plunder/navigation'; export function setPlunderEvents() { setPlunderConfigEvents(); setPlunderNavigationEvents(); + + const plunderConfigStore = usePlunderConfigStore(); + + ipcRenderer.on('plunder:stop', () => (plunderConfigStore.active = false)); }; \ No newline at end of file diff --git a/electron/events/browser.ts b/electron/events/browser.ts deleted file mode 100644 index 67f6a2ec..00000000 --- a/electron/events/browser.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ipcMain } from 'electron'; -import { useAresStore } from '$electron/interface'; -import { getPanelWindow, getMainWindow } from '$electron/utils/helpers'; - -export function setBrowserEvents() { - const mainWindow = getMainWindow(); - const panelWindow = getPanelWindow(); - const aresStore = useAresStore(); - - ipcMain.on('update-captcha-status', (_e, status: boolean) => { - aresStore.captcha = status; - panelWindow.webContents.send('captcha-status-did-update', status); - }); - - ipcMain.handle('get-response-time', () => aresStore.responseTime); - - ipcMain.on('update-response-time', (_e, time: number) => { - aresStore.responseTime = time; - mainWindow.webContents.send('response-time-did-update', time); - }); -}; \ No newline at end of file diff --git a/electron/events/browser/captcha.ts b/electron/events/browser/captcha.ts new file mode 100644 index 00000000..b8f16d5c --- /dev/null +++ b/electron/events/browser/captcha.ts @@ -0,0 +1,38 @@ +import { ipcMain, webContents } from 'electron'; +import { storeToRefs, watch } from 'mechanus'; +import { isUserAlias } from '$global/guards'; +import { MainProcessEventError } from '$electron/error'; +import { useAresStore, useCacheStore, usePlunderHistoryStore, PlunderHistory } from '$electron/interface'; + +export function setCaptchaEvents() { + const aresStore = useAresStore(); + const { captcha } = storeToRefs(aresStore); + + const cacheStore = useCacheStore(); + const plunderHistoryStore = usePlunderHistoryStore(); + + ipcMain.on('captcha:update-status', (e, status: boolean) => { + captcha.value = status; + for (const contents of webContents.getAllWebContents()) { + if (contents !== e.sender) { + contents.send('captcha:status-did-update', status); + }; + }; + }); + + watch(captcha, async (status) => { + try { + if (!status) return; + for (const contents of webContents.getAllWebContents()) { + contents.send('plunder:stop'); + }; + + if (isUserAlias(cacheStore.userAlias)) { + await PlunderHistory.saveHistory(cacheStore.userAlias, plunderHistoryStore); + }; + + } catch (err) { + MainProcessEventError.catch(err); + }; + }); +}; \ No newline at end of file diff --git a/electron/events/browser/index.ts b/electron/events/browser/index.ts new file mode 100644 index 00000000..f2f7bfe7 --- /dev/null +++ b/electron/events/browser/index.ts @@ -0,0 +1,18 @@ +import { ipcMain } from 'electron'; +import { useAresStore } from '$electron/interface'; +import { getMainWindow } from '$electron/utils/helpers'; +import { setCaptchaEvents } from '$electron/events/browser/captcha'; + +export function setBrowserEvents() { + const mainWindow = getMainWindow(); + const aresStore = useAresStore(); + + ipcMain.handle('browser:get-response-time', () => aresStore.responseTime); + + ipcMain.on('browser:update-response-time', (_e, time: number) => { + aresStore.responseTime = time; + mainWindow.webContents.send('response-time-did-update', time); + }); + + setCaptchaEvents(); +}; \ No newline at end of file diff --git a/panel/events/index.ts b/panel/events/index.ts index 2714c5b0..fbff8142 100644 --- a/panel/events/index.ts +++ b/panel/events/index.ts @@ -18,12 +18,12 @@ export function setPanelEvents() { const unitStore = useUnitsStore(); const groupsStore = useGroupsStore(); - ipcRenderer.on('panel:visibility-did-change', (_e, isVisible: boolean) => { - panelStore.isVisible = isVisible; + ipcRenderer.on('captcha:status-did-update', (_e, thereIsCaptcha: boolean) => { + aresStore.captcha = thereIsCaptcha; }); - ipcRenderer.on('captcha-status-did-update', (_e, thereIsCaptcha: boolean) => { - aresStore.captcha = thereIsCaptcha; + ipcRenderer.on('panel:visibility-did-change', (_e, isVisible: boolean) => { + panelStore.isVisible = isVisible; }); ipcRenderer.on('panel:patch-game-data', (_e, data: TribalWarsGameDataType) => { diff --git a/panel/events/plunder.ts b/panel/events/plunder.ts index 96b73184..eaa0ff57 100644 --- a/panel/events/plunder.ts +++ b/panel/events/plunder.ts @@ -9,6 +9,8 @@ export function setPlunderEvents() { const plunderConfigStore = usePlunderConfigStore(); const plunderHistoryStore = usePlunderHistoryStore(); + ipcRenderer.on('plunder:stop', () => (plunderConfigStore.active = false)); + // Atualiza o estado local do Plunder sempre que ocorre uma mudança. ipcRenderer.on('plunder:config-updated', ( _e: unknown, key: T, value: typeof plunderConfigStore[T] diff --git a/panel/views/CaptchaView.vue b/panel/views/CaptchaView.vue index aac4b7c0..005a44ce 100644 --- a/panel/views/CaptchaView.vue +++ b/panel/views/CaptchaView.vue @@ -1,23 +1,5 @@