Skip to content

Commit

Permalink
Fixing some issues #369 #368 #362 (#381)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ToxesFoxes authored May 29, 2024
1 parent 0ff07fb commit ba778c7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/main/ExtensionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
Expand Down
80 changes: 54 additions & 26 deletions src/main/Ui/MainTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
Rectangle,
BrowserWindow,
DidCreateWindowDetails,
Event,
HandlerDetails,
} from "electron";

import { LOGIN_PAGE, RECENT_FILES } from "Const";
Expand All @@ -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;
Expand Down Expand Up @@ -105,7 +110,7 @@ export default class MainTab {
this.view.webContents.send("loadCurrentTheme", theme);
}

private onMainTabWillNavigate(event: Event, url: string) {
private onMainTabWillNavigate(event: Event<any>, url: string) {
if (isValidProjectLink(url) || isPrototypeUrl(url)) {
app.emit("openUrlInNewTab", url);

Expand All @@ -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<any>, 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;
Expand All @@ -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));
Expand Down
8 changes: 6 additions & 2 deletions src/main/Ui/Tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
}
Expand Down
4 changes: 4 additions & 0 deletions src/utils/Common/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit ba778c7

Please sign in to comment.