commit a32040307d0dfb51d7e7f925ee43f16794b8d9c4 Author: Jerry Date: Sat Mar 9 16:39:51 2024 +0800 init diff --git a/extension.js b/extension.js new file mode 100644 index 0000000..27205a1 --- /dev/null +++ b/extension.js @@ -0,0 +1,57 @@ +import GLib from 'gi://GLib' +import GObject from 'gi://GObject' +import St from 'gi://St' +import Clutter from 'gi://Clutter' + +import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js' +import * as PanelMenu from 'resource:///org/gnome/shell/ui/panelMenu.js' +import * as Main from 'resource:///org/gnome/shell/ui/main.js' + +const Indicator = GObject.registerClass( + class Indicator extends PanelMenu.Button { + _init(textInPanel) { + super._init(0.0, "spinner", true) + this.add_child(textInPanel) + } + }) + +export default class IndicatorExampleExtension extends Extension { + timeoutId = 0 + enable() { + let textInPanel = new St.Label({ + text: ":", + y_expand: true, + y_align: Clutter.ActorAlign.CENTER, + }) + textInPanel.set_style("font-family: monospace") + if (this.timeoutId != 0) { + GLib.Source.remove(this.timeoutId) + this.timeoutId = 0 + } + let index = 0 + //const content = ['|', '/', '-', '\\'] + //const content = ['⠻', '⠽', '⠾', '⠷', '⠯', '⠟'] + const content = ['⢿', '⣻', '⣽', '⣾', '⣷', '⣯', '⣟', '⡿'] + this.timeoutId = GLib.timeout_add( + GLib.PRIORITY_DEFAULT, + 100, + () => { + textInPanel.text = content[index] + index ++ + index %= content.length + return GLib.SOURCE_CONTINUE + } + ) + this._indicator = new Indicator(textInPanel) + Main.panel.addToStatusArea(this.uuid, this._indicator, 255, "left") + } + + disable() { + if (this.timeoutId != 0) { + GLib.Source.remove(this.timeoutId) + this.timeoutId = 0 + } + this._indicator.destroy() + this._indicator = null + } +} diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..8f23fe6 --- /dev/null +++ b/metadata.json @@ -0,0 +1,10 @@ +{ + "name": "Spinner", + "description": "A useless spinner", + "uuid": "spinner@isjerryxiao", + "shell-version": [ + "45" + ], + "version": 1, + "url": "https://git.jerryxiao.cc/Jerry/gnome-shell-extension-spinner" +}