This repository has been archived by the owner on Feb 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #322, focus tab on content script failure
Also do a wide-ranging refactor of how services are handled, registered, and run on the content side.
- Loading branch information
Showing
6 changed files
with
190 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
/* globals communicate, helpers */ | ||
/* globals helpers */ | ||
|
||
this.player = (function() { | ||
communicate.register("play", message => { | ||
const button = document.querySelector("button[title='Play']"); | ||
button.click(); | ||
}); | ||
class Player extends helpers.Runner { | ||
action_play() { | ||
const button = document.querySelector("button[title='Play']"); | ||
button.click(); | ||
} | ||
|
||
async action_search({ query, thenPlay }) { | ||
const searchButton = this.querySelector("a[aria-label='Search']"); | ||
searchButton.click(); | ||
const input = await this.waitForSelector(".SearchInputBox input"); | ||
this.setReactInputValue(input, query); | ||
if (thenPlay) { | ||
const player = await this.waitForSelector(".tracklist-play-pause", { | ||
timeout: 2000, | ||
}); | ||
player.click(); | ||
} | ||
} | ||
|
||
communicate.register("search", async message => { | ||
const searchButton = document.querySelector("a[aria-label='Search']"); | ||
searchButton.click(); | ||
const input = await helpers.waitForSelector(".SearchInputBox input"); | ||
helpers.setReactInputValue(input, message.query); | ||
if (message.thenPlay) { | ||
const player = await helpers.waitForSelector(".tracklist-play-pause", { | ||
timeout: 2000, | ||
}); | ||
player.click(); | ||
action_pause() { | ||
const button = document.querySelector("button[title='Pause']"); | ||
button.click(); | ||
} | ||
}); | ||
} | ||
|
||
communicate.register("pause", message => { | ||
const button = document.querySelector("button[title='Pause']"); | ||
button.click(); | ||
}); | ||
Player.register(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,28 @@ | ||
/* globals intents, serviceList, content */ | ||
/* globals intents, serviceList */ | ||
|
||
this.services.spotify = (function() { | ||
class Spotify extends serviceList.Service { | ||
async playQuery(query) { | ||
const tab = await this.getTab(); | ||
await content.lazyInject(tab.id, "/services/spotify/player.js"); | ||
await browser.tabs.sendMessage(tab.id, { | ||
type: "search", | ||
query, | ||
thenPlay: true, | ||
}); | ||
await this.initTab("/services/spotify/player.js"); | ||
await this.callTab("search", { query, thenPlay: true }); | ||
} | ||
|
||
async pause() { | ||
const tab = await this.getTab(); | ||
await content.lazyInject(tab.id, "/services/spotify/player.js"); | ||
await browser.tabs.sendMessage(tab.id, { | ||
type: "pause", | ||
}); | ||
await this.initTab("/services/spotify/player.js"); | ||
await this.callTab("pause"); | ||
} | ||
|
||
async unpause() { | ||
const tab = await this.getTab(); | ||
await content.lazyInject(tab.id, "/services/spotify/player.js"); | ||
await browser.tabs.sendMessage(tab.id, { | ||
type: "play", | ||
}); | ||
await this.initTab("/services/spotify/player.js"); | ||
await this.callTab("unpause"); | ||
} | ||
} | ||
Object.assign(Spotify.prototype, { | ||
name: "spotify", | ||
|
||
Object.assign(Spotify, { | ||
id: "spotify", | ||
title: "Spotify", | ||
baseUrl: "https://open.spotify.com/", | ||
}); | ||
intents.music.register(new Spotify()); | ||
|
||
intents.music.register(Spotify); | ||
})(); |