Skip to content

Commit ba778c7

Browse files
authored
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
1 parent 0ff07fb commit ba778c7

4 files changed

Lines changed: 65 additions & 29 deletions

File tree

src/main/ExtensionManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ export default class ExtensionManager {
438438
if (
439439
!FILE_WHITE_LIST.includes(file.name) &&
440440
(!FILE_EXTENSION_WHITE_LIST.includes(extname(file.name)) ||
441-
!/^[\w/]+(?:\.\w+)*\.\w+/.test(file.name))
441+
!/^[\w\/]+(?:.\w+)*\.\w+/.test(file.name))
442442
) {
443443
throw new Error(`Filename "${file.name}" not allowed`);
444444
}

src/main/Ui/MainTab.ts

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
Rectangle,
88
BrowserWindow,
99
DidCreateWindowDetails,
10+
Event,
11+
HandlerDetails,
1012
} from "electron";
1113

1214
import { LOGIN_PAGE, RECENT_FILES } from "Const";
@@ -21,9 +23,12 @@ import {
2123
isPrototypeUrl,
2224
isAppAuthRedeem,
2325
isFigmaDocLink,
26+
isFigmaBoardLink,
27+
isFigmaDesignLink,
2428
} from "Utils/Common";
2529
import { storage } from "Main/Storage";
2630
import { logger } from "Main/Logger";
31+
import { electron } from 'process';
2732

2833
export default class MainTab {
2934
private _userId: string;
@@ -105,7 +110,7 @@ export default class MainTab {
105110
this.view.webContents.send("loadCurrentTheme", theme);
106111
}
107112

108-
private onMainTabWillNavigate(event: Event, url: string) {
113+
private onMainTabWillNavigate(event: Event<any>, url: string) {
109114
if (isValidProjectLink(url) || isPrototypeUrl(url)) {
110115
app.emit("openUrlInNewTab", url);
111116

@@ -115,46 +120,52 @@ export default class MainTab {
115120
private onDomReady(event: any) {
116121
this.reloadCurrentTheme();
117122
}
118-
private onMainWindowWillNavigate(event: any, newUrl: string) {
119-
const currentUrl = event.sender.getURL();
123+
private onMainWindowWillNavigate(event: Event<any>, url: string) {
124+
if (event?.sender) {
125+
const currentUrl = event.sender.getURL();
126+
if (isAppAuthRedeem(url)) {
127+
return;
128+
}
120129

121-
if (isAppAuthRedeem(newUrl)) {
122-
return;
123-
}
130+
if (url === currentUrl) {
131+
event.preventDefault();
132+
return;
133+
}
124134

125-
if (newUrl === currentUrl) {
126-
event.preventDefault();
127-
return;
128-
}
129135

130-
if (isFigmaDocLink(newUrl)) {
131-
shell.openExternal(newUrl);
136+
const from = parse(currentUrl);
137+
const to = parse(url);
132138

133-
event.preventDefault();
134-
return;
135-
}
139+
if (from.pathname === "/login") {
140+
// this.tabManager.reloadAll();
136141

137-
const from = parse(currentUrl);
138-
const to = parse(newUrl);
142+
event.preventDefault();
143+
return;
144+
}
139145

140-
if (from.pathname === "/login") {
141-
// this.tabManager.reloadAll();
146+
if (to.pathname === "/logout") {
147+
app.emit("signOut");
148+
}
142149

143-
event.preventDefault();
144-
return;
150+
if (to.search && to.search.match(/[\?\&]redirected=1/)) {
151+
event.preventDefault();
152+
return;
153+
}
145154
}
146155

147-
if (to.pathname === "/logout") {
148-
app.emit("signOut");
156+
if (isFigmaDocLink(url)) {
157+
shell.openExternal(url);
158+
event.preventDefault();
159+
return;
149160
}
150-
151-
if (to.search && to.search.match(/[\?\&]redirected=1/)) {
161+
if (isFigmaBoardLink(url) || isFigmaDesignLink(url)) {
162+
app.emit("openUrlInNewTab", url);
152163
event.preventDefault();
153164
return;
154165
}
155166
}
156167
private onNewWindow(window: BrowserWindow, details: DidCreateWindowDetails) {
157-
const url = details.url;
168+
const { url } = details;
158169
logger.debug("newWindow, url: ", url);
159170

160171
if (/start_google_sso/.test(url)) return;
@@ -163,11 +174,28 @@ export default class MainTab {
163174
app.emit("openUrlInNewTab", url);
164175
return;
165176
}
177+
if (isFigmaBoardLink(url) || isFigmaDesignLink(url)) {
178+
window.destroy()
179+
app.emit("openUrlInNewTab", url);
180+
return;
181+
}
166182

167183
shell.openExternal(url);
168184
}
169185

186+
private windowOpenHandler(details: HandlerDetails) {
187+
const { url } = details;
188+
189+
if (isPrototypeUrl(url) || isValidProjectLink(url) || isFigmaBoardLink(url) || isFigmaDesignLink(url)) {
190+
app.emit("openUrlInNewTab", url);
191+
return { action: "deny" };
192+
} else {
193+
return { action: "allow" };
194+
}
195+
}
196+
170197
private registerEvents() {
198+
this.view.webContents.setWindowOpenHandler(this.windowOpenHandler.bind(this));
171199
this.view.webContents.on("will-navigate", this.onMainTabWillNavigate.bind(this));
172200
this.view.webContents.on("will-navigate", this.onMainWindowWillNavigate.bind(this));
173201
this.view.webContents.on("dom-ready", this.onDomReady.bind(this));

src/main/Ui/Tab.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,13 @@ export default class Tab {
197197
}
198198

199199
private windowOpenHandler(details: HandlerDetails) {
200-
const url = details.url;
200+
const { url } = details;
201201

202-
shell.openExternal(url);
202+
if (isPrototypeUrl(url) || isValidProjectLink(url)) {
203+
app.emit("openUrlInNewTab", url);
204+
} else {
205+
shell.openExternal(url);
206+
}
203207

204208
return { action: "deny" };
205209
}

src/utils/Common/url.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,7 @@ export const isValidFigjamLink = (url: string) =>
5757

5858
export const isFigmaDocLink = (url: string) =>
5959
/^https:\/\/w{0,3}?.figma.com\/plugin-docs/.test(url);
60+
export const isFigmaBoardLink = (url: string) =>
61+
/^https:\/\/w{0,3}?.figma.com\/board/.test(url);
62+
export const isFigmaDesignLink = (url: string) =>
63+
/^https:\/\/w{0,3}?.figma.com\/design/.test(url);

0 commit comments

Comments
 (0)