-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
118 lines (97 loc) · 3.31 KB
/
extension.js
File metadata and controls
118 lines (97 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright 2011 Aleksander Zdyb
* Copyright 2012 Arnaud Bonatti
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const Main = imports.ui.main;
const Lang = imports.lang;
const Mainloop = imports.mainloop;
const St = imports.gi.St;
const Gio = imports.gi.Gio;
const ERROR_LABEL = "---";
const UPDATE_INTERVAL = 500;
const LINE_WIDTH = 2;
const MARGIN = 1;
// in org.gnome.desktop.interface
const CLOCK_FORMAT_KEY = 'clock-format';
// in org.gnome.shell.clock
const CLOCK_SHOW_SECONDS_KEY = 'show-seconds';
function NewClock() {
this._init();
}
NewClock.prototype = {
_init: function() {
this.date = Main.panel._dateMenu._date;
// this.settings = Main.panel._dateMenu.menu.box.get_children()[0].get_children()[0].get_children()[3];
this.time_format = "%R"; // Safe fallback
this.time_format_if = "%R"; // O'clock
this.date_menu = Main.panel._dateMenu;
this.orig_clock = this.date_menu._clock;
this.new_clock = new St.Label({text: ERROR_LABEL});
this.desktop_settings = new Gio.Settings({ schema: "org.gnome.desktop.interface" });
this.clock_settings = new Gio.Settings({ schema: "org.gnome.shell.clock" });
this.desktop_settings.connect("changed", Lang.bind(this, this.update_format));
this.clock_settings.connect("changed", Lang.bind(this, this.update_format));
this.update_format();
},
Run: function() {
this.run = true;
this.on_timeout();
Mainloop.timeout_add(UPDATE_INTERVAL, Lang.bind(this, this.on_timeout));
},
update_format: function() {
let clock_format = this.desktop_settings.get_string(CLOCK_FORMAT_KEY);
let show_seconds = this.clock_settings.get_boolean(CLOCK_SHOW_SECONDS_KEY);
if (clock_format == "24h") {
if (show_seconds) {
this.time_format = "%F %T";
this.time_format_if = "";
}else{
this.time_format = "%F %H:%m";
this.time_format_if = "";
}
this.time_format += "";
this.time_format_if += "";
}else{
this.time_format = "%F %H:%m";
this.time_format_if = "";
if (show_seconds) this.time_format += "%F %T";
if (show_seconds) this.time_format_if += "";
this.time_format += "";
this.time_format_if += "";
}
},
on_timeout: function() {
let now = new Date();
if (now.getMinutes()==0) this.new_clock.set_text(now.toLocaleFormat(this.time_format_if));
else this.new_clock.set_text(now.toLocaleFormat(this.time_format));
return true;
},
enable: function() {
this.date_menu.actor.remove_actor(this.orig_clock);
this.date_menu.actor.add_actor(this.new_clock);
this.Run();
this.date.hide();
},
disable: function() {
this.date.show();
this.run = false;
this.date_menu.actor.remove_actor(this.new_clock);
this.date_menu.actor.add_actor(this.orig_clock);
}
}
function init() {
return new NewClock();
}