From 9d4ae1676d25a5ca2cbf7013d8d43db4f9989718 Mon Sep 17 00:00:00 2001 From: sonichy Date: Sun, 4 May 2025 12:27:27 +0800 Subject: [PATCH] menu change to tooltip --- BingWallpaper@sonichy/extension.js | 14 +++++++------- BingWallpaper@sonichy/metadata.json | 2 +- CMUD@sonichy/extension.js | 29 ++++++++++++++++++++++++++--- CMUD@sonichy/metadata.json | 2 +- datetime@sonichy/extension.js | 22 +++++++++++++++------- 5 files changed, 50 insertions(+), 19 deletions(-) diff --git a/BingWallpaper@sonichy/extension.js b/BingWallpaper@sonichy/extension.js index 51616a5..7dc271c 100755 --- a/BingWallpaper@sonichy/extension.js +++ b/BingWallpaper@sonichy/extension.js @@ -8,9 +8,6 @@ import * as Main from 'resource:///org/gnome/shell/ui/main.js'; import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js'; import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js'; -export var schema = 'org.gnome.desktop.background'; -export var imagePath = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES) + '/BingWallpaper'; - export default class BingWallpaperExtension extends Extension { enable() { this._indicator = new PanelMenu.Button(0.0, this.metadata.name, false); @@ -25,13 +22,15 @@ export default class BingWallpaperExtension extends Extension { Main.panel.addToStatusArea(this.uuid, this._indicator); + this.imagePath = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES) + '/BingWallpaper'; const menu_browse = new PopupMenu.PopupImageMenuItem('Browse', 'folder-directory-symbolic', {}); menu_browse.connect('activate', () => { - let uri = 'file://' + imagePath; + let uri = 'file://' + this.imagePath; Gio.app_info_launch_default_for_uri(uri, global.create_app_launch_context(0, -1)); }); this._indicator.menu.addMenuItem(menu_browse); + const schema = 'org.gnome.desktop.background'; this.gsettings = new Gio.Settings({ schema: schema }); let uri = this.gsettings.get_string('picture-uri'); let filename = uri.substring(uri.lastIndexOf('/') + 1) @@ -40,9 +39,10 @@ export default class BingWallpaperExtension extends Extension { this._indicator.menu.addMenuItem(this.menu_update); } - disable() { + disable() { this._indicator?.destroy(); - this._indicator = null; + this._indicator = null; + this.gsettings = null; } getWallpaper() { @@ -57,7 +57,7 @@ export default class BingWallpaperExtension extends Extension { let imgUrl = "http://www.bing.com" + json.images[0].url; var filename = json.images[0].enddate + '_' + json.images[0].urlbase.replace('/th?id=OHR.', '') + '.jpg'; this.menu_update.label.text = json.images[0].copyright; - var filepath = imagePath + '/' + filename; + var filepath = this.imagePath + '/' + filename; let file = Gio.file_new_for_path(filepath); let request = Soup.Message.new('GET', imgUrl); httpSession.send_and_read_async(request, GLib.PRIORITY_DEFAULT, null, (httpSession, message) => { diff --git a/BingWallpaper@sonichy/metadata.json b/BingWallpaper@sonichy/metadata.json index 65a5de2..6084f95 100755 --- a/BingWallpaper@sonichy/metadata.json +++ b/BingWallpaper@sonichy/metadata.json @@ -1,7 +1,7 @@ { "uuid": "BingWallpaper@sonichy", "name": "Bing Wallpaper", - "description": "Change wallpaper of GNOME with Bing wallpaper on one click.", + "description": "Change wallpaper of GNOME with Bing wallpaper on one click. This extension is not affiliated, funded, or in any way associated with Microsoft and Bing.", "author": "sonichy", "version": "1.0", "shell-version": [ "45", "46", "47", "48" ], diff --git a/CMUD@sonichy/extension.js b/CMUD@sonichy/extension.js index 214956b..370d79c 100755 --- a/CMUD@sonichy/extension.js +++ b/CMUD@sonichy/extension.js @@ -37,8 +37,30 @@ export default class CMUDExtension extends Extension { // Add the indicator to the panel Main.panel.addToStatusArea(this.uuid, this._indicator); - const menuItem = new PopupMenu.PopupMenuItem(''); - this._indicator.menu.addMenuItem(menuItem); + //const menuItem = new PopupMenu.PopupMenuItem(''); + //this._indicator.menu.addMenuItem(menuItem); + + this.label_tooltip = new St.Label({ text: '' }); + this.label_tooltip.set_style('background:#222; padding:10px; border:1px solid #aaa; border-radius:10px;'); + global.stage.add_child(this.label_tooltip); + this.label_tooltip.hide(); + this._indicator.connect('notify::hover', () => { + const [x, y] = this._indicator.get_transformed_position(); + //console.log(x, y); + if (x == 0 && y != 0) //LEFT + this.label_tooltip.set_position(x + this._indicator.width + 1, y); + else if (x != 0 && y == 0) //TOP + this.label_tooltip.set_position(x, y + this.label_tooltip.height + 4); + else + if (this._indicator.height == Main.panel.height) //BOTTOM + this.label_tooltip.set_position(x, y - this.label_tooltip.height - 1); + else //RIGHT + this.label_tooltip.set_position(x - this.label_tooltip.width - 1, y); + if (this._indicator.hover) + this.label_tooltip.show(); + else + this.label_tooltip.hide(); + }); this._timeout = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1, () => { var net = this.net(); @@ -48,7 +70,8 @@ export default class CMUDExtension extends Extension { this.cpu(); area_cpu.queue_repaint(); var s = 'Uptime: ' + this.uptime() + '\nCPU: ' + cp + '%\nMem: ' + this.mem() + '\nUp: ' + this.B2G(net.ub) + '\nDown: ' + this.B2G(net.db); - menuItem.label.text = s; + //menuItem.label.text = s; + this.label_tooltip.text = s; // Run as loop, not once. return GLib.SOURCE_CONTINUE; }); diff --git a/CMUD@sonichy/metadata.json b/CMUD@sonichy/metadata.json index f1548f6..ecfa62c 100644 --- a/CMUD@sonichy/metadata.json +++ b/CMUD@sonichy/metadata.json @@ -5,5 +5,5 @@ "shell-version": [ "45", "46", "47", "48" ], "url": "https://github.com/sonichy/GNOME_extension", "uuid": "CMUD@sonichy", - "version": 3 + "version": 1.1 } diff --git a/datetime@sonichy/extension.js b/datetime@sonichy/extension.js index 9e8bf4d..55b79ff 100755 --- a/datetime@sonichy/extension.js +++ b/datetime@sonichy/extension.js @@ -27,18 +27,26 @@ export default class DatetimeExtension extends Extension { calendar.setDate(now); this._indicator.menu.addMenuItem(menuItem); - const menuItem1 = new PopupMenu.PopupMenuItem(''); + //const menuItem1 = new PopupMenu.PopupMenuItem(''); //menuItem1.label.set_style('text-align:center'); //无效 - this._indicator.menu.addMenuItem(menuItem1); + //this._indicator.menu.addMenuItem(menuItem1); this.label_tooltip = new St.Label({ text: '' }); - this.label_tooltip.set_style('background:#222;padding:10px;'); + this.label_tooltip.set_style('background:#222;padding:10px;border:1px solid #aaa;border-radius:10px;'); global.stage.add_child(this.label_tooltip); this.label_tooltip.hide(); - this._indicator.connect('notify::hover', () => { + this._indicator.connect('notify::hover', () => { const [x, y] = this._indicator.get_transformed_position(); - //console.log(x,y); - this.label_tooltip.set_position(x, y - this.label_tooltip.height); + //console.log(x, y); + if (x == 0 && y != 0) //LEFT + this.label_tooltip.set_position(x + this._indicator.width + 1, y); + else if (x != 0 && y == 0) //TOP + this.label_tooltip.set_position(x, y + this.label_tooltip.height + 4); + else + if (this._indicator.height == Main.panel.height) //BOTTOM + this.label_tooltip.set_position(x, y - this.label_tooltip.height - 1); + else //RIGHT + this.label_tooltip.set_position(x - this.label_tooltip.width - 1, y); if (this._indicator.hover) this.label_tooltip.show(); else @@ -58,7 +66,7 @@ export default class DatetimeExtension extends Extension { var weekday1 = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]; var text = h + ' : ' + m + '\n' + (date.getMonth() + 1) + '/' + date.getDate() + ' ' + weekday[day]; label.set_text(text); - menuItem1.label.text = date.toLocaleString() + ' ' + weekday1[day]; + //menuItem1.label.text = date.toLocaleString() + ' ' + weekday1[day]; this.label_tooltip.text = date.toLocaleString() + ' ' + weekday1[day]; // Run as loop, not once. return GLib.SOURCE_CONTINUE;