Skip to content

Commit

Permalink
chore: upgrade electron to newer version and fix external link crashes (
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdicarlo authored Oct 4, 2024
1 parent b15125f commit 6b71908
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ function LoginPanel(props: Omit<WebsiteLoginPanelProps, 'onClose'>) {
}

return (
// eslint-disable-next-line lingui/no-unlocalized-strings
<Box h="calc(100% - 34px)" p="sm">
<Box h="calc(100% - 50px)" p="sm">
{loginMethod}
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function PostyBirbLayout() {
breakpoint: 'sm',
}}
>
<AppShell.Navbar id="postybirb__navbar">
<AppShell.Navbar id="postybirb__navbar" zIndex={1000}>
<AppShell.Section>
<Box ta="center" p="5">
<AppImage />
Expand Down
24 changes: 24 additions & 0 deletions apps/postybirb-ui/src/components/external-link/external-link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Anchor } from '@mantine/core';
import { AnchorHTMLAttributes, PropsWithChildren } from 'react';

export function ExternalLink(
props: PropsWithChildren<
Omit<AnchorHTMLAttributes<HTMLAnchorElement>, 'target' | 'onClick'>
>
) {
return (
<Anchor
{...props}
target="_blank"
c="blue"
onClick={(event) => {
if (window.electron?.openExternalLink) {
event.preventDefault();
window.electron.openExternalLink(
(event.target as HTMLAnchorElement).href
);
}
}}
/>
);
}
1 change: 1 addition & 0 deletions apps/postybirb-ui/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ declare global {
electron: {
getAppVersion(): Promise<string>;
pickDirectory?(): Promise<string | undefined>;
openExternalLink(url: string): void;
platform: string;
app_port: string;
app_version: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -85,11 +86,11 @@ export default function DiscordLoginView(
isWebhookValid === false ? <Trans>Webhook is required</Trans> : null
}
description={
<a href="https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks">
<ExternalLink href="https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks">
<Trans context="discord.webhook-help">
How to create a webhook
</Trans>
</a>
</ExternalLink>
}
onChange={(event) => {
setWebhook(event.currentTarget.value);
Expand Down
2 changes: 2 additions & 0 deletions apps/postybirb/src/app/api/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 0 additions & 18 deletions apps/postybirb/src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
BrowserWindow,
Menu,
Tray,
WebContentsWillNavigateEventParams,
app,
globalShortcut,
nativeImage,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion apps/postybirb/src/app/events/electron.events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -31,6 +31,10 @@ ipcMain.handle('pick-directory', async (): Promise<string | undefined> => {
return undefined;
});

ipcMain.on('open-external-link', (event, url) => {
shell.openExternal(url);
});

// Handle App termination
ipcMain.on('quit', (event, code) => {
app.exit(code);
Expand Down
6 changes: 3 additions & 3 deletions lang/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down Expand Up @@ -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 ""

Expand Down Expand Up @@ -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 ""

Expand Down
6 changes: 3 additions & 3 deletions lang/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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 ""

Expand Down
6 changes: 3 additions & 3 deletions lang/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 "Сохранить"

Expand Down Expand Up @@ -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 ""

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
58 changes: 23 additions & 35 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 6b71908

Please sign in to comment.