From 497bb0e2cbefad3e9a1188ee5df49cf61f6bd6e4 Mon Sep 17 00:00:00 2001 From: Akis Kesoglou Date: Thu, 6 Jul 2023 21:39:53 +0300 Subject: [PATCH 1/3] Fix opening links from within SafeWebView Change-type: patch --- .../components/safe-webview/safe-webview.tsx | 33 +++++++++---------- lib/gui/etcher.ts | 18 ++++++++++ 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/lib/gui/app/components/safe-webview/safe-webview.tsx b/lib/gui/app/components/safe-webview/safe-webview.tsx index c47ae170..62b08d78 100644 --- a/lib/gui/app/components/safe-webview/safe-webview.tsx +++ b/lib/gui/app/components/safe-webview/safe-webview.tsx @@ -95,6 +95,7 @@ export class SafeWebview extends React.PureComponent< ); this.entryHref = url.href; // Events steal 'this' + this.handleDomReady = _.bind(this.handleDomReady, this); this.didFailLoad = _.bind(this.didFailLoad, this); this.didGetResponseDetails = _.bind(this.didGetResponseDetails, this); // Make a persistent electron session for the webview @@ -121,6 +122,8 @@ export class SafeWebview extends React.PureComponent< ref={this.webviewRef} partition={ELECTRON_SESSION} style={style} + // @ts-ignore + allowpopups="true" /> ); } @@ -134,8 +137,8 @@ export class SafeWebview extends React.PureComponent< this.didFailLoad, ); this.webviewRef.current.addEventListener( - 'new-window', - SafeWebview.newWindow, + 'dom-ready', + this.handleDomReady, ); this.webviewRef.current.addEventListener( 'console-message', @@ -157,8 +160,8 @@ export class SafeWebview extends React.PureComponent< this.didFailLoad, ); this.webviewRef.current.removeEventListener( - 'new-window', - SafeWebview.newWindow, + 'dom-ready', + this.handleDomReady, ); this.webviewRef.current.removeEventListener( 'console-message', @@ -168,6 +171,15 @@ export class SafeWebview extends React.PureComponent< this.session.webRequest.onCompleted(null); } + handleDomReady() { + const webview = this.webviewRef.current; + if (webview == null) { + return; + } + const id = webview.getWebContentsId(); + electron.ipcRenderer.send('webview-dom-ready', id); + } + // Set the element state to hidden public didFailLoad() { this.setState({ @@ -196,17 +208,4 @@ export class SafeWebview extends React.PureComponent< } } } - - // Open link in browser if it's opened as a 'foreground-tab' - public static async newWindow(event: electron.NewWindowEvent) { - const url = new window.URL(event.url); - if ( - (url.protocol === 'http:' || url.protocol === 'https:') && - event.disposition === 'foreground-tab' && - // Don't open links if they're disabled by the env var - !(await settings.get('disableExternalLinks')) - ) { - electron.shell.openExternal(url.href); - } - } } diff --git a/lib/gui/etcher.ts b/lib/gui/etcher.ts index 13ed23d2..104f6858 100644 --- a/lib/gui/etcher.ts +++ b/lib/gui/etcher.ts @@ -267,6 +267,24 @@ async function main(): Promise { console.log('Build menu failed. '); } }); + + electron.ipcMain.on('webview-dom-ready', (_, id) => { + const webview = electron.webContents.fromId(id); + + // Open link in browser if it's opened as a 'foreground-tab' + webview.setWindowOpenHandler((event) => { + const url = new URL(event.url); + if ( + (url.protocol === 'http:' || url.protocol === 'https:') && + event.disposition === 'foreground-tab' && + // Don't open links if they're disabled by the env var + !(settings.getSync('disableExternalLinks')) + ) { + electron.shell.openExternal(url.href); + } + return { action: 'deny' }; + }); + }); } } main(); From 94106692942ed33a6fc9843140f3ee2a232dcee9 Mon Sep 17 00:00:00 2001 From: Akis Kesoglou Date: Thu, 6 Jul 2023 21:50:29 +0300 Subject: [PATCH 2/3] Fix lint issues --- lib/gui/app/i18n/zh-TW.ts | 6 +++--- lib/gui/etcher.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/gui/app/i18n/zh-TW.ts b/lib/gui/app/i18n/zh-TW.ts index 98b63a44..d1a16201 100644 --- a/lib/gui/app/i18n/zh-TW.ts +++ b/lib/gui/app/i18n/zh-TW.ts @@ -46,7 +46,8 @@ const translation = { drive: '磁碟', missingPartitionTable: '看起來這不是一個可啟動的{{type}}。\n\n這個{{type}}似乎不包含分割表,因此您的設備可能無法識別或無法正確啟動。', - largeDriveSize: '這是個很大容量的磁碟!請檢查並確認它不包含對您來說存放很重要的資料', + largeDriveSize: + '這是個很大容量的磁碟!請檢查並確認它不包含對您來說存放很重要的資料', systemDrive: '選擇系統分割區很危險,因為這將會刪除你的系統', sourceDrive: '來源映像檔位於這個分割區中', noSpace: '磁碟空間不足。請插入另一個較大的磁碟並重試。', @@ -130,8 +131,7 @@ const translation = { autoUpdate: '自動更新', settings: '軟體設定', systemInformation: '系統資訊', - trimExtPartitions: - '修改原始映像檔上未分配的空間(在 ext 類型分割區中)', + trimExtPartitions: '修改原始映像檔上未分配的空間(在 ext 類型分割區中)', }, menu: { edit: '編輯', diff --git a/lib/gui/etcher.ts b/lib/gui/etcher.ts index 104f6858..f593f2f5 100644 --- a/lib/gui/etcher.ts +++ b/lib/gui/etcher.ts @@ -21,7 +21,7 @@ import { promises as fs } from 'fs'; import { platform } from 'os'; import * as path from 'path'; import * as semver from 'semver'; -import * as _ from 'lodash'; +import * as lodash from 'lodash'; import './app/i18n'; @@ -107,10 +107,10 @@ async function getCommandLineURL(argv: string[]): Promise { } } -const initSentryMain = _.once(() => { +const initSentryMain = lodash.once(() => { const dsn = settings.getSync('analyticsSentryToken') || - _.get(packageJSON, ['analytics', 'sentry', 'token']); + lodash.get(packageJSON, ['analytics', 'sentry', 'token']); SentryMain.init({ dsn, beforeSend: anonymizeSentryData }); }); @@ -278,7 +278,7 @@ async function main(): Promise { (url.protocol === 'http:' || url.protocol === 'https:') && event.disposition === 'foreground-tab' && // Don't open links if they're disabled by the env var - !(settings.getSync('disableExternalLinks')) + !settings.getSync('disableExternalLinks') ) { electron.shell.openExternal(url.href); } From 7fdbc439f7a2bdf3071a2e51d15085cf962f09bb Mon Sep 17 00:00:00 2001 From: Akis Kesoglou Date: Wed, 12 Jul 2023 11:20:43 +0300 Subject: [PATCH 3/3] Fix Publish action on Windows --- .github/actions/publish/action.yml | 7 +++++++ .github/actions/test/action.yml | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/.github/actions/publish/action.yml b/.github/actions/publish/action.yml index 6e19a250..bf32eeda 100644 --- a/.github/actions/publish/action.yml +++ b/.github/actions/publish/action.yml @@ -31,10 +31,17 @@ runs: path: ${{ runner.temp }} - name: Extract custom source artifact + if: runner.os != 'Windows' shell: pwsh working-directory: . run: tar -xf ${{ runner.temp }}/custom.tgz + - name: Extract custom source artifact + if: runner.os == 'Windows' + shell: pwsh + working-directory: . + run: C:\"Program Files"\Git\usr\bin\tar.exe --force-local -xf ${{ runner.temp }}\custom.tgz + - name: Setup Node.js uses: actions/setup-node@v3 with: diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index 647c91ee..39ecaabd 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -47,9 +47,15 @@ runs: ELECTRON_NO_ATTACH_CONSOLE: true - name: Compress custom source + if: runner.os != 'Windows' shell: pwsh run: tar -acf ${{ runner.temp }}/custom.tgz . + - name: Compress custom source + if: runner.os == 'Windows' + shell: pwsh + run: C:\"Program Files"\Git\usr\bin\tar.exe --force-local -acf ${{ runner.temp }}\custom.tgz . + - name: Upload custom artifact uses: actions/upload-artifact@v3 with: