Update for Gnome Shell 45+
This commit is contained in:
parent
3ed3394a33
commit
66d79cc804
|
@ -23,6 +23,7 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
|
import json
|
||||||
|
|
||||||
from google.auth.transport.requests import Request
|
from google.auth.transport.requests import Request
|
||||||
from google.oauth2.credentials import Credentials
|
from google.oauth2.credentials import Credentials
|
||||||
|
@ -53,7 +54,13 @@ def _initCreds():
|
||||||
creds = flow.run_local_server(port=0)
|
creds = flow.run_local_server(port=0)
|
||||||
# Save the credentials for the next run
|
# Save the credentials for the next run
|
||||||
with open('token.json', 'w') as token:
|
with open('token.json', 'w') as token:
|
||||||
token.write(creds.to_json())
|
data = {}
|
||||||
|
data['refresh_token'] = creds.refresh_token
|
||||||
|
data['client_id'] = creds.client_id
|
||||||
|
data['client_secret'] = creds.client_secret
|
||||||
|
data['token_uri'] = creds.token_uri
|
||||||
|
data['id_token'] = creds.id_token
|
||||||
|
token.write(json.dumps(data))
|
||||||
|
|
||||||
def getUnreadMails():
|
def getUnreadMails():
|
||||||
"""
|
"""
|
||||||
|
@ -69,6 +76,7 @@ def getUnreadMails():
|
||||||
results = service.users().messages().list(userId='me', labelIds=['UNREAD'],\
|
results = service.users().messages().list(userId='me', labelIds=['UNREAD'],\
|
||||||
includeSpamTrash=False, pageToken=pageToken)\
|
includeSpamTrash=False, pageToken=pageToken)\
|
||||||
.execute()
|
.execute()
|
||||||
|
if not 'messages' in results.keys(): continue
|
||||||
threads = threads.union(set([k['threadId'] for k in results['messages']]))
|
threads = threads.union(set([k['threadId'] for k in results['messages']]))
|
||||||
# Loop over all result pages (100 results per page by default)
|
# Loop over all result pages (100 results per page by default)
|
||||||
pageToken = results.get('nextPageToken', '')
|
pageToken = results.get('nextPageToken', '')
|
||||||
|
|
|
@ -43,15 +43,12 @@ class PicturePopup(GenericMonitor):
|
||||||
self.runMainLoop()
|
self.runMainLoop()
|
||||||
|
|
||||||
def display_next_img(self):
|
def display_next_img(self):
|
||||||
filedata = urllib.request.urlopen('https://source.unsplash.com/random')
|
filedata = urllib.request.urlopen('https://picsum.photos/500/500')
|
||||||
# Get redirected URL without parameters
|
|
||||||
url = filedata.url.split('?')[0]
|
|
||||||
filedata = urllib.request.urlopen(url + '?fit=max&width=500&height=500')
|
|
||||||
datatowrite = filedata.read()
|
datatowrite = filedata.read()
|
||||||
with open('/tmp/cat2.jpg', 'wb') as f:
|
with open('/tmp/cat2.jpg', 'wb') as f:
|
||||||
f.write(datatowrite)
|
f.write(datatowrite)
|
||||||
widget = GenericMonitorTextWidget('#%d' % self.imgs_idx, 'color:purple')
|
widget = GenericMonitorTextWidget('#%d' % self.imgs_idx, 'color:purple')
|
||||||
url_widget = GenericMonitorTextWidget(url, 'color:white;font-weight:bold', signals={'on-click':'signal'}) # No name here
|
url_widget = GenericMonitorTextWidget('random_pic', 'color:white;font-weight:bold', signals={'on-click':'signal'}) # No name here
|
||||||
picture_widget = GenericMonitorPictureWidget('/tmp/cat2.jpg', name='NestedWidget', signals={'on-click':'signal'})
|
picture_widget = GenericMonitorPictureWidget('/tmp/cat2.jpg', name='NestedWidget', signals={'on-click':'signal'})
|
||||||
popup = GenericMonitorPopup([url_widget, picture_widget])
|
popup = GenericMonitorPopup([url_widget, picture_widget])
|
||||||
signals = {
|
signals = {
|
||||||
|
|
66
extension.js
66
extension.js
|
@ -29,17 +29,17 @@
|
||||||
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/panel.js
|
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/panel.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const St = imports.gi.St;
|
import * as Extension from 'resource:///org/gnome/shell/extensions/extension.js';
|
||||||
const Gio = imports.gi.Gio;
|
import St from 'gi://St';
|
||||||
const GLib = imports.gi.GLib
|
import Gio from 'gi://Gio';
|
||||||
const Main = imports.ui.main;
|
import GLib from 'gi://GLib';
|
||||||
const Mainloop = imports.mainloop;
|
import Clutter from 'gi://Clutter';
|
||||||
const Clutter = imports.gi.Clutter;
|
import GObject from 'gi://GObject';
|
||||||
const PanelMenu = imports.ui.panelMenu;
|
import Pixbuf from 'gi://GdkPixbuf';
|
||||||
const PopupMenu = imports.ui.popupMenu;
|
import Cogl from 'gi://Cogl';
|
||||||
const GObject = imports.gi.GObject;
|
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
|
||||||
const Pixbuf = imports.gi.GdkPixbuf;
|
import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js';
|
||||||
const Cogl = imports.gi.Cogl;
|
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
|
||||||
|
|
||||||
|
|
||||||
function hashGet(hash, key, defaultValue) {
|
function hashGet(hash, key, defaultValue) {
|
||||||
|
@ -50,7 +50,7 @@ function hashGet(hash, key, defaultValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function log(message) {
|
function log(message) {
|
||||||
global.log('[GenericMontior]', message);
|
console.error('[GenericMontior]', message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -189,7 +189,8 @@ class SignalMgt {
|
||||||
this.button = event.get_button();
|
this.button = event.get_button();
|
||||||
this.nbClicks = 1;
|
this.nbClicks = 1;
|
||||||
|
|
||||||
let sourceId = Mainloop.timeout_add(this.dbus.ClutterSettings['double-click-time'],
|
let sourceId = GLib.timeout_add(GLib.G_PRIORITY_DEFAULT,
|
||||||
|
this.dbus.ClutterSettings['double-click-time'],
|
||||||
this._doClickCallback.bind(this));
|
this._doClickCallback.bind(this));
|
||||||
this.timeouts.push(sourceId);
|
this.timeouts.push(sourceId);
|
||||||
}
|
}
|
||||||
|
@ -228,7 +229,7 @@ class MyPopupMenuItem extends PopupMenu.PopupBaseMenuItem {
|
||||||
this.box.set_vertical(true);
|
this.box.set_vertical(true);
|
||||||
|
|
||||||
for (let widgetIndex in widgets)
|
for (let widgetIndex in widgets)
|
||||||
this.box.add(widgets[widgetIndex]);
|
this.box.add_child(widgets[widgetIndex]);
|
||||||
|
|
||||||
this.add_child(this.box);
|
this.add_child(this.box);
|
||||||
}
|
}
|
||||||
|
@ -555,14 +556,12 @@ class MonitorWidget extends PanelMenu.Button {
|
||||||
|
|
||||||
// From https://github.com/ubuntu/gnome-shell-extension-appindicator/blob/master/interfaces.js
|
// From https://github.com/ubuntu/gnome-shell-extension-appindicator/blob/master/interfaces.js
|
||||||
// loads a xml file into an in-memory string
|
// loads a xml file into an in-memory string
|
||||||
function loadInterfaceXml(filename) {
|
function loadInterfaceXml(extension, filename) {
|
||||||
const extension = imports.misc.extensionUtils.getCurrentExtension();
|
|
||||||
|
|
||||||
const interfacesDir = extension.dir.get_child('.');
|
const interfacesDir = extension.dir.get_child('.');
|
||||||
|
|
||||||
const file = interfacesDir.get_child(filename);
|
const file = interfacesDir.get_child(filename);
|
||||||
|
|
||||||
let [result, contents] = imports.gi.GLib.file_get_contents(file.get_path());
|
let [result, contents] = GLib.file_get_contents(file.get_path());
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
// HACK: The "" + trick is important as hell because file_get_contents returns
|
// HACK: The "" + trick is important as hell because file_get_contents returns
|
||||||
|
@ -580,11 +579,11 @@ function loadInterfaceXml(filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class GenericMonitorDBUS {
|
class GenericMonitorDBUS {
|
||||||
constructor() {
|
constructor(extension) {
|
||||||
this.monitor_groups = {};
|
this.monitor_groups = {};
|
||||||
this.actor_clicked = {};
|
this.actor_clicked = {};
|
||||||
this.ClutterSettings = Clutter.Settings.get_default();
|
this.ClutterSettings = Clutter.Settings.get_default();
|
||||||
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(loadInterfaceXml('dbus.xml'), this);
|
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(loadInterfaceXml(extension, 'dbus.xml'), this);
|
||||||
this._dbusImpl.export(Gio.DBus.session, '/com/soutade/GenericMonitor');
|
this._dbusImpl.export(Gio.DBus.session, '/com/soutade/GenericMonitor');
|
||||||
this._dbusImpl.emit_signal('onActivate', null);
|
this._dbusImpl.emit_signal('onActivate', null);
|
||||||
}
|
}
|
||||||
|
@ -799,30 +798,21 @@ class GenericMonitorDBUS {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Extension {
|
export default class GenericMonitorExtension extends Extension.Extension {
|
||||||
|
constructor(...args) {
|
||||||
|
super(...args);
|
||||||
|
this.textDBusService = null;
|
||||||
|
}
|
||||||
|
|
||||||
enable() {
|
enable() {
|
||||||
this.textDBusService = new GenericMonitorDBUS();
|
this.textDBusService = new GenericMonitorDBUS(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
|
if (this.textDBusService !== null) {
|
||||||
this.textDBusService.destructor();
|
this.textDBusService.destructor();
|
||||||
delete this.textDBusService;
|
delete this.textDBusService;
|
||||||
|
this.textDBusService = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let extension = null;
|
|
||||||
|
|
||||||
function init() {
|
|
||||||
}
|
|
||||||
|
|
||||||
function enable() {
|
|
||||||
extension = new Extension();
|
|
||||||
extension.enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
function disable() {
|
|
||||||
if (extension) {
|
|
||||||
extension.disable();
|
|
||||||
extension = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,11 @@
|
||||||
"uuid": "generic-monitor@gnome-shell-extensions",
|
"uuid": "generic-monitor@gnome-shell-extensions",
|
||||||
"name": "Generic Monitor",
|
"name": "Generic Monitor",
|
||||||
"description": "Display text & icon on systray using DBUS",
|
"description": "Display text & icon on systray using DBUS",
|
||||||
"version": "13",
|
"version": "14",
|
||||||
"shell-version": [
|
"shell-version": [
|
||||||
"44",
|
"47",
|
||||||
"43",
|
"46",
|
||||||
"42.3",
|
"45"
|
||||||
"42",
|
|
||||||
"41"
|
|
||||||
],
|
],
|
||||||
"url": "http://indefero.soutade.fr/p/genericmonitor"
|
"url": "http://indefero.soutade.fr/p/genericmonitor"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user