/usr/share/gnome-shell/extensions/mediaplayer@patapon.info/util.js is in gnome-shell-extension-mediaplayer 3.5-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | /* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
/* jshint esnext: true */
/* jshint -W097 */
/* global imports: false */
/**
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
const Mainloop = imports.mainloop;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
const Pango = imports.gi.Pango;
const Tweener = imports.ui.tweener;
function setCoverIconAsync(icon, coverUrl, fallback_icon_name, dontAnimate, delay) {
fallback_icon_name = (fallback_icon_name || 'audio-x-generic-symbolic');
if (coverUrl) {
let file = Gio.File.new_for_uri(coverUrl);
file.load_contents_async(null, function(source, result) {
try {
let bytes = source.load_contents_finish(result)[1];
let newIcon = Gio.BytesIcon.new(bytes);
if (!newIcon.equal(icon.gicon)) {
if (dontAnimate) {
icon.gicon = newIcon;
}
else if (delay) {
Mainloop.timeout_add(250, function() {
animateChange(icon, 'gicon', newIcon);
return false;
});
}
else {
animateChange(icon, 'gicon', newIcon);
}
}
}
catch(err) {
if (icon.icon_name != fallback_icon_name) {
if (dontAnimate) {
icon.icon_name = fallback_icon_name;
}
else if (delay) {
Mainloop.timeout_add(250, function() {
animateChange(icon, 'icon_name', fallback_icon_name);
return false;
});
}
else {
animateChange(icon, 'icon_name', fallback_icon_name);
}
}
}
});
}
else if (icon.icon_name != fallback_icon_name) {
if (dontAnimate) {
icon.icon_name = fallback_icon_name;
}
else {
animateChange(icon, 'icon_name', fallback_icon_name);
}
}
}
function animateChange(actor, prop, value) {
Tweener.addTween(actor, {
opacity: 0,
time: 0.125,
onComplete: function() {
actor[prop] = value;
Tweener.addTween(actor, {
opacity: 255,
time: 0.125
});
}
});
}
function getPlayerSymbolicIcon(desktopEntry, fallback) {
if (desktopEntry) {
//The Player's symbolic Icon name *should* be it's
//Desktop Entry + '-symbolic'.
//For example, Pithos:
//Desktop Entry - 'io.github.Pithos'
//Symbolic Icon Name - 'io.github.Pithos-symbolic'
let possibleIconName = desktopEntry + '-symbolic';
let currentIconTheme = Gtk.IconTheme.get_default();
let IconExists = currentIconTheme.has_icon(possibleIconName);
if (IconExists) {
return possibleIconName;
}
}
return fallback || 'audio-x-generic-symbolic';
}
function parseMetadata(metadata, state) {
// Pragha sends a metadata dict with one value on stop
if (!metadata || Object.keys(metadata).length < 2) {
metadata = {};
}
state.trackUrl = metadata["xesam:url"] ? metadata["xesam:url"].unpack() : "";
state.trackArtist = metadata["xesam:artist"] ? metadata["xesam:artist"].deep_unpack().join('/') : "";
state.trackArtist = metadata["rhythmbox:streamTitle"] ? metadata["rhythmbox:streamTitle"].unpack() : state.trackArtist;
state.trackAlbum = metadata["xesam:album"] ? metadata["xesam:album"].unpack() : "";
state.trackTitle = metadata["xesam:title"] ? metadata["xesam:title"].unpack() : "";
state.trackLength = metadata["mpris:length"] ? Math.round(metadata["mpris:length"].unpack() / 1000000) : 0;
state.trackObj = metadata["mpris:trackid"] ? metadata["mpris:trackid"].unpack() : "/org/mpris/MediaPlayer2/TrackList/NoTrack";
state.trackCoverUrl = metadata["mpris:artUrl"] ? metadata["mpris:artUrl"].unpack() : "";
state.trackRating = metadata["xesam:userRating"] ? parseInt(metadata["xesam:userRating"].unpack() * 5) : 'no rating';
state.trackRating = metadata["pithos:rating"] ? metadata["pithos:rating"].unpack() : state.trackRating;
state.isRhythmboxStream = metadata["rhythmbox:streamTitle"] ? true : false;
}
var compileTemplate = function(template, playerState) {
let escapedText = template.replace(/{(\w+)\|?([^}]*)}/g, function(match, fieldName, appendText) {
let text = "";
if (playerState[fieldName] && playerState[fieldName].toString() !== "") {
text = playerState[fieldName].toString() + appendText;
text = GLib.markup_escape_text(text, -1);
}
return text;
});
//Validate Pango markup.
try {
let validMarkup = Pango.parse_markup(escapedText, -1, '')[0];
if (!validMarkup) {
escapedText = 'Invalid Syntax';
}
}
catch(err) {
escapedText = 'Invalid Syntax';
}
return escapedText;
};
var _extends = function(object1, object2) {
Object.getOwnPropertyNames(object2).forEach(function(name, index) {
let desc = Object.getOwnPropertyDescriptor(object2, name);
if (! desc.writable)
Object.defineProperty(object1.prototype, name, desc);
else {
object1.prototype[name] = object2[name];
}
});
};
|