From ba778c73d13532932837b9602bdf41f45825e060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A2=D0=BE=D1=85=D0=B0=20=D0=9B=D0=B8=D1=81?= Date: Wed, 29 May 2024 12:21:56 +0500 Subject: [PATCH] Fixing some issues #369 #368 #362 (#381) * fix: set appVersion to ignore version checking. Closes #371 #372 #373 * fix: Display jam and design page types inside app. Closes #369 * fix: Regex to match file path for importing extension. #368 * fix: Window opens while trying to open some urls after b89e095 * fix: Opens prototype or project from opened design in new tab instead of browser (#362) * Update MainTab.ts Fix opening some urls in window --- src/main/ExtensionManager.ts | 2 +- src/main/Ui/MainTab.ts | 80 ++++++++++++++++++++++++------------ src/main/Ui/Tab.ts | 8 +++- src/utils/Common/url.ts | 4 ++ 4 files changed, 65 insertions(+), 29 deletions(-) diff --git a/src/main/ExtensionManager.ts b/src/main/ExtensionManager.ts index c882c47..63d086f 100644 --- a/src/main/ExtensionManager.ts +++ b/src/main/ExtensionManager.ts @@ -438,7 +438,7 @@ export default class ExtensionManager { if ( !FILE_WHITE_LIST.includes(file.name) && (!FILE_EXTENSION_WHITE_LIST.includes(extname(file.name)) || - !/^[\w/]+(?:\.\w+)*\.\w+/.test(file.name)) + !/^[\w\/]+(?:.\w+)*\.\w+/.test(file.name)) ) { throw new Error(`Filename "${file.name}" not allowed`); } diff --git a/src/main/Ui/MainTab.ts b/src/main/Ui/MainTab.ts index 9b9f063..bdcb060 100644 --- a/src/main/Ui/MainTab.ts +++ b/src/main/Ui/MainTab.ts @@ -7,6 +7,8 @@ import { Rectangle, BrowserWindow, DidCreateWindowDetails, + Event, + HandlerDetails, } from "electron"; import { LOGIN_PAGE, RECENT_FILES } from "Const"; @@ -21,9 +23,12 @@ import { isPrototypeUrl, isAppAuthRedeem, isFigmaDocLink, + isFigmaBoardLink, + isFigmaDesignLink, } from "Utils/Common"; import { storage } from "Main/Storage"; import { logger } from "Main/Logger"; +import { electron } from 'process'; export default class MainTab { private _userId: string; @@ -105,7 +110,7 @@ export default class MainTab { this.view.webContents.send("loadCurrentTheme", theme); } - private onMainTabWillNavigate(event: Event, url: string) { + private onMainTabWillNavigate(event: Event, url: string) { if (isValidProjectLink(url) || isPrototypeUrl(url)) { app.emit("openUrlInNewTab", url); @@ -115,46 +120,52 @@ export default class MainTab { private onDomReady(event: any) { this.reloadCurrentTheme(); } - private onMainWindowWillNavigate(event: any, newUrl: string) { - const currentUrl = event.sender.getURL(); + private onMainWindowWillNavigate(event: Event, url: string) { + if (event?.sender) { + const currentUrl = event.sender.getURL(); + if (isAppAuthRedeem(url)) { + return; + } - if (isAppAuthRedeem(newUrl)) { - return; - } + if (url === currentUrl) { + event.preventDefault(); + return; + } - if (newUrl === currentUrl) { - event.preventDefault(); - return; - } - if (isFigmaDocLink(newUrl)) { - shell.openExternal(newUrl); + const from = parse(currentUrl); + const to = parse(url); - event.preventDefault(); - return; - } + if (from.pathname === "/login") { + // this.tabManager.reloadAll(); - const from = parse(currentUrl); - const to = parse(newUrl); + event.preventDefault(); + return; + } - if (from.pathname === "/login") { - // this.tabManager.reloadAll(); + if (to.pathname === "/logout") { + app.emit("signOut"); + } - event.preventDefault(); - return; + if (to.search && to.search.match(/[\?\&]redirected=1/)) { + event.preventDefault(); + return; + } } - if (to.pathname === "/logout") { - app.emit("signOut"); + if (isFigmaDocLink(url)) { + shell.openExternal(url); + event.preventDefault(); + return; } - - if (to.search && to.search.match(/[\?\&]redirected=1/)) { + if (isFigmaBoardLink(url) || isFigmaDesignLink(url)) { + app.emit("openUrlInNewTab", url); event.preventDefault(); return; } } private onNewWindow(window: BrowserWindow, details: DidCreateWindowDetails) { - const url = details.url; + const { url } = details; logger.debug("newWindow, url: ", url); if (/start_google_sso/.test(url)) return; @@ -163,11 +174,28 @@ export default class MainTab { app.emit("openUrlInNewTab", url); return; } + if (isFigmaBoardLink(url) || isFigmaDesignLink(url)) { + window.destroy() + app.emit("openUrlInNewTab", url); + return; + } shell.openExternal(url); } + private windowOpenHandler(details: HandlerDetails) { + const { url } = details; + + if (isPrototypeUrl(url) || isValidProjectLink(url) || isFigmaBoardLink(url) || isFigmaDesignLink(url)) { + app.emit("openUrlInNewTab", url); + return { action: "deny" }; + } else { + return { action: "allow" }; + } + } + private registerEvents() { + this.view.webContents.setWindowOpenHandler(this.windowOpenHandler.bind(this)); this.view.webContents.on("will-navigate", this.onMainTabWillNavigate.bind(this)); this.view.webContents.on("will-navigate", this.onMainWindowWillNavigate.bind(this)); this.view.webContents.on("dom-ready", this.onDomReady.bind(this)); diff --git a/src/main/Ui/Tab.ts b/src/main/Ui/Tab.ts index e13b99c..2f2f280 100644 --- a/src/main/Ui/Tab.ts +++ b/src/main/Ui/Tab.ts @@ -197,9 +197,13 @@ export default class Tab { } private windowOpenHandler(details: HandlerDetails) { - const url = details.url; + const { url } = details; - shell.openExternal(url); + if (isPrototypeUrl(url) || isValidProjectLink(url)) { + app.emit("openUrlInNewTab", url); + } else { + shell.openExternal(url); + } return { action: "deny" }; } diff --git a/src/utils/Common/url.ts b/src/utils/Common/url.ts index 61e0726..73eaff8 100644 --- a/src/utils/Common/url.ts +++ b/src/utils/Common/url.ts @@ -57,3 +57,7 @@ export const isValidFigjamLink = (url: string) => export const isFigmaDocLink = (url: string) => /^https:\/\/w{0,3}?.figma.com\/plugin-docs/.test(url); +export const isFigmaBoardLink = (url: string) => + /^https:\/\/w{0,3}?.figma.com\/board/.test(url); +export const isFigmaDesignLink = (url: string) => + /^https:\/\/w{0,3}?.figma.com\/design/.test(url);