Skip to content

Commit

Permalink
macos only
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Osbourne committed Jul 11, 2024
1 parent d3d57c7 commit 3b6273f
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 13 deletions.
26 changes: 18 additions & 8 deletions integration-test/playwright/page-objects/duckplayer-overlays.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,26 @@ export class DuckplayerOverlays {
}

async watchInDuckPlayer () {
const failure = new Promise(resolve => {
this.page.context().on('requestfailed', f => {
if (f.url().startsWith('duck')) resolve(f.url())
})
})
const action = () => this.page.getByRole('link', { name: 'Watch in Duck Player' }).click()

await this.page.getByRole('link', { name: 'Watch in Duck Player' }).click()
await this.build.switch({
'apple-isolated': async () => {
await action()
await this.duckPlayerLoadsFor('123')
},
windows: async () => {
const failure = new Promise(resolve => {
this.page.context().on('requestfailed', f => {
if (f.url().startsWith('duck')) resolve(f.url())
})
})

await action()

// assert the page tried to navigate to duck player
expect(await failure).toEqual('duck://player/123')
// assert the page tried to navigate to duck player
expect(await failure).toEqual('duck://player/123')
}
})
}

async watchHere () {
Expand Down
2 changes: 1 addition & 1 deletion integration-test/playwright/type-helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class Build {
}
return fn()
}
throw new Error('missing impl for that')
throw new Error('missing impl for that on platform: ' + this.name)
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/features/duck-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export default class DuckPlayerFeature extends ContentFeature {

const comms = new DuckPlayerOverlayMessages(this.messaging)
const env = new Environment({
debug: args.debug
debug: args.debug,
platform: this.platform
})

if (overlaysEnabled) {
Expand Down
6 changes: 5 additions & 1 deletion src/features/duckplayer/overlay-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ function assertCustomEvent (event) {
export class Pixel {
/**
* A list of known pixels
* @param {{name: "overlay"} | {name: "play.use", remember: "0" | "1"} | {name: "play.do_not_use", remember: "0" | "1"}} input
* @param {{name: "overlay"}
* | {name: "play.use", remember: "0" | "1"}
* | {name: "play.use.thumbnail"}
* | {name: "play.do_not_use", remember: "0" | "1"}} input
*/
constructor (input) {
this.input = input
Expand All @@ -134,6 +137,7 @@ export class Pixel {
params () {
switch (this.input.name) {
case 'overlay': return {}
case 'play.use.thumbnail': return {}
case 'play.use':
case 'play.do_not_use': {
return { remember: this.input.remember }
Expand Down
6 changes: 6 additions & 0 deletions src/features/duckplayer/overlays.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ export class Environment {

/**
* @param {object} params
* @param {import('../../utils.js').Platform} params.platform
* @param {boolean|null|undefined} [params.debug]
*/
constructor (params) {
this.debug = Boolean(params.debug)
this.platform = params.platform
}

/**
Expand Down Expand Up @@ -185,4 +187,8 @@ export class Environment {
isTestMode () {
return this.debug === true
}

get opensVideoOverlayLinksViaMessage () {
return this.platform.name !== 'windows'
}
}
6 changes: 5 additions & 1 deletion src/features/duckplayer/thumbnails.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import { SideEffects, VideoParams } from './util.js'
import { IconOverlay } from './icon-overlay.js'
import { Environment } from './overlays.js'
import { OpenInDuckPlayerMsg } from './overlay-messages.js'
import { OpenInDuckPlayerMsg, Pixel } from './overlay-messages.js'

/**
* @typedef ThumbnailParams
Expand Down Expand Up @@ -92,6 +92,10 @@ export class Thumbnails {
// create the icon & append it to the page
const icon = new IconOverlay()
icon.appendHoverOverlay((href) => {
if (this.environment.opensVideoOverlayLinksViaMessage) {
this.messages.sendPixel(new Pixel({ name: 'play.use.thumbnail' }))
}

this.messages.openDuckPlayer(new OpenInDuckPlayerMsg({ href }))
})

Expand Down
9 changes: 8 additions & 1 deletion src/features/duckplayer/video-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ export class VideoOverlay {
* But, if the checkbox was not checked, then we want to keep the state
* as 'alwaysAsk'
*
* @param {boolean} remember
* @param {VideoParams} params
*/
userOptIn (remember, params) {
/** @type {import("../duck-player.js").UserValues['privatePlayerMode']} */
Expand All @@ -285,7 +287,12 @@ export class VideoOverlay {
privatePlayerMode
}
this.messages.setUserValues(outgoing)
.then(() => this.environment.setHref(params.toPrivatePlayerUrl()))
.then(() => {
if (this.environment.opensVideoOverlayLinksViaMessage) {
return this.messages.openDuckPlayer(new OpenInDuckPlayerMsg({ href: params.toPrivatePlayerUrl() }))
}
return this.environment.setHref(params.toPrivatePlayerUrl())
})
.catch(e => console.error('error setting user choice', e))
}

Expand Down

0 comments on commit 3b6273f

Please sign in to comment.