Skip to content

Commit 860bcc8

Browse files
committed
Simplify view loading (hopefully more consistent page visibility)
1 parent 7100451 commit 860bcc8

File tree

2 files changed

+7
-29
lines changed

2 files changed

+7
-29
lines changed

packages/streamwall/src/main/StreamWindow.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export interface StreamWindowEventMap {
3636
export default class StreamWindow extends EventEmitter<StreamWindowEventMap> {
3737
config: StreamWindowConfig
3838
win: BrowserWindow
39-
offscreenWin: BrowserWindow
4039
backgroundView: WebContentsView
4140
overlayView: WebContentsView
4241
views: Map<number, ViewActor>
@@ -70,13 +69,6 @@ export default class StreamWindow extends EventEmitter<StreamWindowEventMap> {
7069
})
7170
this.win = win
7271

73-
const offscreenWin = new BrowserWindow({
74-
width,
75-
height,
76-
show: false,
77-
})
78-
this.offscreenWin = offscreenWin
79-
8072
const backgroundView = new WebContentsView({
8173
webPreferences: {
8274
preload: path.join(__dirname, 'layerPreload.js'),
@@ -146,14 +138,15 @@ export default class StreamWindow extends EventEmitter<StreamWindowEventMap> {
146138
}
147139

148140
createView() {
149-
const { win, offscreenWin } = this
141+
const { win } = this
150142
assert(win != null, 'Window must be initialized')
151143
const { backgroundColor } = this.config
152144
const view = new WebContentsView({
153145
webPreferences: {
154146
preload: path.join(__dirname, 'mediaPreload.js'),
155147
nodeIntegration: false,
156148
contextIsolation: true,
149+
backgroundThrottling: false,
157150
partition: 'persist:session',
158151
},
159152
})
@@ -171,7 +164,6 @@ export default class StreamWindow extends EventEmitter<StreamWindowEventMap> {
171164
id: viewId,
172165
view,
173166
win,
174-
offscreenWin,
175167
},
176168
})
177169

packages/streamwall/src/main/viewStateMachine.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ const viewStateMachine = setup({
2121
id: number
2222
view: WebContentsView
2323
win: BrowserWindow
24-
offscreenWin: BrowserWindow
2524
},
2625

2726
context: {} as {
2827
id: number
2928
win: BrowserWindow
30-
offscreenWin: BrowserWindow
3129
view: WebContentsView
3230
pos: ViewPos | null
3331
content: ViewContent | null
@@ -85,23 +83,19 @@ const viewStateMachine = setup({
8583
},
8684

8785
offscreenView: ({ context }) => {
88-
const { view, win, offscreenWin } = context
89-
// It appears necessary to initialize the browser view by adding it to a window and setting bounds. Otherwise, some streaming sites like Periscope will not load their videos due to RAFs not firing.
90-
// TODO: Is this still necessary with WebContentsView?
91-
win.contentView.removeChildView(view)
92-
offscreenWin.contentView.addChildView(view)
86+
const { view, win } = context
87+
win.contentView.addChildView(view, 0) // Insert below background (so hidden by background)
9388
view.setBounds(win.getBounds())
9489
},
9590

9691
positionView: ({ context }) => {
97-
const { pos, view, win, offscreenWin } = context
92+
const { pos, view, win } = context
9893

9994
if (!pos) {
10095
return
10196
}
10297

103-
offscreenWin.contentView.removeChildView(view)
104-
win.contentView.addChildView(view, 1) // Insert at index 1 above default view and so overlay remains on top
98+
win.contentView.addChildView(view, win.contentView.children.length - 2) // Insert below overlay but above background
10599
view.setBounds(pos)
106100
},
107101
},
@@ -147,24 +141,16 @@ const viewStateMachine = setup({
147141
} else {
148142
wc.loadURL(content.url)
149143
}
150-
151-
try {
152-
// Force page visibility
153-
wc.capturePage(undefined, { stayAwake: true })
154-
} catch (err) {
155-
console.warn('Error calling capturePage:', err)
156-
}
157144
},
158145
),
159146
},
160147
}).createMachine({
161148
id: 'view',
162149
initial: 'empty',
163-
context: ({ input: { id, view, win, offscreenWin } }) => ({
150+
context: ({ input: { id, view, win } }) => ({
164151
id,
165152
view,
166153
win,
167-
offscreenWin,
168154
pos: null,
169155
content: null,
170156
options: null,

0 commit comments

Comments
 (0)