From 6b719083559f54a6a374af1b7ac9292f03aabb62 Mon Sep 17 00:00:00 2001 From: Lemonynade Date: Fri, 4 Oct 2024 07:38:23 -0400 Subject: [PATCH] chore: upgrade electron to newer version and fix external link crashes (#297) --- .../website-login-panel.tsx | 3 +- .../app/postybirb-layout/postybirb-layout.tsx | 2 +- .../external-link/external-link.tsx | 24 ++++++++ apps/postybirb-ui/src/main.tsx | 1 + .../discord/discord-login-view.tsx | 5 +- apps/postybirb/src/app/api/preload.ts | 2 + apps/postybirb/src/app/app.ts | 18 ------ .../src/app/events/electron.events.ts | 6 +- lang/en.po | 6 +- lang/es.po | 6 +- lang/ru.po | 6 +- package.json | 5 +- yarn.lock | 58 ++++++++----------- 13 files changed, 72 insertions(+), 70 deletions(-) create mode 100644 apps/postybirb-ui/src/components/external-link/external-link.tsx diff --git a/apps/postybirb-ui/src/app/postybirb-layout/drawers/account-drawer/website-login-panel/website-login-panel.tsx b/apps/postybirb-ui/src/app/postybirb-layout/drawers/account-drawer/website-login-panel/website-login-panel.tsx index e3d715ba9..72307a0d5 100644 --- a/apps/postybirb-ui/src/app/postybirb-layout/drawers/account-drawer/website-login-panel/website-login-panel.tsx +++ b/apps/postybirb-ui/src/app/postybirb-layout/drawers/account-drawer/website-login-panel/website-login-panel.tsx @@ -35,8 +35,7 @@ function LoginPanel(props: Omit) { } return ( - // eslint-disable-next-line lingui/no-unlocalized-strings - + {loginMethod} ); diff --git a/apps/postybirb-ui/src/app/postybirb-layout/postybirb-layout.tsx b/apps/postybirb-ui/src/app/postybirb-layout/postybirb-layout.tsx index 8f6ac647f..ba1a35503 100644 --- a/apps/postybirb-ui/src/app/postybirb-layout/postybirb-layout.tsx +++ b/apps/postybirb-ui/src/app/postybirb-layout/postybirb-layout.tsx @@ -117,7 +117,7 @@ export function PostyBirbLayout() { breakpoint: 'sm', }} > - + diff --git a/apps/postybirb-ui/src/components/external-link/external-link.tsx b/apps/postybirb-ui/src/components/external-link/external-link.tsx new file mode 100644 index 000000000..3d57479a7 --- /dev/null +++ b/apps/postybirb-ui/src/components/external-link/external-link.tsx @@ -0,0 +1,24 @@ +import { Anchor } from '@mantine/core'; +import { AnchorHTMLAttributes, PropsWithChildren } from 'react'; + +export function ExternalLink( + props: PropsWithChildren< + Omit, 'target' | 'onClick'> + > +) { + return ( + { + if (window.electron?.openExternalLink) { + event.preventDefault(); + window.electron.openExternalLink( + (event.target as HTMLAnchorElement).href + ); + } + }} + /> + ); +} diff --git a/apps/postybirb-ui/src/main.tsx b/apps/postybirb-ui/src/main.tsx index b8c87b234..a37fac7b6 100644 --- a/apps/postybirb-ui/src/main.tsx +++ b/apps/postybirb-ui/src/main.tsx @@ -59,6 +59,7 @@ declare global { electron: { getAppVersion(): Promise; pickDirectory?(): Promise; + openExternalLink(url: string): void; platform: string; app_port: string; app_version: string; diff --git a/apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx b/apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx index 3743f16f3..1ecb51e63 100644 --- a/apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx +++ b/apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx @@ -3,6 +3,7 @@ import { Box, Button, Stack, TextInput } from '@mantine/core'; import { notifications } from '@mantine/notifications'; import { useState } from 'react'; import accountApi from '../../api/account.api'; +import { ExternalLink } from '../../components/external-link/external-link'; import HttpErrorResponse from '../../models/http-error-response'; import { LoginComponentProps } from '../../models/login-component-props'; @@ -85,11 +86,11 @@ export default function DiscordLoginView( isWebhookValid === false ? Webhook is required : null } description={ - + How to create a webhook - + } onChange={(event) => { setWebhook(event.currentTarget.value); diff --git a/apps/postybirb/src/app/api/preload.ts b/apps/postybirb/src/app/api/preload.ts index e30eb8f66..578bcdb0e 100644 --- a/apps/postybirb/src/app/api/preload.ts +++ b/apps/postybirb/src/app/api/preload.ts @@ -3,6 +3,8 @@ import { contextBridge, ipcRenderer } from 'electron'; contextBridge.exposeInMainWorld('electron', { getAppVersion: () => ipcRenderer.invoke('get-app-version'), pickDirectory: () => ipcRenderer.invoke('pick-directory'), + openExternalLink: (url: string) => + ipcRenderer.send('open-external-link', url), platform: process.platform, app_port: process.env.POSTYBIRB_PORT, app_version: process.env.POSTYBIRB_VERSION, diff --git a/apps/postybirb/src/app/app.ts b/apps/postybirb/src/app/app.ts index 9ab8c11b8..11080902c 100644 --- a/apps/postybirb/src/app/app.ts +++ b/apps/postybirb/src/app/app.ts @@ -11,7 +11,6 @@ import { BrowserWindow, Menu, Tray, - WebContentsWillNavigateEventParams, app, globalShortcut, nativeImage, @@ -61,19 +60,6 @@ export default class PostyBirb { PostyBirb.mainWindow = null; } - private static onRedirect( - details: WebContentsWillNavigateEventParams & { - preventDefault: () => void; - } - ) { - const { url, preventDefault } = details; - // if (url !== PostyBirb.mainWindow.webContents.getURL()) { - // // this is a normal external redirect, open it in a new browser window - // preventDefault(); // !BUG - causes a crash in current electron version - // shell.openExternal(url); - // } - } - private static onReady() { // This method will be called when Electron has finished // initialization and is ready to create browser windows. @@ -135,10 +121,6 @@ export default class PostyBirb { PostyBirb.mainWindow.on('closed', () => { PostyBirb.onClose(); }); - - PostyBirb.mainWindow.webContents.on('will-navigate', (details) => { - PostyBirb.onRedirect(details); - }); } private static loadMainWindow() { diff --git a/apps/postybirb/src/app/events/electron.events.ts b/apps/postybirb/src/app/events/electron.events.ts index 12be30908..137e39d23 100644 --- a/apps/postybirb/src/app/events/electron.events.ts +++ b/apps/postybirb/src/app/events/electron.events.ts @@ -3,7 +3,7 @@ * between the frontend to the electron backend. */ -import { app, ipcMain, dialog } from 'electron'; +import { app, dialog, ipcMain, shell } from 'electron'; import { environment } from '../../environments/environment'; export default class ElectronEvents { @@ -31,6 +31,10 @@ ipcMain.handle('pick-directory', async (): Promise => { return undefined; }); +ipcMain.on('open-external-link', (event, url) => { + shell.openExternal(url); +}); + // Handle App termination ipcMain.on('quit', (event, code) => { app.exit(code); diff --git a/lang/en.po b/lang/en.po index 1aa998633..c3eb1a790 100644 --- a/lang/en.po +++ b/lang/en.po @@ -291,7 +291,7 @@ msgstr "" msgid "Hours" msgstr "" -#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:89 +#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:90 msgctxt "discord.webhook-help" msgid "How to create a webhook" msgstr "" @@ -450,7 +450,7 @@ msgstr "" #: apps/postybirb-ui/src/app/postybirb-layout/drawers/tag-converter-drawer.tsx:190 #: apps/postybirb-ui/src/app/postybirb-layout/drawers/tag-group-drawer.tsx:171 #: apps/postybirb-ui/src/components/form/user-specified-website-options-modal/user-specified-website-options-modal.tsx:96 -#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:105 +#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:106 msgid "Save" msgstr "" @@ -665,7 +665,7 @@ msgstr "" msgid "Use custom description" msgstr "" -#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:85 +#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:86 msgid "Webhook is required" msgstr "" diff --git a/lang/es.po b/lang/es.po index e631c561d..51a20a330 100644 --- a/lang/es.po +++ b/lang/es.po @@ -289,7 +289,7 @@ msgstr "" msgid "Hours" msgstr "" -#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:89 +#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:90 msgctxt "discord.webhook-help" msgid "How to create a webhook" msgstr "Cómo crear un webhook" @@ -448,7 +448,7 @@ msgstr "Ruso" #: apps/postybirb-ui/src/app/postybirb-layout/drawers/tag-converter-drawer.tsx:190 #: apps/postybirb-ui/src/app/postybirb-layout/drawers/tag-group-drawer.tsx:171 #: apps/postybirb-ui/src/components/form/user-specified-website-options-modal/user-specified-website-options-modal.tsx:96 -#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:105 +#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:106 msgid "Save" msgstr "Guardar" @@ -663,7 +663,7 @@ msgstr "" msgid "Use custom description" msgstr "" -#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:85 +#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:86 msgid "Webhook is required" msgstr "" diff --git a/lang/ru.po b/lang/ru.po index 8ff7b2e99..b70a9e1f6 100644 --- a/lang/ru.po +++ b/lang/ru.po @@ -289,7 +289,7 @@ msgstr "" msgid "Hours" msgstr "" -#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:89 +#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:90 msgctxt "discord.webhook-help" msgid "How to create a webhook" msgstr "Как создать webhook" @@ -448,7 +448,7 @@ msgstr "Русский" #: apps/postybirb-ui/src/app/postybirb-layout/drawers/tag-converter-drawer.tsx:190 #: apps/postybirb-ui/src/app/postybirb-layout/drawers/tag-group-drawer.tsx:171 #: apps/postybirb-ui/src/components/form/user-specified-website-options-modal/user-specified-website-options-modal.tsx:96 -#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:105 +#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:106 msgid "Save" msgstr "Сохранить" @@ -663,7 +663,7 @@ msgstr "" msgid "Use custom description" msgstr "" -#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:85 +#: apps/postybirb-ui/src/website-components/discord/discord-login-view.tsx:86 msgid "Webhook is required" msgstr "" diff --git a/package.json b/package.json index 9dfa7b651..594a4bd11 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "dayjs": "^1.11.13", "document-register-element": "1.13.1", "electron-context-menu": "^3.1.1", - "electron-updater": "^6.1.4", + "electron-updater": "^6.3.9", "express": "^4.21.0", "fastq": "^1.17.1", "filesize": "^10.1.6", @@ -171,7 +171,8 @@ "babel-plugin-macros": "^3.1.0", "cypress": "^7.3.0", "dotenv": "10.0.0", - "electron": "^26", + "electron": "^32", + "electron-builder": "^24.13.3", "eslint": "8.48.0", "eslint-config-airbnb": "^19.0.4", "eslint-config-airbnb-typescript": "^17.1.0", diff --git a/yarn.lock b/yarn.lock index 16071396d..004ad3578 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4876,13 +4876,6 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-14.18.63.tgz#1788fa8da838dbb5f9ea994b834278205db6ca2b" integrity sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ== -"@types/node@^18.11.18": - version "18.19.54" - resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.54.tgz#f1048dc083f81b242640f04f18fb3e4ccf13fcdb" - integrity sha512-+BRgt0G5gYjTvdLac9sIeE0iZcJxi4Jc4PV5EUzqi+88jmQLr+fRZdv2tCTV7IHKSGxM6SaLoOXQWWUiLUItMw== - dependencies: - undici-types "~5.26.4" - "@types/node@^20.16.10", "@types/node@^20.9.0": version "20.16.10" resolved "https://registry.yarnpkg.com/@types/node/-/node-20.16.10.tgz#0cc3fdd3daf114a4776f54ba19726a01c907ef71" @@ -6473,18 +6466,18 @@ buffer@^6.0.3: base64-js "^1.3.1" ieee754 "^1.2.1" -builder-util-runtime@9.2.4: - version "9.2.4" - resolved "https://registry.yarnpkg.com/builder-util-runtime/-/builder-util-runtime-9.2.4.tgz#13cd1763da621e53458739a1e63f7fcba673c42a" - integrity sha512-upp+biKpN/XZMLim7aguUyW8s0FUpDvOtK6sbanMFDAMBzpHDqdhgVYm6zc9HJ6nWo7u2Lxk60i2M6Jd3aiNrA== +builder-util-runtime@9.2.10: + version "9.2.10" + resolved "https://registry.yarnpkg.com/builder-util-runtime/-/builder-util-runtime-9.2.10.tgz#a0f7d9e214158402e78b74a745c8d9f870c604bc" + integrity sha512-6p/gfG1RJSQeIbz8TK5aPNkoztgY1q5TgmGFMAXcY8itsGW6Y2ld1ALsZ5UJn8rog7hKF3zHx5iQbNQ8uLcRlw== dependencies: debug "^4.3.4" sax "^1.2.4" -builder-util-runtime@9.2.5: - version "9.2.5" - resolved "https://registry.yarnpkg.com/builder-util-runtime/-/builder-util-runtime-9.2.5.tgz#0afdffa0adb5c84c14926c7dd2cf3c6e96e9be83" - integrity sha512-HjIDfhvqx/8B3TDN4GbABQcgpewTU4LMRTQPkVpKYV3lsuxEJoIfvg09GyWTNmfVNSUAYf+fbTN//JX4TH20pg== +builder-util-runtime@9.2.4: + version "9.2.4" + resolved "https://registry.yarnpkg.com/builder-util-runtime/-/builder-util-runtime-9.2.4.tgz#13cd1763da621e53458739a1e63f7fcba673c42a" + integrity sha512-upp+biKpN/XZMLim7aguUyW8s0FUpDvOtK6sbanMFDAMBzpHDqdhgVYm6zc9HJ6nWo7u2Lxk60i2M6Jd3aiNrA== dependencies: debug "^4.3.4" sax "^1.2.4" @@ -8133,7 +8126,7 @@ ejs@^3.1.7, ejs@^3.1.8: dependencies: jake "^10.8.5" -electron-builder@^24.6.3: +electron-builder@^24.13.3, electron-builder@^24.6.3: version "24.13.3" resolved "https://registry.yarnpkg.com/electron-builder/-/electron-builder-24.13.3.tgz#c506dfebd36d9a50a83ee8aa32d803d83dbe4616" integrity sha512-yZSgVHft5dNVlo31qmJAe4BVKQfFdwpRw7sFp1iQglDRCDD6r22zfRJuZlhtB5gp9FHUxCMEoWGq10SkCnMAIg== @@ -8191,12 +8184,12 @@ electron-to-chromium@^1.5.28: resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.31.tgz#b1478418769dec72ea70d9fdf147a81491857f10" integrity sha512-QcDoBbQeYt0+3CWcK/rEbuHvwpbT/8SV9T3OSgs6cX1FlcUAkgrkqbg9zLnDrMM/rLamzQwal4LYFCiWk861Tg== -electron-updater@^6.1.4: - version "6.3.4" - resolved "https://registry.yarnpkg.com/electron-updater/-/electron-updater-6.3.4.tgz#3934bc89875bb524c2cbbd11041114e97c0c2496" - integrity sha512-uZUo7p1Y53G4tl6Cgw07X1yF8Jlz6zhaL7CQJDZ1fVVkOaBfE2cWtx80avwDVi8jHp+I/FWawrMgTAeCCNIfAg== +electron-updater@^6.3.9: + version "6.3.9" + resolved "https://registry.yarnpkg.com/electron-updater/-/electron-updater-6.3.9.tgz#e1e7f155624c58e6f3760f376c3a584028165ec4" + integrity sha512-2PJNONi+iBidkoC5D1nzT9XqsE8Q1X28Fn6xRQhO3YX8qRRyJ3mkV4F1aQsuRnYPqq6Hw+E51y27W75WgDoofw== dependencies: - builder-util-runtime "9.2.5" + builder-util-runtime "9.2.10" fs-extra "^10.1.0" js-yaml "^4.1.0" lazy-val "^1.0.5" @@ -8205,15 +8198,6 @@ electron-updater@^6.1.4: semver "^7.6.3" tiny-typed-emitter "^2.1.0" -electron@^26: - version "26.6.10" - resolved "https://registry.yarnpkg.com/electron/-/electron-26.6.10.tgz#01ca7610bd662033ed3ceb70804cbf940c7e6756" - integrity sha512-pV2SD0RXzAiNRb/2yZrsVmVkBOMrf+DVsPulIgRjlL0+My9BL5spFuhHVMQO9yHl9tFpWtuRpQv0ofM/i9P8xg== - dependencies: - "@electron/get" "^2.0.0" - "@types/node" "^18.11.18" - extract-zip "^2.0.1" - electron@^31.0.1: version "31.6.0" resolved "https://registry.yarnpkg.com/electron/-/electron-31.6.0.tgz#625809a2dfad1dbabcc04552b35f313fc238fd69" @@ -8223,6 +8207,15 @@ electron@^31.0.1: "@types/node" "^20.9.0" extract-zip "^2.0.1" +electron@^32: + version "32.1.2" + resolved "https://registry.yarnpkg.com/electron/-/electron-32.1.2.tgz#84d1efd95d41224e58a6a9bbd1db4ba80154fc02" + integrity sha512-CXe6doFzhmh1U7daOvUzmF6Cj8hssdYWMeEPRnRO6rB9/bbwMlWctcQ7P8NJXhLQ88/vYUJQrJvlJPh8qM0BRQ== + dependencies: + "@electron/get" "^2.0.0" + "@types/node" "^20.9.0" + extract-zip "^2.0.1" + emittery@^0.13.1: version "0.13.1" resolved "https://registry.yarnpkg.com/emittery/-/emittery-0.13.1.tgz#c04b8c3457490e0847ae51fced3af52d338e3dad" @@ -17087,11 +17080,6 @@ unbox-primitive@^1.0.2: has-symbols "^1.0.3" which-boxed-primitive "^1.0.2" -undici-types@~5.26.4: - version "5.26.5" - resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" - integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== - undici-types@~6.19.2: version "6.19.8" resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02"