1
1
const Applet = imports . ui . applet ;
2
2
const Lang = imports . lang ;
3
3
const Settings = imports . ui . settings ;
4
- const UUID = "desaturate-all@hkoosha" ;
5
4
const Clutter = imports . gi . Clutter ;
6
5
const Main = imports . ui . main ;
7
6
const Mainloop = imports . mainloop ;
7
+ const Gettext = imports . gettext ;
8
+ const Gio = imports . gi . Gio ;
9
+
10
+ const UUID = "desaturate-all@hkoosha" ;
11
+
12
+ function _ ( str ) {
13
+ return Gettext . dgettext ( UUID , str ) ;
14
+ }
8
15
9
16
function MyApplet ( ) {
10
17
this . _init . apply ( this , arguments ) ;
@@ -34,6 +41,10 @@ MyApplet.prototype = {
34
41
this . settings . connect ( "changed::start-timechooser" , Lang . bind ( this , this . on_time_changed ) ) ;
35
42
this . settings . connect ( "changed::end-timechooser" , Lang . bind ( this , this . on_time_changed ) ) ;
36
43
44
+ this . desktop_settings = new Gio . Settings ( { schema_id : "org.cinnamon.desktop.interface" } ) ;
45
+ this . set_applet_tooltip ( "time" ) ; // initial value so that the show/hide events will occur
46
+ this . _applet_tooltip . _tooltip . connect ( "show" , Lang . bind ( this , this . on_tooltip_shown ) ) ;
47
+
37
48
this . on_keybinding_changed ( ) ;
38
49
this . on_saturation_changed ( ) ;
39
50
if ( ! this . settings . getValue ( "automatic" ) ) {
@@ -44,6 +55,40 @@ MyApplet.prototype = {
44
55
}
45
56
} ,
46
57
58
+ on_tooltip_shown ( ) {
59
+ let ttText ;
60
+ let effectEnabled = Main . uiGroup . has_effects ( ) && Main . uiGroup . get_effects ( ) . indexOf ( this . effect ) > - 1 ;
61
+ if ( effectEnabled ) {
62
+ ttText = _ ( "Click to disable effect" ) ;
63
+ } else {
64
+ ttText = _ ( "Click to desaturate the desktop" )
65
+ }
66
+ if ( this . settings . getValue ( "automatic" ) ) {
67
+ let toggleTime = this . _get_toggle_time ( ) ;
68
+ let hours = Math . floor ( toggleTime . seconds / 60 / 60 ) ;
69
+ if ( hours === 0 ) {
70
+ let min = Math . floor ( ( toggleTime . seconds / 60 ) + 1 ) ;
71
+ if ( toggleTime . enable ) {
72
+ ttText += "\n" + _ ( "Will automatically desaturate in" ) ;
73
+ } else {
74
+ ttText += "\n" + _ ( "Will automatically disable in" ) ;
75
+ }
76
+ ttText += ` ${ min } ` + _ ( "minutes" ) ;
77
+ } else {
78
+ if ( toggleTime . enable ) {
79
+ ttText += "\n" + _ ( "Will automatically desaturate at" ) + " " ;
80
+ } else {
81
+ ttText += "\n" + _ ( "Will automatically disable at" ) + " " ;
82
+ }
83
+ let use_24h = this . desktop_settings . get_boolean ( "clock-use-24h" ) ;
84
+ let ttTimeFormat = new Intl . DateTimeFormat ( undefined , { hour : "numeric" , minute : "2-digit" , hour12 : ! use_24h } ) ;
85
+
86
+ ttText += ttTimeFormat . format ( toggleTime . time ) ;
87
+ }
88
+ }
89
+ this . set_applet_tooltip ( ttText ) ;
90
+ } ,
91
+
47
92
_toggleEffect ( enable = null ) {
48
93
let effectEnabled = Main . uiGroup . has_effects ( ) && Main . uiGroup . get_effects ( ) . indexOf ( this . effect ) > - 1 ;
49
94
if ( enable != true && effectEnabled ) {
@@ -55,15 +100,7 @@ MyApplet.prototype = {
55
100
}
56
101
} ,
57
102
58
- _toggleEffect_based_on_time ( ) {
59
- if ( this . toggleDelay ) {
60
- Mainloop . source_remove ( this . toggleDelay ) ;
61
- this . toggleDelay = null ;
62
- }
63
-
64
- if ( ! this . settings . getValue ( "automatic" ) )
65
- return ;
66
-
103
+ _get_toggle_time ( ) {
67
104
const date = new Date ( ) ;
68
105
const enableAt = new Date ( ) ;
69
106
const disableAt = new Date ( ) ;
@@ -82,16 +119,32 @@ MyApplet.prototype = {
82
119
disableAt . setDate ( disableAt . getDate ( ) + 1 ) ;
83
120
84
121
let enable = ( date < disableAt && date >= enableAt ) ;
85
- this . _toggleEffect ( enable ) ;
86
-
87
122
let diffTime ;
123
+ let time ;
88
124
if ( enable ) {
89
125
diffTime = Math . abs ( disableAt - date ) / 1000 ;
126
+ time = disableAt ;
90
127
//log( `Disabling in ${diffTime} seconds` );
91
128
} else {
92
129
diffTime = Math . abs ( enableAt - date ) / 1000 ;
130
+ time = enableAt ;
93
131
//log( `Enabling in ${diffTime} seconds` );
94
132
}
133
+ return { enable : ! enable , seconds : diffTime , time : time } ;
134
+ } ,
135
+
136
+ _toggleEffect_based_on_time ( ) {
137
+ if ( this . toggleDelay ) {
138
+ Mainloop . source_remove ( this . toggleDelay ) ;
139
+ this . toggleDelay = null ;
140
+ }
141
+
142
+ if ( ! this . settings . getValue ( "automatic" ) )
143
+ return ;
144
+
145
+ let toggleTime = this . _get_toggle_time ( ) ;
146
+ this . _toggleEffect ( ! toggleTime . enable ) ;
147
+ let diffTime = toggleTime . seconds ;
95
148
this . toggleDelay = Mainloop . timeout_add_seconds ( diffTime , ( ) => { this . toggleDelay = null ; this . _toggleEffect_based_on_time ( ) ; } ) ;
96
149
} ,
97
150
0 commit comments