Skip to content

Commit eed856f

Browse files
committed
feat: add navigation history change event and enhance webview data handling
1 parent 09b2aa6 commit eed856f

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

src/main/browser/tabs/tab/controllers/data.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
11
import { Tab } from "@/browser/tabs/tab";
22
import { TabbedBrowserWindow } from "@/browser/window";
3+
import { WebContents } from "electron";
34

45
export class TabDataController {
56
private readonly tab: Tab;
67

8+
// from other controllers
79
public window: TabbedBrowserWindow | null = null;
810
public space: string | null = null;
911
public pipActive: boolean = false;
1012

13+
// from webview (recorded here)
14+
public audible: boolean = false;
15+
public muted: boolean = false;
16+
public url: string = "";
17+
public isLoading: boolean = true;
18+
19+
// recorded here
20+
public asleep: boolean = false;
21+
1122
constructor(tab: Tab) {
1223
this.tab = tab;
1324

1425
tab.on("window-changed", () => this.refreshData());
1526
tab.on("space-changed", () => this.refreshData());
1627
tab.on("pip-active-changed", () => this.refreshData());
28+
tab.on("nav-history-changed", () => this.emitDataChanged());
29+
30+
tab.on("webview-detached", () => this.onWebviewDetached());
31+
}
32+
33+
private emitDataChanged() {
34+
this.tab.emit("data-changed");
1735
}
1836

1937
public refreshData() {
@@ -49,11 +67,42 @@ export class TabDataController {
4967
return changed;
5068
}
5169

70+
public setupWebviewData(webContents: WebContents) {
71+
// audible
72+
webContents.on("audio-state-changed", () => {});
73+
webContents.on("media-started-playing", () => {});
74+
webContents.on("media-paused", () => {});
75+
76+
// title
77+
webContents.on("page-title-updated", () => {});
78+
79+
// isLoading
80+
webContents.on("did-finish-load", () => {});
81+
webContents.on("did-start-loading", () => {});
82+
webContents.on("did-stop-loading", () => {});
83+
84+
// url
85+
webContents.on("did-finish-load", () => {});
86+
webContents.on("did-start-navigation", () => {});
87+
webContents.on("did-redirect-navigation", () => {});
88+
webContents.on("did-navigate-in-page", () => {});
89+
}
90+
91+
private onWebviewDetached() {
92+
return false;
93+
}
94+
5295
public get() {
96+
const tab = this.tab;
97+
const navHistory = tab.navigation.navHistory;
98+
const navHistoryIndex = tab.navigation.navHistoryIndex;
99+
53100
return {
54101
window: this.window,
55102
space: this.space,
56-
pipActive: this.pipActive
103+
pipActive: this.pipActive,
104+
navHistory: navHistory,
105+
navHistoryIndex: navHistoryIndex
57106
};
58107
}
59108
}

src/main/browser/tabs/tab/controllers/navigation.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class TabNavigationController {
3131
return this._navHistoryIndex ?? this.navHistory.length - 1;
3232
}
3333

34-
public setupNavigation(webContents: WebContents) {
34+
public setupWebviewNavigation(webContents: WebContents) {
3535
// Restore the navigation history
3636
webContents.navigationHistory.restore({
3737
entries: this.navHistory,
@@ -53,6 +53,8 @@ export class TabNavigationController {
5353
this.navHistory = navHistory;
5454
this._navHistoryIndex = activeIndex;
5555

56+
tab.emit("nav-history-changed");
57+
5658
return true;
5759
}
5860

@@ -79,6 +81,7 @@ export class TabNavigationController {
7981
}
8082
this._navHistoryIndex = navHistoryIndex + 1;
8183
}
84+
tab.emit("nav-history-changed");
8285
return true;
8386
}
8487

src/main/browser/tabs/tab/controllers/webview.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ export class TabWebviewController {
7070
tab.emit("focused");
7171
});
7272

73-
tab.navigation.setupNavigation(this.webContents);
73+
tab.navigation.setupWebviewNavigation(this.webContents);
74+
tab.data.setupWebviewData(this.webContents);
7475

7576
tab.emit("webview-attached");
7677

src/main/browser/tabs/tab/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type TabEvents = {
2929
"bounds-changed": [PageBounds];
3030
"visiblity-changed": [boolean];
3131
"sleep-changed": [];
32+
"nav-history-changed": [];
3233
"data-changed": [];
3334

3435
focused: [];

0 commit comments

Comments
 (0)