|
1 | 1 | import { Tab } from "@/browser/tabs/tab"; |
2 | 2 | import { TabbedBrowserWindow } from "@/browser/window"; |
| 3 | +import { WebContents } from "electron"; |
3 | 4 |
|
4 | 5 | export class TabDataController { |
5 | 6 | private readonly tab: Tab; |
6 | 7 |
|
| 8 | + // from other controllers |
7 | 9 | public window: TabbedBrowserWindow | null = null; |
8 | 10 | public space: string | null = null; |
9 | 11 | public pipActive: boolean = false; |
10 | 12 |
|
| 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 | + |
11 | 22 | constructor(tab: Tab) { |
12 | 23 | this.tab = tab; |
13 | 24 |
|
14 | 25 | tab.on("window-changed", () => this.refreshData()); |
15 | 26 | tab.on("space-changed", () => this.refreshData()); |
16 | 27 | 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"); |
17 | 35 | } |
18 | 36 |
|
19 | 37 | public refreshData() { |
@@ -49,11 +67,42 @@ export class TabDataController { |
49 | 67 | return changed; |
50 | 68 | } |
51 | 69 |
|
| 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 | + |
52 | 95 | public get() { |
| 96 | + const tab = this.tab; |
| 97 | + const navHistory = tab.navigation.navHistory; |
| 98 | + const navHistoryIndex = tab.navigation.navHistoryIndex; |
| 99 | + |
53 | 100 | return { |
54 | 101 | window: this.window, |
55 | 102 | space: this.space, |
56 | | - pipActive: this.pipActive |
| 103 | + pipActive: this.pipActive, |
| 104 | + navHistory: navHistory, |
| 105 | + navHistoryIndex: navHistoryIndex |
57 | 106 | }; |
58 | 107 | } |
59 | 108 | } |
0 commit comments