mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-29 23:32:04 +02:00
Initial MPRIS support
Implement a working MPRIS DBus connection with a separate API to control it. Right now only player playback state is reflected and Play/Pause/PlayPause calls work.
This commit is contained in:
53
src/misc.js
53
src/misc.js
@@ -1,4 +1,4 @@
|
||||
const { Gio, Gdk, Gtk } = imports.gi;
|
||||
const { Gio, GLib, Gdk, Gtk } = imports.gi;
|
||||
const Debug = imports.src.debug;
|
||||
|
||||
const { debug } = Debug;
|
||||
@@ -39,6 +39,57 @@ function getClapperVersion()
|
||||
: '';
|
||||
}
|
||||
|
||||
function getClapperThemeIconUri()
|
||||
{
|
||||
const display = Gdk.Display.get_default();
|
||||
if(!display) return null;
|
||||
|
||||
const iconTheme = Gtk.IconTheme.get_for_display(display);
|
||||
if(!iconTheme || !iconTheme.has_icon(appId))
|
||||
return null;
|
||||
|
||||
const iconPaintable = iconTheme.lookup_icon(appId, null, 256, 1,
|
||||
Gtk.TextDirection.NONE, Gtk.IconLookupFlags.FORCE_REGULAR
|
||||
);
|
||||
const iconFile = iconPaintable.get_file();
|
||||
if(!iconFile) return null;
|
||||
|
||||
const iconPath = iconFile.get_path();
|
||||
if(!iconPath) return null;
|
||||
|
||||
let substractName = iconPath.substring(
|
||||
iconPath.indexOf('/icons/') + 7, iconPath.indexOf('/scalable/')
|
||||
);
|
||||
if(!substractName || substractName.includes('/'))
|
||||
return null;
|
||||
|
||||
substractName = substractName.toLowerCase();
|
||||
const postFix = (substractName === iconTheme.theme_name.toLowerCase())
|
||||
? substractName
|
||||
: 'hicolor';
|
||||
const cacheIconName = `clapper-${postFix}.svg`;
|
||||
|
||||
/* We need to have this icon placed in a folder
|
||||
* accessible from both app runtime and gnome-shell */
|
||||
const expectedFile = Gio.File.new_for_path(
|
||||
GLib.get_user_cache_dir() + `/${appId}/icons/${cacheIconName}`
|
||||
);
|
||||
if(!expectedFile.query_exists(null)) {
|
||||
debug('no cached icon file');
|
||||
|
||||
const dirPath = expectedFile.get_parent().get_path();
|
||||
GLib.mkdir_with_parents(dirPath, 493); // octal 755
|
||||
iconFile.copy(expectedFile,
|
||||
Gio.FileCopyFlags.TARGET_DEFAULT_PERMS, null, null
|
||||
);
|
||||
debug(`icon copied to cache dir: ${cacheIconName}`);
|
||||
}
|
||||
const iconUri = expectedFile.get_uri();
|
||||
debug(`using cached clapper icon uri: ${iconUri}`);
|
||||
|
||||
return iconUri;
|
||||
}
|
||||
|
||||
function loadCustomCss()
|
||||
{
|
||||
const clapperPath = getClapperPath();
|
||||
|
@@ -20,14 +20,18 @@ class ClapperPlayer extends GstClapper.Clapper
|
||||
const glsinkbin = Gst.ElementFactory.make('glsinkbin', null);
|
||||
glsinkbin.sink = gtk4plugin.video_sink;
|
||||
|
||||
const dispatcher = new GstClapper.ClapperGMainContextSignalDispatcher();
|
||||
const renderer = new GstClapper.ClapperVideoOverlayVideoRenderer({
|
||||
video_sink: glsinkbin
|
||||
});
|
||||
|
||||
super._init({
|
||||
signal_dispatcher: dispatcher,
|
||||
video_renderer: renderer
|
||||
signal_dispatcher: new GstClapper.ClapperGMainContextSignalDispatcher(),
|
||||
video_renderer: new GstClapper.ClapperVideoOverlayVideoRenderer({
|
||||
video_sink: glsinkbin,
|
||||
}),
|
||||
mpris: new GstClapper.ClapperMpris({
|
||||
own_name: `org.mpris.MediaPlayer2.${Misc.appName}`,
|
||||
id_path: '/' + Misc.appId.replace(/\./g, '/'),
|
||||
identity: Misc.appName,
|
||||
desktop_entry: Misc.appId,
|
||||
default_art_url: Misc.getClapperThemeIconUri(),
|
||||
}),
|
||||
});
|
||||
|
||||
this.widget = gtk4plugin.video_sink.widget;
|
||||
|
Reference in New Issue
Block a user