Skip to content

Commit

Permalink
Initial integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jiri-janousek committed Nov 28, 2020
1 parent 6a168af commit 056751e
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 11 deletions.
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
jobs:
build:
machine: # for docker --privileged
image: circleci/classic:latest
working_directory: ~/workdir
steps:
- checkout
- run:
name: Install deps & check project
command: wget https://raw.githubusercontent.com/tiliado/nuvolasdk/master/scripts/circleci.sh && chmod a+x circleci.sh && ./circleci.sh
- store_artifacts:
path: ~/workdir/keep
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pretzel Change Log
======================

1.1 - unreleased
1.0 - unreleased
----------------

* Initial release.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Integration of Pretzel into your linux desktop via
Support
-------

Follow [Bug reporting guidelines](https://github.com/tiliado/nuvolaruntime/wiki/Bug-Reporting-Guidelines).
- Use [Nuvola Runtime issue tracker](https://github.com/tiliado/nuvolaruntime/issues/new/choose)
to report bugs, ask questions or suggest features.
- Follow [Bug reporting guidelines](https://github.com/tiliado/nuvolaruntime/wiki/Bug-Reporting-Guidelines).

Installation
------------
Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env python3
import nuvolasdk
nuvolasdk.gen_makefile("4.18.1")
nuvolasdk.gen_makefile("4.18.0")
85 changes: 79 additions & 6 deletions integrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
'use strict';

(function (Nuvola) {
const PLAY_SVG = 'M16.032 31.584c-8.64 0-15.616-6.976-15.616-15.616S7.392.416 16.032.416s15.552 6.976 15.552 15.616c0 8.576-6.976 15.552-15.552 15.552zm0-30.08c-8.064 0-14.528 6.464-14.528 14.528S7.968 30.56 16.032 30.56 30.56 24.096 30.56 16.032c-.064-8.064-6.528-14.528-14.528-14.528zm-3.776 8.992l9.568 5.536-9.568 5.536V10.496M11.168 8.64v14.72l12.672-7.328L11.168 8.64z'
const PAUSE_SVG = 'M16.032 31.584c-8.64 0-15.616-6.976-15.616-15.616S7.392.416 16.032.416s15.552 6.976 15.552 15.616c0 8.576-6.976 15.552-15.552 15.552zm0-30.08c-8.064 0-14.528 6.464-14.528 14.528S7.968 30.56 16.032 30.56 30.56 24.096 30.56 16.032c-.064-8.064-6.528-14.528-14.528-14.528zm-3.776 8.064h1.696v12.864h-1.696V9.568zm5.888 0h1.664v12.864h-1.664V9.568z'

// Create media player component
const player = Nuvola.$object(Nuvola.MediaPlayer)

Expand Down Expand Up @@ -58,28 +61,98 @@

// Extract data from the web page
WebApp.update = function () {
const elms = this._getElements()
const track = {
title: null,
artist: null,
album: null,
artLocation: null,
title: Nuvola.queryText('.hOOKvw span.oKpSL'),
artist: Nuvola.queryAttribute('.hOOKvw p.ZSqOQ', 'title'),
album: Nuvola.queryAttribute('.hOOKvw p.ZSqOQ:last-child', 'title'),
artLocation: Nuvola.queryAttribute('.hOOKvw img.hFdXsU', 'src'),
rating: null
}

player.setTrack(track)
player.setPlaybackState(PlaybackState.UNKNOWN)

let state
if (elms.pause) {
state = PlaybackState.PLAYING
} else if (elms.play) {
state = PlaybackState.PAUSED
} else {
state = PlaybackState.UNKNOWN
}
player.setPlaybackState(state)

player.setCanGoPrev(!!elms.prev)
player.setCanGoNext(!!elms.next)
player.setCanPlay(!!elms.play)
player.setCanPause(!!elms.pause)

// Schedule the next update
setTimeout(this.update.bind(this), 500)
}

// Handler of playback actions
WebApp._onActionActivated = function (emitter, name, param) {
const elms = this._getElements()
switch (name) {
case PlayerAction.Play:
case PlayerAction.TOGGLE_PLAY:
if (elms.play) {
Nuvola.clickOnElement(elms.play)
} else {
Nuvola.clickOnElement(elms.pause)
}
break
case PlayerAction.PLAY:
Nuvola.clickOnElement(elms.play)
break
case PlayerAction.PAUSE:
case PlayerAction.STOP:
Nuvola.clickOnElement(elms.pause)
break
case PlayerAction.PREV_SONG:
Nuvola.clickOnElement(elms.prev)
break
case PlayerAction.NEXT_SONG:
Nuvola.clickOnElement(elms.next)
break
}
}

WebApp._getElements = function () {
// Interesting elements
const elms = {
play: document.querySelector('.hOOKvw button.hrAWUR > svg.jStubB'),
pause: null,
next: document.querySelector('.hOOKvw button.ionnrC > svg.betPcV'),
prev: document.querySelector('.hOOKvw button.ionnrC > svg.cIilyo')
}

if (elms.play) {
const svg = elms.play.firstElementChild.getAttribute('d')
if (svg === PAUSE_SVG) {
elms.pause = elms.play
elms.play = null
} else if (svg !== PLAY_SVG) {
elms.play = null
}
}

for (const key in elms) {
if (elms[key]) {
// Get parent buttons
if (elms[key].tagName == 'svg') {
elms[key] = elms[key].parentElement
}

// Ignore disabled buttons
if (elms[key].disabled) {
elms[key] = null
}
}
}

return elms
}

WebApp.start()
})(this) // function(Nuvola)
5 changes: 3 additions & 2 deletions metadata.in.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "pretzel",
"name": "Pretzel",
"home_url": "https://app.pretzel.rocks",
"home_url": "https://play.pretzel.rocks",
"maintainer_name": "Jiří Janoušek",
"maintainer_link": "https://github.com/fenryxo",
"version_major": 1,
Expand All @@ -17,5 +17,6 @@
"src/icon-xs.svg 16 22 24",
"src/icon-sm.svg 32 48"
]
}
},
"dark_theme": true
}
Binary file added src/webview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 056751e

Please sign in to comment.