Skip to content

Commit 14e196f

Browse files
authored
Open all web links in Integrated Browser (#1713)
1 parent 9dd222a commit 14e196f

File tree

4 files changed

+20
-64
lines changed

4 files changed

+20
-64
lines changed

src/commands/serverActions.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
} from "../utils";
2020
import { mainCommandMenu, mainSourceControlMenu } from "./studio";
2121
import { AtelierAPI } from "../api";
22-
import { getCSPToken } from "../utils/getCSPToken";
2322
import { isfsConfig } from "../utils/FileProviderUtil";
2423

2524
type ServerAction = { detail: string; id: string; label: string; rawLink?: string };
@@ -224,11 +223,11 @@ export async function serverActions(): Promise<void> {
224223
}
225224
switch (action.id) {
226225
case "openPortal": {
227-
vscode.env.openExternal(vscode.Uri.parse(`${serverUrl}${portalPath}`));
226+
vscode.commands.executeCommand("workbench.action.browser.open", `${serverUrl}${portalPath}`);
228227
break;
229228
}
230229
case "openClassReference": {
231-
vscode.env.openExternal(vscode.Uri.parse(`${serverUrl}${classRef}`));
230+
vscode.commands.executeCommand("workbench.action.browser.open", `${serverUrl}${classRef}`);
232231
break;
233232
}
234233
case "openStudioAddin": {
@@ -248,15 +247,12 @@ export async function serverActions(): Promise<void> {
248247
});
249248
if (addin) {
250249
sendStudioAddinTelemetryEvent(addin.label);
251-
const token = await getCSPToken(api, addin.id);
252250
let params = `Namespace=${nsEncoded}`;
253251
params += `&User=${encodeURIComponent(username)}`;
254-
if (project !== "") {
252+
if (project != "") {
255253
params += `&Project=${encodeURIComponent(project)}`;
256254
}
257-
params += `&CSPCHD=${token}`;
258-
params += "&CSPSHARE=1";
259-
vscode.env.openExternal(vscode.Uri.parse(`${serverUrl}${addin.id}?${params}`));
255+
vscode.commands.executeCommand("workbench.action.browser.open", `${serverUrl}${addin.id}?${params}`);
260256
}
261257
}
262258
break;
@@ -278,16 +274,7 @@ export async function serverActions(): Promise<void> {
278274
break;
279275
}
280276
default: {
281-
let url = vscode.Uri.parse(action.detail);
282-
if (action.rawLink?.startsWith("${serverUrl}")) {
283-
const token = await getCSPToken(api, url.path);
284-
if (token.length > 0) {
285-
url = url.with({
286-
query: url.query.length ? `${url.query}&CSPCHD=${token}` : `CSPCHD=${token}`,
287-
});
288-
}
289-
}
290-
vscode.env.openExternal(url);
277+
vscode.commands.executeCommand("workbench.action.browser.open", action.detail);
291278
}
292279
}
293280
});

src/commands/studio.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,6 @@ export class StudioActions {
130130
.then((answer) => (answer === "Yes" ? "1" : answer === "No" ? "0" : "2"));
131131
case 2: {
132132
// Run a CSP page/Template. The Target is the full path of CSP page/template on the connected server
133-
134-
// Do this ourself instead of using our new getCSPToken wrapper function, because that function reuses tokens which causes issues with
135-
// webview when server is 2020.1.1 or greater, as session cookie scope is typically Strict, meaning that the webview
136-
// cannot store the cookie. Consequence is web sessions may build up (they get a 900 second timeout)
137133
const cspchd = await this.api
138134
.actionQuery("select %Atelier_v1_Utils.General_GetCSPToken(?) token", [target])
139135
.then((data) => data.result.content[0].token)
@@ -160,10 +156,8 @@ export class StudioActions {
160156
if (message.result && message.result === "done") {
161157
answer = "1";
162158
panel.dispose();
163-
} else if (typeof message.href == "string") {
164-
const linkUri = vscode.Uri.parse(message.href);
165-
// Only open http(s) links
166-
if (/^https?$/.test(linkUri.scheme)) vscode.env.openExternal(linkUri);
159+
} else if (typeof message.href == "string" && /^https?:\/\//.test(message.href)) {
160+
vscode.commands.executeCommand("workbench.action.browser.open", message.href);
167161
}
168162
});
169163
panel.onDidDispose(() => resolve(answer));
@@ -207,8 +201,11 @@ export class StudioActions {
207201
}
208202
case 3: {
209203
// Run an EXE on the client.
210-
if (/^(ht|f)tps?:\/\//i.test(target)) {
211-
// Allow target that is a URL to be opened in an external browser
204+
if (/^https?:\/\//.test(target)) {
205+
// Allow https URLs to be opened in the Integrated Browser
206+
vscode.commands.executeCommand("workbench.action.browser.open", target);
207+
} else if (/^ftps?:\/\//.test(target)) {
208+
// ftp links aren't supported by the Integrated Browser
212209
vscode.env.openExternal(vscode.Uri.parse(target));
213210
} else {
214211
// Anything else is not supported

src/extension.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,9 @@ function proposedApiPrompt(active: boolean, added?: readonly vscode.WorkspaceFol
641641
.then(async (action) => {
642642
switch (action) {
643643
case "Yes":
644-
vscode.env.openExternal(
645-
vscode.Uri.parse("https://github.com/intersystems-community/vscode-objectscript#enable-proposed-apis")
644+
vscode.commands.executeCommand(
645+
"workbench.action.browser.open",
646+
"https://github.com/intersystems-community/vscode-objectscript#enable-proposed-apis"
646647
);
647648
break;
648649
case "Never":
@@ -1749,12 +1750,11 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
17491750
.catch(() => {
17501751
// Swallow errors
17511752
})) ?? `/csp/${api.ns}`;
1752-
vscode.env.openExternal(
1753-
vscode.Uri.parse(
1754-
`${api.config.https ? "https" : "http"}://${api.config.host}:${api.config.port}${
1755-
api.config.pathPrefix
1756-
}${app}${path}`
1757-
)
1753+
vscode.commands.executeCommand(
1754+
"workbench.action.browser.open",
1755+
`${api.config.https ? "https" : "http"}://${api.config.host}:${api.config.port}${
1756+
api.config.pathPrefix
1757+
}${app}${path}`
17581758
);
17591759
}
17601760
}

src/utils/getCSPToken.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)