Skip to content

Commit

Permalink
preliminary Gnome 45 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Mershl committed Oct 7, 2023
1 parent 2a39808 commit d1378ad
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 61 deletions.
21 changes: 14 additions & 7 deletions [email protected]/dbus.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@
*/

// No translatable strings in this file.
const { Gio, GLib, GObject, Gtk, Meta, Shell, St } = imports.gi;

const { activateWindow } = imports.ui.main;

const UUID = imports.misc.extensionUtils.getCurrentExtension().metadata.uuid;
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import Gtk from 'gi://Gtk';
import Meta from 'gi://Meta';
import Shell from 'gi://Shell';
import St from 'gi://St';

import { activateWindow } from 'resource:///org/gnome/shell/ui/main.js';
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';

const UUID = "[email protected]";
const MPRIS_PREFIX = 'org.mpris.MediaPlayer2.';
// See https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html#Simple-Type:Track_Id
const NO_TRACK_PATH = '/org/mpris/MediaPlayer2/TrackList/NoTrack';
Expand Down Expand Up @@ -364,14 +371,14 @@ function parseMetadata(metadata, playerName) {
return [obj_id, cover_url, artist, title, mimetype_icon];
}

function logMyError(error) {
export function logMyError(error) {
// Cancelling counts as an error don't spam the logs.
if (!error.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) {
logError(error, `Extension ${UUID}`);
}
}

var DBusProxyHandler = GObject.registerClass({
export var DBusProxyHandler = GObject.registerClass({
GTypeName: 'DBusProxyHandler',
Signals: {
'add-player': {
Expand Down
50 changes: 23 additions & 27 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,36 @@
*/

// No translatable strings in this file.
const Panel = imports.ui.main.panel;
import { panel } from 'resource:///org/gnome/shell/ui/main.js';

const stockMpris = Panel.statusArea.dateMenu._messageList._mediaSection;
const stockMpris = panel.statusArea.dateMenu._messageList._mediaSection;
const shouldShow = stockMpris._shouldShow;

const { MprisIndicatorButton } = imports.misc.extensionUtils.getCurrentExtension().imports.widgets;
import { MprisIndicatorButton } from './widgets.js';

const ROLE = 'mprisindicatorbutton';

function init(extensionMeta) {
let localeDir = extensionMeta.dir.get_child('locale');
let localePath = localeDir.query_exists(null) ? localeDir.get_path() : imports.misc.config.LOCALEDIR;
imports.gettext.bindtextdomain(ROLE, localePath);
}

function enable() {
if (!Panel.statusArea[ROLE]) {
stockMpris.visible = false;
stockMpris._shouldShow = () => false;
Panel.addToStatusArea(ROLE, new MprisIndicatorButton());
export default class MprisIndicatorButtonExtension {
enable() {
if (!panel.statusArea[ROLE]) {
stockMpris.visible = false;
stockMpris._shouldShow = () => false;
panel.addToStatusArea(ROLE, new MprisIndicatorButton());
}
}
}

function disable() {
let indicator = Panel.statusArea[ROLE];
if (indicator) {
stockMpris._shouldShow = shouldShow;
stockMpris.visible = stockMpris._shouldShow();
// Avoid - 'JS ERROR: Exception in callback for signal:
// open-state-changed: Error: Argument 'descendant' (type interface) may not be null
// _onMenuSet/indicator.menu._openChangedId'
// When the Shell disables extensions on screen lock/blank and the menu happens to be open.
// If you connect a signal you should disconnect it... GNOME devs...
indicator.menu.disconnect(indicator.menu._openChangedId);
indicator.destroy();
disable() {
let indicator = panel.statusArea[ROLE];
if (indicator) {
stockMpris._shouldShow = shouldShow;
stockMpris.visible = stockMpris._shouldShow();
// Avoid - 'JS ERROR: Exception in callback for signal:
// open-state-changed: Error: Argument 'descendant' (type interface) may not be null
// _onMenuSet/indicator.menu._openChangedId'
// When the Shell disables extensions on screen lock/blank and the menu happens to be open.
// If you connect a signal you should disconnect it... GNOME devs...
indicator.menu.disconnect(indicator.menu._openChangedId);
indicator.destroy();
}
}
}
19 changes: 12 additions & 7 deletions [email protected]/indicatorToolTip.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
*/

// No translatable strings in this file.
const { Atk, Clutter, GObject, St } = imports.gi;
import Atk from 'gi://Atk';
import Clutter from 'gi://Clutter';
import GObject from 'gi://GObject';
import St from 'gi://St';

const LayoutManager = imports.ui.main.layoutManager;
import { layoutManager } from 'resource:///org/gnome/shell/ui/main.js';

const TOOL_TIP_HOVER_DELAY = imports.ui.dash.DASH_ITEM_HOVER_TIMEOUT;
const TOOL_TIP_ANIMATION_TIME = imports.ui.boxpointer.POPUP_ANIMATION_TIME;
import * as Dash from 'resource:///org/gnome/shell/ui/dash.js';
const TOOL_TIP_HOVER_DELAY = Dash.DASH_ITEM_HOVER_TIMEOUT;
import * as BoxPointer from 'resource:///org/gnome/shell/ui/boxpointer.js';
const TOOL_TIP_ANIMATION_TIME = BoxPointer.POPUP_ANIMATION_TIME;

const DEFAULT_SYNC_CREATE_PROP_FLAGS = GObject.BindingFlags.DEFAULT | GObject.BindingFlags.SYNC_CREATE;

Expand Down Expand Up @@ -57,7 +62,7 @@ const ToolTipConstraint = GObject.registerClass({
}
// Get the monitor the the indicator is on and try to tell
// which side it's on.
let monitor = LayoutManager.findMonitorForActor(indicator);
let monitor = layoutManager.findMonitorForActor(indicator);
let [x, y] = indicator.get_transformed_position();
if (vertical) {
side = Math.floor(x) == monitor.x ? St.Side.LEFT : St.Side.RIGHT;
Expand Down Expand Up @@ -128,7 +133,7 @@ const ToolTipConstraint = GObject.registerClass({
// It is meant to make it easy for others to extend and use along
// with ToolTipConstraint (which should really never need to be touched)
// to add tooltips to their Indicators if they like.
var ToolTipBase = GObject.registerClass({
export var ToolTipBase = GObject.registerClass({
GTypeName: 'ToolTipBase',
GTypeFlags: GObject.TypeFlags.ABSTRACT,
Properties: {
Expand Down Expand Up @@ -260,7 +265,7 @@ var ToolTipBase = GObject.registerClass({

this.pushSignal(this.indicator, 'destroy', this.onIndicatorDestroy.bind(this));

LayoutManager.addTopChrome(this, {affectsInputRegion: false});
layoutManager.addTopChrome(this, {affectsInputRegion: false});
}

get text() {
Expand Down
2 changes: 1 addition & 1 deletion [email protected]/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"name": "Mpris Indicator Button with title",
"description": "A full featured MPRIS indicator.",
"original-author": "[email protected]",
"shell-version": ["3.36", "3.38", "40", "41", "42", "43", "44"],
"shell-version": ["45"],
"url": "https://github.com/jylertones/gnome-shell-extension-mpris-indicator-button/"
}
2 changes: 1 addition & 1 deletion [email protected]/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const _ = imports.gettext.domain('mprisindicatorbutton').gettext;

// TRANSLATORS: These are all of the translatable strings in this extension.
// Any new translatable strings will be added to the end as to not break previous translations.
var TRANSLATED = {
export var TRANSLATED = {
// TRANSLATORS: Non proper noun part of the extension's name.
// User visible string and used by accessibility software.
get ['Indicator Button']() {return _("Indicator Button");},
Expand Down
39 changes: 21 additions & 18 deletions [email protected]/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,33 @@
*/

// No translatable strings in this file.
const { Atk, Clutter, Gio, GObject, Gtk, St } = imports.gi;

// const { AggregateLayout } = imports.ui.panel;
const { Button } = imports.ui.panelMenu;
const {
import Atk from 'gi://Atk';
import Clutter from 'gi://Clutter';
import Gio from 'gi://Gio';
import GObject from 'gi://GObject';
import Gtk from 'gi://Gtk';
import St from 'gi://St';

import { Button } from 'resource:///org/gnome/shell/ui/panelMenu.js';
import {
PopupBaseMenuItem,
PopupSubMenuMenuItem,
PopupMenuSection,
PopupSeparatorMenuItem,
Ornament,
} = imports.ui.popupMenu;
const { Slider } = imports.ui.slider;
} from 'resource:///org/gnome/shell/ui/popupMenu.js';
import { Slider } from 'resource:///org/gnome/shell/ui/slider.js';

const Me = imports.misc.extensionUtils.getCurrentExtension();
const {
import {
DBusProxyHandler,
logMyError,
} = imports.misc.extensionUtils.getCurrentExtension().imports.dbus;
const {
} from './dbus.js';
import {
ToolTipBase,
} = imports.misc.extensionUtils.getCurrentExtension().imports.indicatorToolTip;
const {
} from './indicatorToolTip.js';
import {
TRANSLATED,
} = imports.misc.extensionUtils.getCurrentExtension().imports.translations;
} from './translations.js';
const DEFAULT_SYNC_CREATE_PROP_FLAGS =
GObject.BindingFlags.DEFAULT | GObject.BindingFlags.SYNC_CREATE;
const MOUSE_BUTTON_BACK = 8;
Expand Down Expand Up @@ -506,8 +509,8 @@ const MainItem = GObject.registerClass(
class MainItem extends PopupBaseMenuItem {
_init() {
super._init();
this._ornamentLabel.y_align = Clutter.ActorAlign.CENTER;
this._ornamentLabel.y_expand = true;
// this._ornamentLabel.y_align = Clutter.ActorAlign.CENTER;
// this._ornamentLabel.y_expand = true;
this._signals = [];
this.pushSignal(this, "destroy", this._onDestroy.bind(this));
}
Expand Down Expand Up @@ -548,7 +551,7 @@ const MediaControlsItem = GObject.registerClass(
class MediaControlsItem extends PopupBaseMenuItem {
_init() {
super._init();
this._ornamentLabel.destroy();
// this._ornamentLabel.destroy();
this.add_style_class_name("media-controls-item");
this._signals = [];
this.accessible_name = TRANSLATED["Media Controls"];
Expand Down Expand Up @@ -1547,7 +1550,7 @@ class Player extends PopupMenuSection {
}
}

var MprisIndicatorButton = GObject.registerClass(
export var MprisIndicatorButton = GObject.registerClass(
{
GTypeName: "MprisIndicatorButton",
Signals: {
Expand Down

0 comments on commit d1378ad

Please sign in to comment.