Skip to content

Commit 1a7f291

Browse files
committed
additional fixes:
- embed: support configuring custom proxyPrefix - electron app: fix opening links in new window - electron app: fix preload page build
1 parent fa11c8a commit 1a7f291

File tree

7 files changed

+48
-95
lines changed

7 files changed

+48
-95
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"node-fetch": "2.6.7",
2424
"pdfjs-dist": "2.2.228",
2525
"pretty-bytes": "^5.6.0",
26-
"replaywebpage": "^2.2.0-beta.4",
26+
"replaywebpage": "^2.2.0-beta.5",
2727
"stream-browserify": "^3.0.0",
2828
"tsconfig-paths-webpack-plugin": "^4.1.0",
2929
"unused-filename": "^4.0.1",

src/electron/app-popup.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,14 @@ import { RecPopup } from "../popup";
44
import { CollectionLoader } from "@webrecorder/wabac/swlib";
55
import { listAllMsg } from "../utils";
66
import { setLocalOption } from "../localstorage";
7+
import { type PropertyValues } from "lit";
78

89
// ===========================================================================
910
class AppRecPopup extends RecPopup {
10-
constructor() {
11-
super();
12-
13-
// @ts-expect-error - TS2339 - Property 'collLoader' does not exist on type 'AppRecPopup'.
14-
this.collLoader = new CollectionLoader();
15-
16-
//this.tabId = 0;//window.location.hash && Number(window.location.hash.slice(1));
17-
18-
// @ts-expect-error - TS2339 - Property 'allowCreate' does not exist on type 'AppRecPopup'.
19-
this.allowCreate = false;
20-
21-
// @ts-expect-error - TS2339 - Property 'msg' does not exist on type 'AppRecPopup'.
22-
this.msg = null;
23-
}
11+
collLoader = new CollectionLoader();
12+
allowCreated = false;
13+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
14+
msg: any = null;
2415

2516
static get properties() {
2617
return {
@@ -29,22 +20,18 @@ class AppRecPopup extends RecPopup {
2920
};
3021
}
3122

32-
// @ts-expect-error - TS2416 - Property 'firstUpdated' in type 'AppRecPopup' is not assignable to the same property in base type 'RecPopup'.
33-
firstUpdated() {
34-
super.firstUpdated();
35-
36-
// @ts-expect-error - TS2339 - Property 'collLoader' does not exist on type 'AppRecPopup'.
23+
firstUpdated() : Promise<void> {
3724
listAllMsg(this.collLoader).then((msg) => {
3825
this.onMessage(msg);
3926
});
27+
28+
return super.firstUpdated()
4029
}
4130

42-
// @ts-expect-error - TS7006 - Parameter 'changedProperties' implicitly has an 'any' type.
43-
updated(changedProperties) {
31+
updated(changedProperties: PropertyValues<this>) {
4432
super.updated(changedProperties);
4533

46-
if (changedProperties.has("msg")) {
47-
// @ts-expect-error - TS2339 - Property 'msg' does not exist on type 'AppRecPopup'.
34+
if (changedProperties.has("msg") && this.msg) {
4835
this.onMessage(this.msg);
4936
}
5037
}
@@ -68,12 +55,10 @@ class AppRecPopup extends RecPopup {
6855

6956
// @ts-expect-error - TS7006 - Parameter 'message' implicitly has an 'any' type.
7057
async makeNewColl(message) {
71-
// @ts-expect-error - TS2339 - Property 'collLoader' does not exist on type 'AppRecPopup'.
7258
const newColl = await this.collLoader.initNewColl({ title: message.title });
7359

7460
await setLocalOption("defaultCollId", newColl.name);
7561

76-
// @ts-expect-error - TS2339 - Property 'collLoader' does not exist on type 'AppRecPopup'.
7762
const respMsg = await listAllMsg(this.collLoader);
7863

7964
this.onMessage(respMsg);

src/electron/electron-recorder-app.ts

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*eslint-env node */
22

3-
import { app, session, BrowserWindow, ipcMain, dialog } from "electron";
3+
import { app, session, BrowserWindow, ipcMain, dialog, type HandlerDetails, WebContents, WindowOpenHandlerResponse } from "electron";
44
import { ElectronRecorder } from "./electron-recorder";
55

66
import {
@@ -176,14 +176,11 @@ class ElectronRecorderApp extends ElectronReplayApp {
176176
}
177177

178178
createRecordWindow({
179-
// @ts-expect-error - TS2525 - Initializer provides no value for this binding element and the binding element has no default value.
180-
url,
179+
url = "",
181180
collId = "",
182181
startRec = true,
183182
autorun = false,
184183
} = {}) {
185-
console.log("start rec window: " + url);
186-
187184
const recWindow = new BrowserWindow({
188185
width: this.screenSize.width,
189186
height: this.screenSize.height,
@@ -218,7 +215,7 @@ class ElectronRecorderApp extends ElectronReplayApp {
218215
startRec,
219216
// @ts-expect-error - TS7006 - Parameter 'autorun' implicitly has an 'any' type.
220217
autorun,
221-
popupView = null,
218+
//popupView = null,
222219
) {
223220
const id = recWebContents.id;
224221

@@ -229,7 +226,7 @@ class ElectronRecorderApp extends ElectronReplayApp {
229226
recWindow,
230227
collId,
231228
autorun,
232-
popup: popupView,
229+
popup: null,
233230
staticPrefix: this.staticContentPath,
234231
// @ts-expect-error - TS2339 - Property 'userAgent' does not exist on type 'ElectronRecorderApp'.
235232
userAgent: this.userAgent,
@@ -245,20 +242,17 @@ class ElectronRecorderApp extends ElectronReplayApp {
245242
});
246243
});
247244

248-
const newWinContents = popupView
249-
? // @ts-expect-error - TS2339 - Property 'webContents' does not exist on type 'never'.
250-
popupView.webContents
251-
: recWindow.webContents;
245+
const newWinContents = recWindow.webContents;
252246

253-
// @ts-expect-error - TS7006 - Parameter 'event' implicitly has an 'any' type. | TS7006 - Parameter 'url' implicitly has an 'any' type.
254-
newWinContents.on("new-window", (event, url) => {
255-
event.preventDefault();
247+
newWinContents.setWindowOpenHandler((details: HandlerDetails) => {
248+
const { url } = details;
256249
if (url.startsWith(STATIC_PREFIX)) {
257-
// @ts-expect-error - TS2531 - Object is possibly 'null'.
258-
this.mainWindow.loadURL(url);
259-
// @ts-expect-error - TS2531 - Object is possibly 'null'.
260-
this.mainWindow.show();
250+
this.mainWindow!.loadURL(url);
251+
this.mainWindow!.show();
252+
return { action: 'deny' };
261253
}
254+
255+
return { action: 'allow' };
262256
});
263257

264258
ipcMain.on("popup-msg-" + id, async (event, msg) => {
@@ -278,37 +272,17 @@ class ElectronRecorderApp extends ElectronReplayApp {
278272
}
279273
});
280274

281-
recWebContents.on(
282-
"new-window",
283-
(
284-
// @ts-expect-error - TS7006 - Parameter 'event' implicitly has an 'any' type.
285-
event,
286-
// @ts-expect-error - TS7006 - Parameter 'url' implicitly has an 'any' type.
287-
url,
288-
// @ts-expect-error - TS7006 - Parameter 'frameName' implicitly has an 'any' type.
289-
frameName,
290-
// @ts-expect-error - TS7006 - Parameter 'disposition' implicitly has an 'any' type.
291-
disposition,
292-
// @ts-expect-error - TS7006 - Parameter 'options' implicitly has an 'any' type.
293-
options,
294-
// @ts-expect-error - TS7006 - Parameter 'additionalFeatures' implicitly has an 'any' type.
295-
additionalFeatures,
296-
// @ts-expect-error - TS7006 - Parameter 'referrer' implicitly has an 'any' type.
297-
referrer,
298-
) => {
299-
event.preventDefault();
300-
event.newGuest = this.createRecordWindow({ url, collId, startRec });
301-
console.log(
302-
"new-window",
303-
url,
304-
frameName,
305-
disposition,
306-
options,
307-
additionalFeatures,
308-
referrer,
309-
);
310-
},
311-
);
275+
recWebContents.setWindowOpenHandler((details: HandlerDetails) : WindowOpenHandlerResponse => {
276+
const { url } = details;
277+
return {
278+
action: "allow",
279+
outlivesOpener: true,
280+
createWindow: () => {
281+
const win = this.createRecordWindow({ url, collId, startRec });
282+
return win.webContents;
283+
}
284+
}
285+
});
312286

313287
recWebContents.on("destroyed", () => {
314288
// @ts-expect-error - TS2339 - Property 'recorders' does not exist on type 'ElectronRecorderApp'.

src/electron/rec-window.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ class RecWindowUI extends LitElement {
8686
:host {
8787
width: 100%;
8888
height: 100%;
89+
display: flex;
90+
flex-direction: column;
8991
}
9092
9193
webview {
@@ -333,6 +335,7 @@ class RecWindowUI extends LitElement {
333335

334336
renderWebView() {
335337
return html` <webview
338+
allowpopups=""
336339
partition="persist:wr"
337340
@did-start-loading="${
338341
// @ts-expect-error - TS2339 - Property 'isLoading' does not exist on type 'RecWindowUI'.

src/ui/recordembed.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { type PropertyValues } from "lit";
21
import { property } from "lit/decorators.js";
32
import { Embed, apiPrefix } from "replaywebpage";
43

@@ -77,6 +76,12 @@ export class RecordEmbed extends Embed {
7776
window.addEventListener("beforeunload", () => {
7877
this.deleteColl();
7978
});
79+
80+
this.customConfig!.archivePrefix = this.archivePrefix;
81+
this.customConfig!.isLive = !this.archivePrefix;
82+
this.customConfig!.prefix = this.proxyPrefix;
83+
this.source = "proxy://" + this.proxyPrefix;
84+
8085
super.firstUpdated();
8186
}
8287

@@ -86,17 +91,6 @@ export class RecordEmbed extends Embed {
8691
}
8792
}
8893

89-
updated(changedProperties: PropertyValues<this>) {
90-
if (changedProperties.has("proxyPrefix") && this.customConfig) {
91-
this.customConfig.proxyPrefix = this.proxyPrefix;
92-
}
93-
if (changedProperties.has("archivePrefix") && this.customConfig) {
94-
this.customConfig.archivePrefix = this.archivePrefix;
95-
this.customConfig.isLive = !this.archivePrefix;
96-
}
97-
super.updated(changedProperties);
98-
}
99-
10094
getDownloadUrl() {
10195
return `${apiPrefix}/c/${this.coll}/dl?format=wacz&pages=all`;
10296
}

webpack.config.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ const optimization = {
6868
const resolve = {
6969
extensions: [".ts", ".js"],
7070
plugins: [new TsconfigPathsPlugin()],
71-
fallback: {"path": false, "fs": false}
7271
};
7372

7473
// ===========================================================================
@@ -109,6 +108,7 @@ const electronPreloadConfig = (/*env, argv*/) => {
109108
mode: "production",
110109
entry: {
111110
preload: "./src/electron/electron-rec-preload.ts",
111+
"rec-preload": "./src/electron/rec-preload.ts",
112112
},
113113
optimization,
114114
output: {
@@ -236,7 +236,6 @@ const extensionWebConfig = (env, argv) => {
236236
const electronWebConfig = (env, argv) => {
237237
const entry = {
238238
"rec-window": "./src/electron/rec-window.ts",
239-
"rec-preload": "./src/electron/rec-preload.ts",
240239
};
241240

242241
const copy = [
@@ -245,8 +244,6 @@ const electronWebConfig = (env, argv) => {
245244
{ from: "src/electron/rec-window.html", to: "" },
246245
];
247246

248-
const target = "web";
249-
250247
return sharedBuild(DIST_ELECTRON, { copy, entry }, argv);
251248
};
252249

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6786,10 +6786,10 @@ repeat-string@^1.6.1:
67866786
resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-1.6.1.tgz#8dcae470e1c88abc2d600fff4a776286da75e637"
67876787
integrity sha512-PV0dzCYDNfRi1jCDbJzpW7jNNDRuCOG/jI5ctQcGKt/clZD+YcPS3yIlWuTJMmESC8aevCFmWJy5wjAFgNqN6w==
67886788

6789-
replaywebpage@^2.2.0-beta.4:
6790-
version "2.2.0-beta.4"
6791-
resolved "https://registry.yarnpkg.com/replaywebpage/-/replaywebpage-2.2.0-beta.4.tgz#b01cd911ad3c3755637acaea37a9c0ba62cc5204"
6792-
integrity sha512-588xkIL2eu3eNWkQ4FymK3FeZ6um1wp3c05BKFvoUDuB7JmU2vpB3DFjsUKvMd6jeVG0ZVG+a4YH546iflas5A==
6789+
replaywebpage@^2.2.0-beta.5:
6790+
version "2.2.0-beta.5"
6791+
resolved "https://registry.yarnpkg.com/replaywebpage/-/replaywebpage-2.2.0-beta.5.tgz#40feb2a383c843da02e88600820f1430c6817103"
6792+
integrity sha512-VlOvKwDUUzdAh29+pkweloWyUZTpLbasE+5cgiAWcO1sXDbOioGGEldPeacbp40/luNpYPSZA+IhIonEPQegDQ==
67936793
dependencies:
67946794
"@fortawesome/fontawesome-free" "^5.15.4"
67956795
"@shoelace-style/shoelace" "~2.15.1"

0 commit comments

Comments
 (0)