This commit is contained in:
JerryXiao 2024-03-09 16:39:51 +08:00
commit a32040307d
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5
2 changed files with 67 additions and 0 deletions

57
extension.js Normal file
View file

@ -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
}
}

10
metadata.json Normal file
View file

@ -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"
}