Skip to content

Commit

Permalink
Merge pull request #2 from Lt-Mayonesa/feature/cosure-compile
Browse files Browse the repository at this point in the history
Compile with google's closure compile
  • Loading branch information
lt-mayonesa authored Mar 30, 2019
2 parents 40216ca + 2bebbbc commit 64353af
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 77 deletions.
28 changes: 21 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ language: node_js
node_js:
- 8

addons:
apt:
update: true
packages:
- jq

cache:
directories:
- node_modules

install:
- npm install esdoc esdoc-standard-plugin esdoc-ecmascript-proposal-plugin karma karma-jasmine karma-firefox-launcher karma-chrome-launcher jasmine-core karma-coverage
- npm install esdoc esdoc-standard-plugin esdoc-ecmascript-proposal-plugin karma karma-jasmine karma-firefox-launcher karma-chrome-launcher jasmine-core karma-coverage google-closure-compiler

before_script:
- export DISPLAY=:99.0
Expand All @@ -18,11 +24,19 @@ script:

before_deploy:
- ./node_modules/.bin/esdoc
- ./build.sh $TRAVIS_TAG

deploy:
provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN # Set in travis-ci.org dashboard
local_dir: docs
on:
branch: master
- provider: pages
skip_cleanup: true
github_token: $GITHUB_TOKEN # Set in travis-ci.org dashboard
local_dir: docs
on:
branch: master
- provider: releases
api_key: $GITHUB_TOKEN
file_glob: true
file: browser-mpris2-*.zip
skip_cleanup: true
on:
tags: true
49 changes: 49 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
# Compile all javascript source codes into dist/ folder

out="extension/"
lang_out="ECMASCRIPT_2015"

function title() {
green="\e[32m"
fin="\e[0m"
echo -e "\n${green}$1${fin}"
}

title "Step 1: Base Scripts"
npx google-closure-compiler --js='src/main/**.js' --js_output_file="${out}base.js" --language_out=${lang_out}
echo "Compiled all files in src/media into ${out}base.js ✓";

title "Step 2: Provider Scripts"
for filename in src/providers/*.js; do
echo "↳ Compiling $filename"
name=$(basename ${filename})
npx google-closure-compiler --js="$filename" --js_output_file="${out}providers/$name" --language_out=${lang_out}
done
echo "Compiled all providers into ${out}providers/ ✓"

title "Step 3: Init Script"
npx google-closure-compiler --js='src/init.js' --js_output_file="${out}init.js" --language_out=${lang_out}
echo "Compiled src/init.js into ${out}init.js ✓"

title "Step 4: Background Script"
npx google-closure-compiler --js='background.js' --js_output_file="${out}background.js" --language_out=${lang_out}
echo "Compiled background.js into ${out}background.js ✓"

title "Step 5: Manifest"
# replace first and last content script js with base.js and init.js respectively
cat manifest.json | \
jq '.content_scripts[0].js = ["base.js"]' | \
jq '.content_scripts[-1].js = ["init.js"]' \
> ${out}manifest.json
# replace all instances of src/ with empty string
sed -i -e 's,src/,,g' ${out}manifest.json
echo "Generated ${out}manifest.json ✓"

# Compress extension and native to a release zip
title "Step 6: Zip Release"
zip -r "browser-mpris2-$1.zip" ${out} native/
echo "Created realease .zip for version $1"

title "DONE ✓"
exit 0;
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"name": "browser-mpris2",
"description": "Implements the MPRIS2 interface for Chrome and Firefox",
"version": "0.2",
"version": "0.2.1",

"background": {
"scripts": ["background.js"],
Expand Down
35 changes: 0 additions & 35 deletions native/chrome-mpris2
Original file line number Diff line number Diff line change
Expand Up @@ -412,41 +412,6 @@ class Browser(MediaPlayer2):
self.CanGoPrevious = False


@inheritdocstring
class SoundCloud(MediaPlayer2):
def __init__(self, conn, name, tabid):
super().__init__(conn, name, tabid)

self.CanQuit = True
self.CanRaise = True
self.CanSetFullscreen = False
self.HasTrackList = False
self.SupportedMimeTypes = []
self.SupportedUriSchemes = ["http", "https"]

self.Fullscreen = False
self.LoopStatus = "None"
self.Metadata = {}

self.PlaybackStatus = "Stopped"
self.Rate = 1
self.Shuffle = False
self.Volume = 1

self.Identity = "soundcloud"
self.CanControl = True
self.CanPlay = True
self.CanPause = True
self.CanSeek = True
self.CanSetFullscreen = False

self.MinimumRate = 1
self.MaximumRate = 1

self.CanGoNext = False
self.CanGoPrevious = False


players = {
"browser": Browser
}
Expand Down
13 changes: 8 additions & 5 deletions src/main/globals.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* @type {Object}
* @enum {string}
* @property {string} CHANGE=changed - whether a mrpis2 property has changed
* @property {string} RETURN=return - if we are returning an expected value
* @property {string} SEEK=seeked - seeking
Expand All @@ -15,7 +15,7 @@ const MessageType = {

/**
*
* @constant {Object}
* @enum {string}
* @property {string} GET=Get - request a property from the client
* @property {string} SET=Set - request to set a property in the client
* @property {string} PLAY=Play - request to start playing the current media
Expand All @@ -42,7 +42,7 @@ const MessageMethod = {

/**
*
* @constant {Object}
* @enum {string}
* @property {string} POSITION=Position - the time of playback
* @property {string} RATE=Rate - the speed rate of playback
* @property {string} VOLUME=Volume - the volume of playback
Expand All @@ -66,7 +66,7 @@ const MessageProperty = {
* <b>PLAYLIST</b> looping should be implemented by provider
*
*
* @constant {Object}
* @enum {string}
* @property {string} NONE=None - default playback
* @property {string} TRACK=Track - playback will loop current track
* @property {string} PLAYLIST=Playlist - playback will loop current playlist
Expand All @@ -83,10 +83,12 @@ const LoopStatus = {
* @constant {Object}
* @property {string} PLAYING=Playing - the media is playing
* @property {string} PAUSED=Paused - the media is paused
* @property {string} STOPPED=Stopped - the media is stopped
*/
const PlaybackStatus = {
PLAYING: 'Playing',
PAUSED: 'Paused'
PAUSED: 'Paused',
STOPPED: 'Stopped'
};

/**
Expand All @@ -113,4 +115,5 @@ const PlaybackStatus = {
* @property {number} [Rate] - the playback speed of the media
* @property {Metadata} [Metadata] - the media specific information
*/
let Payload;

22 changes: 11 additions & 11 deletions src/main/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ class Host {
*/
this.source = 'browser';

this.port.onMessage.addListener((r, s, sr) => this.messageListener(r, s, sr));
this.port.onMessage.addListener((r, s, sr) => this.messageListener(r));
}

/**
* Send a message to host app
*
* @param {MessageType} type
* @param {Object} [payload]
* @param {Object|number} [payload]
*/
sendMessage (type, payload) {
this.port.postMessage({
Expand All @@ -61,7 +61,7 @@ class Host {
change () {
if (this.playback.activePlayer) {
let payload = this.carrier.requestPayload(this.playback);
if (Object.keys(payload).length)
if (Object.keys(payload || {}).length)
this.sendMessage(
MessageType.CHANGE,
payload
Expand All @@ -82,7 +82,7 @@ class Host {
/**
*
* @param {MessageMethod} method
* @param {Object} args
* @param {*} args
*/
return (method, args) {
this.port.postMessage({
Expand Down Expand Up @@ -142,12 +142,12 @@ class Host {
*
* @param {string} _ - org.mpris.MediaPlayer2.Player
* @param {MessageProperty} propName - property that should be returned
* @returns {number}
* @returns {number|void}
*/
get (_, propName) {
switch (propName) {
case MessageProperty.POSITION:
return this.playback.getPosition();
return this.playback.getPosition() || 0;
}
}

Expand All @@ -157,24 +157,24 @@ class Host {
*
* @param {string} _ - org.mpris.MediaPlayer2.Player
* @param {MessageProperty} propName - property to set
* @param {*} newValue - depends on the property to set
* @param {number|LoopStatus|boolean} [newValue] - depends on the property to set
*/
set (_, propName, newValue) {
switch (propName) {
case MessageProperty.RATE:
this.playback.setRate(newValue);
this.playback.setRate(Number(newValue));
break;

case MessageProperty.VOLUME:
this.playback.setVolume(newValue);
this.playback.setVolume(Number(newValue));
break;

case MessageProperty.SHUFFLE:
this.playback.setShuffle(newValue);
this.playback.setShuffle(Boolean(newValue));
break;

case MessageProperty.LOOP_STATUS:
this.playback.setLoopStatus(newValue);
this.playback.setLoopStatus(Object.values(LoopStatus).find(e => e === newValue));
break;

case MessageProperty.FULL_SCREEN:
Expand Down
4 changes: 2 additions & 2 deletions src/main/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class Page {
*/
checkForMediaElements () {
this.document.querySelectorAll('video,audio')
.forEach(player => page.registerPlayer(player));
.forEach(player => this.registerPlayer(player));
}

/**
Expand All @@ -174,7 +174,7 @@ class Page {
/**
* Get the page's title
*
* @returns {string}
* @returns {null|string}
*/
getTitle () {
return this.document.title;
Expand Down
8 changes: 4 additions & 4 deletions src/main/playback.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Playback {

/**
* Get the volume of playback
* @returns {number}
* @returns {null|number}
*/
getVolume () {
return this.activePlayer && this.activePlayer.getVolume();
Expand All @@ -66,7 +66,7 @@ class Playback {

/**
* Get the rate of playback
* @returns {number}
* @returns {null|number}
*/
getRate () {
return this.activePlayer && this.activePlayer.getRate();
Expand Down Expand Up @@ -186,7 +186,7 @@ class Playback {
/**
* **COMMAND** Get active player's position
*
* @returns {number}
* @returns {null|number}
*/
getPosition () {
return this.activePlayer !== null ? this.activePlayer.getPosition() : null;
Expand Down Expand Up @@ -215,7 +215,7 @@ class Playback {
/**
* Get the identity of playback, by default it is the site's domain
*
* @returns {string}
* @returns {null|string}
*/
getIdentity () {
return this.activePlayer && this.activePlayer.getSiteDomain();
Expand Down
Loading

0 comments on commit 64353af

Please sign in to comment.