commit a24f79b86d1b2fe2d311a617f0cf1880030d29ce Author: sonichy Date: Sun Apr 27 16:54:34 2025 +0800 first diff --git a/BingWallpaper@sonichy/README.md b/BingWallpaper@sonichy/README.md new file mode 100755 index 0000000..9e3e5e1 --- /dev/null +++ b/BingWallpaper@sonichy/README.md @@ -0,0 +1,14 @@ +# BingWallpaper_GNOME +Change wallpaper of GNOME with Bing wallpaper on one click. + +## Changelog +### V1.0 (2025-04-26) +Get Bing wallpaper API, parse image url, download image, set GNOME wallpaper. + +## Reference +[guide](https://gjs.guide/extensions/development/creating.html) +[Soup](https://libsoup.gnome.org/libsoup-3.0/index.html) +[bing-wallpaper-gnome-extension](https://github.com/neffo/bing-wallpaper-gnome-extension) + +## Debug +dbus-run-session -- gnome-shell --nested --wayland diff --git a/BingWallpaper@sonichy/bing-symbolic.svg b/BingWallpaper@sonichy/bing-symbolic.svg new file mode 100644 index 0000000..7a6cc22 --- /dev/null +++ b/BingWallpaper@sonichy/bing-symbolic.svg @@ -0,0 +1,81 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/BingWallpaper@sonichy/extension.js b/BingWallpaper@sonichy/extension.js new file mode 100755 index 0000000..5a53d9f --- /dev/null +++ b/BingWallpaper@sonichy/extension.js @@ -0,0 +1,79 @@ +import GLib from "gi://GLib"; +import Gio from 'gi://Gio'; +import St from 'gi://St'; +import Soup from 'gi://Soup'; + +import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js'; +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); + + let gicon = Gio.icon_new_for_string(this.dir.get_path() + '/bing-symbolic.svg'); + const icon = new St.Icon({ + gicon: gicon, + style_class: 'system-status-icon' + }); + this._indicator.add_child(icon); + //this._indicator.connect('pressed', () => this.getWallpaper()); + + Main.panel.addToStatusArea(this.uuid, this._indicator); + + const menu_browse = new PopupMenu.PopupImageMenuItem('Browse', 'folder-directory-symbolic', {}); + menu_browse.connect('activate', () => {}); + this._indicator.menu.addMenuItem(menu_browse); + + this.menu_update = new PopupMenu.PopupImageMenuItem('Update', 'info-symbolic', {}); + this.menu_update.connect('activate', () => this.getWallpaper()); + this._indicator.menu.addMenuItem(this.menu_update); + } + + disable() { + this._indicator?.destroy(); + this._indicator = null; + } + + getWallpaper() { + console.log('BingWallpaper menu pressed!'); + let gsettings = new Gio.Settings({ schema: schema }); + //let uri = gsettings.get_string('picture-uri'); + //console.log(schema + ': ' + uri); + var url = 'http://cn.bing.com/HPImageArchive.aspx'; + let params = { format: 'js', idx: '0' , n: '1' } ; + let httpSession = new Soup.Session(); + let request = Soup.Message.new_from_encoded_form('GET', url, Soup.form_encode_hash(params)); + httpSession.send_and_read_async(request, GLib.PRIORITY_DEFAULT, null, (httpSession, message) => { + const decoder = new TextDecoder(); + var data = decoder.decode(httpSession.send_and_read_finish(message).get_data()); + console.log(data); + var json = JSON.parse(data); + 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; + //console.log(imgUrl); + //console.log(filename); + var filepath = imagePath + '/' + filename; + //console.log(filepath); + 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) => { + data = httpSession.send_and_read_finish(message).get_data(); + file.replace_contents_bytes_async(data, null, false, Gio.FileCreateFlags.REPLACE_DESTINATION, null, (file, res) => { + let uri = 'file://' + filepath; + //console.log(uri); + gsettings.set_string('picture-uri', uri); + gsettings.set_string('picture-uri-dark', uri); + Gio.Settings.sync(); + gsettings.apply(); + }); + }); + }); + } + +} diff --git a/BingWallpaper@sonichy/metadata.json b/BingWallpaper@sonichy/metadata.json new file mode 100755 index 0000000..65a5de2 --- /dev/null +++ b/BingWallpaper@sonichy/metadata.json @@ -0,0 +1,9 @@ +{ + "uuid": "BingWallpaper@sonichy", + "name": "Bing Wallpaper", + "description": "Change wallpaper of GNOME with Bing wallpaper on one click.", + "author": "sonichy", + "version": "1.0", + "shell-version": [ "45", "46", "47", "48" ], + "url": "https://github.com/sonichy/GNOME_extension" +} diff --git a/CMUD@sonichy/README.md b/CMUD@sonichy/README.md new file mode 100755 index 0000000..0b66bf5 --- /dev/null +++ b/CMUD@sonichy/README.md @@ -0,0 +1,14 @@ +# CMUD_GNOME +Display uptime, cpu, memory, upload, download on GNOME taskbar. +![alt](preview.png) + +## Changelog +### V1.0 (2025-04-22) +Display uptime, cpu, memory, upload, download on GNOME taskbar. + +## Reference +[guide](https://gjs.guide/extensions/development/creating.html) +[Cinnamon_Applet](https://github.com/sonichy/Cinnamon_Applet) + +## Debug +dbus-run-session -- gnome-shell --nested --wayland diff --git a/CMUD@sonichy/extension.js b/CMUD@sonichy/extension.js new file mode 100755 index 0000000..214956b --- /dev/null +++ b/CMUD@sonichy/extension.js @@ -0,0 +1,210 @@ +import GLib from "gi://GLib"; +import Gio from "gi://Gio"; +import St from 'gi://St'; +import Clutter from "gi://Clutter"; + +import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js'; +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'; + +var db0 = 0, ub0 = 0, tt0 = 0, idle0 = 0, mp, cp; + +export default class CMUDExtension extends Extension { + + enable() { + // Create a panel button + this._indicator = new PanelMenu.Button(0.0, this.metadata.name, false); + var box = new St.BoxLayout(); + this._indicator.add_child(box); + + var area_mem = new St.DrawingArea(); + area_mem.width = 3; + area_mem.height = this._indicator.height; + area_mem.connect('repaint', this.onRepaint_mem); + box.add_child(area_mem); + + var label = new St.Label({ text: '↑ 0KB/s\n↓ 0KB/s', y_align: Clutter.ActorAlign.CENTER }); + label.set_style('text-align:center; font-family:Noto Mono'); + box.add_child(label); + + var area_cpu = new St.DrawingArea(); + area_cpu.width = 3; + area_cpu.height = this._indicator.height; + area_cpu.connect('repaint', this.onRepaint_cpu); + box.add_child(area_cpu); + + // Add the indicator to the panel + Main.panel.addToStatusArea(this.uuid, this._indicator); + + const menuItem = new PopupMenu.PopupMenuItem(''); + this._indicator.menu.addMenuItem(menuItem); + + this._timeout = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1, () => { + var net = this.net(); + label.set_text('↑' + this.B2G(net.ubs) + '/s\n↓' + this.B2G(net.dbs) + '/s'); + this.mem(); + area_mem.queue_repaint(); + 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; + // Run as loop, not once. + return GLib.SOURCE_CONTINUE; + }); + + } + + disable() { + if (this._timeout) { + GLib.source_remove(this._timeout); + this._timeout = null; + } + this._indicator?.destroy(); + this._indicator = null; + } + + uptime() { + const file = Gio.File.new_for_path('/proc/uptime'); + const [, contents, etag] = file.load_contents(null); + var t = contents.toString().split(' '); + var tt = Number(t[0]); + var d = 0; + if (tt > 86400) { + d = tt / 86400; + tt -= d * 86400; + } + var ds = ""; + if (d > 0) + ds = d + "day"; + var h = ~~(tt/3600); + if (h < 10) + h = '0' + h; + var m = ~~(tt%3600/60); + if (m < 10) + m = '0' + m; + var s = ~~(tt%3600%60); + if (s < 10) + s = '0' + s; + var hms = ds + h + ':' + m + ':' + s; + return hms; + } + + net() { + const file = Gio.File.new_for_path('/proc/net/dev'); + const [, contents, etag] = file.load_contents(null); + var l = contents.toString().trim().split('\n'); + var db = 0, ub = 0; + for (var i=2; i 999999999) { + b = b / (1024 * 1024 * 1024); + if (b >= 100) { + s = ' ' + b.toFixed(0) + 'GB'; + } else if (b >= 10) { + s = b.toFixed(1) + 'GB'; + } else { + s = b.toFixed(2) + 'GB'; + } + } else { + if (b > 999999) { + b = b / (1024 * 1024); + if (b >= 100) { + s = ' ' + b.toFixed(0) + 'MB'; + } else if (b >= 10) { + s = b.toFixed(1) + 'MB'; + } else { + s = b.toFixed(2) + 'MB'; + } + } else { + if (b > 999) { + b = b / 1024; + if (b >= 100) { + s = ' ' + b.toFixed(0) + 'KB'; + } else if (b >= 10) { + s = ' ' + b.toFixed(0) + 'KB'; + } else { + s = ' ' + b.toFixed(0) + 'KB'; + } + } else { + if (b >= 100) { + s = ' ' + b + ' B'; + } else if (b >= 10) { + s = ' ' + b + ' B'; + } else { + s = ' ' + b + ' B'; + } + } + } + } + return s; + } + + onRepaint_mem(area) { + let ctx = area.get_context(); + ctx.setLineWidth(3); + if (mp >= 90) + ctx.setSourceRGBA(1, 0, 0, 1); + else + ctx.setSourceRGBA(1, 1, 1, 1); + ctx.moveTo(0, area.height); + ctx.lineTo(0, area.height * (100 - mp) / 100); + ctx.stroke(); + ctx.$dispose(); + } + + onRepaint_cpu(area) { + let ctx = area.get_context(); + ctx.setLineWidth(3); + if (cp >= 90) + ctx.setSourceRGBA(1, 0, 0, 1); + else + ctx.setSourceRGBA(1, 1, 1, 1); + ctx.moveTo(0, area.height); + ctx.lineTo(0, area.height * (100 - cp) / 100); + ctx.stroke(); + ctx.$dispose(); + } + +} diff --git a/CMUD@sonichy/metadata.json b/CMUD@sonichy/metadata.json new file mode 100755 index 0000000..f3cfdfe --- /dev/null +++ b/CMUD@sonichy/metadata.json @@ -0,0 +1,9 @@ +{ + "uuid": "CMUD@sonichy", + "name": "CMUD", + "description": "Display uptime, cpu, memory, upload, download on GNOME taskbar.", + "author": "sonichy", + "version": "1.0", + "shell-version": [ "45", "46", "47", "48" ], + "url": "https://github.com/sonichy/Cinnamon_Applet" +} diff --git a/CMUD@sonichy/preview.png b/CMUD@sonichy/preview.png new file mode 100644 index 0000000..17b6da9 Binary files /dev/null and b/CMUD@sonichy/preview.png differ diff --git a/README.md b/README.md new file mode 100755 index 0000000..7eb53f3 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +## Reference +[guide](https://gjs.guide/extensions/development/creating.html) + +## Debug +dbus-run-session -- gnome-shell --nested --wayland diff --git a/datetime@sonichy/README.md b/datetime@sonichy/README.md new file mode 100755 index 0000000..a73121b --- /dev/null +++ b/datetime@sonichy/README.md @@ -0,0 +1,13 @@ +# Datetime_GNOME +Display date and time on GNOME taskbar. +![alt](preview.png) + +## Changelog +### V1.0 (2025-04-22) + +## Reference +[guide](https://gjs.guide/extensions/development/creating.html) +[Cinnamon_Applet](https://github.com/sonichy/Cinnamon_Applet) + +## Debug +dbus-run-session -- gnome-shell --nested --wayland diff --git a/datetime@sonichy/extension.js b/datetime@sonichy/extension.js new file mode 100755 index 0000000..8883e67 --- /dev/null +++ b/datetime@sonichy/extension.js @@ -0,0 +1,53 @@ +import GLib from "gi://GLib"; +import St from 'gi://St'; + +import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js'; +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 default class DatetimeExtension extends Extension { + enable() { + // Create a panel button + this._indicator = new PanelMenu.Button(0.0, this.metadata.name, false); + + var label = new St.Label({ text: '00:00\n1/1 一' }); + label.set_style('text-align:center'); + this._indicator.add_child(label); + + // Add the indicator to the panel + Main.panel.addToStatusArea(this.uuid, this._indicator); + + const menuItem = new PopupMenu.PopupMenuItem(''); + this._indicator.menu.addMenuItem(menuItem); + + this._timeout = GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 1, () => { + var date = new Date(); + var h = date.getHours(); + if (h < 10) + h = "0" + h; + var m = date.getMinutes(); + if (m < 10) + m = "0" + m; + var day = date.getDay(); + var weekday = ["日", "一", "二", "三", "四", "五", "六"]; + var weekday1 = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]; + const text = h + ' : ' + m + '\n' + (date.getMonth() + 1) + '/' + date.getDate() + ' ' + weekday[day]; + label.set_text(text); + menuItem.label.text = date.toLocaleString() + ' ' + weekday1[day]; + // Run as loop, not once. + return GLib.SOURCE_CONTINUE; + }); + + } + + disable() { + if (this._timeout) { + GLib.source_remove(this._timeout); + this._timeout = null; + } + this._indicator?.destroy(); + this._indicator = null; + } + +} diff --git a/datetime@sonichy/metadata.json b/datetime@sonichy/metadata.json new file mode 100755 index 0000000..f286649 --- /dev/null +++ b/datetime@sonichy/metadata.json @@ -0,0 +1,9 @@ +{ + "uuid": "datetime@sonichy", + "name": "datetime", + "description": "Display date and time on GNOME taskbar", + "author": "sonichy", + "version": "1.0", + "shell-version": [ "45", "46", "47", "48" ], + "url": "https://github.com/sonichy/Cinnamon_Applet" +} diff --git a/datetime@sonichy/preview.png b/datetime@sonichy/preview.png new file mode 100644 index 0000000..8c31c19 Binary files /dev/null and b/datetime@sonichy/preview.png differ