first
This commit is contained in:
13
datetime@sonichy/README.md
Executable file
13
datetime@sonichy/README.md
Executable file
@@ -0,0 +1,13 @@
|
||||
# Datetime_GNOME
|
||||
Display date and time on GNOME taskbar.
|
||||

|
||||
|
||||
## 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
|
||||
53
datetime@sonichy/extension.js
Executable file
53
datetime@sonichy/extension.js
Executable file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
9
datetime@sonichy/metadata.json
Executable file
9
datetime@sonichy/metadata.json
Executable file
@@ -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"
|
||||
}
|
||||
BIN
datetime@sonichy/preview.png
Normal file
BIN
datetime@sonichy/preview.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 94 KiB |
Reference in New Issue
Block a user