11const Applet = imports . ui . applet ;
2+ const Lang = imports . lang ;
23const Mainloop = imports . mainloop ;
4+ const St = imports . gi . St ;
35
46function MyApplet ( metadata , orientation , panelHeight , instance_id ) {
57 this . _init ( metadata , orientation , panelHeight , instance_id ) ;
@@ -17,44 +19,51 @@ MyApplet.prototype = {
1719 ) ;
1820
1921 this . set_applet_icon_name ( "clock" ) ;
20- this . set_applet_tooltip ( "Click to view the time" ) ;
21-
22- // Debug: Log initialization
23- // global.log("Click-Clock applet initialized successfully.");
22+ this . set_applet_tooltip ( "Click to view the time and date" ) ;
2423 } ,
2524
26- // Override the default on_applet_clicked method
2725 on_applet_clicked : function ( ) {
2826 try {
2927 // global.log("Applet clicked!"); // Debug log
3028
3129 let now = new Date ( ) ;
32- let timeString = now . toLocaleTimeString ( ) ;
30+ let localeDate = now . toLocaleDateString ( undefined , {
31+ weekday : "short" ,
32+ day : "numeric" ,
33+ month : "short" ,
34+ } ) ;
35+ let localeTime = now . toLocaleTimeString ( undefined , {
36+ hour : "2-digit" ,
37+ minute : "2-digit" ,
38+ hour12 : false ,
39+ } ) ;
40+ let displayString = `${ localeDate } ${ localeTime } ` ;
3341
34- // global.log("Current time: " + timeString); // Log the time
35- this . set_applet_label ( timeString ) ;
36- this . set_applet_tooltip ( `Current time: ${ timeString } ` ) ;
42+ this . set_applet_label ( displayString ) ;
43+ this . set_applet_tooltip ( `Current date and time: ${ displayString } ` ) ;
3744
38- // Reset to icon after 20 seconds
3945 if ( this . _timeoutId ) {
4046 Mainloop . source_remove ( this . _timeoutId ) ;
4147 }
4248
43- this . _timeoutId = Mainloop . timeout_add_seconds ( 20 , ( ) => {
44- this . _resetToIcon ( ) ;
45- return false ; // Stop the timeout
46- } ) ;
49+ this . _timeoutId = Mainloop . timeout_add_seconds (
50+ 20 ,
51+ Lang . bind ( this , function ( ) {
52+ this . _resetToIcon ( ) ;
53+ return false ;
54+ } )
55+ ) ;
4756 } catch ( e ) {
4857 global . logError ( "Error in on_applet_clicked: " + e ) ;
4958 }
5059 } ,
5160
5261 _resetToIcon : function ( ) {
5362 try {
54- // global.log("Resetting to clock icon."); // Debug log
63+ // global.log("Resetting to icon."); // Debug log
5564 this . set_applet_label ( "" ) ;
5665 this . set_applet_icon_name ( "clock" ) ;
57- this . set_applet_tooltip ( "Click to view the time" ) ;
66+ this . set_applet_tooltip ( "Click to view the time and date " ) ;
5867 } catch ( e ) {
5968 global . logError ( "Error in _resetToIcon: " + e ) ;
6069 }
0 commit comments