X-Git-Url: https://adrianiainlam.tk/git/?p=indicator-lunar-calendar.git;a=blobdiff_plain;f=indicator-lunar-calendar.js;h=ea4470f4ab07648aa152e6baadb203343d41dcba;hp=77b778da3b98acd29f735106f2e80f8f8493681e;hb=0bf60d5783348434829af1d603cb5f07539039db;hpb=c2c14655e4da36c46f245fe9ad421d3b290ae600 diff --git a/indicator-lunar-calendar.js b/indicator-lunar-calendar.js index 77b778d..ea4470f 100755 --- a/indicator-lunar-calendar.js +++ b/indicator-lunar-calendar.js @@ -28,13 +28,14 @@ var Gtk = GNode.importNS('Gtk'); var AppIndicator3 = GNode.importNS('AppIndicator3'); var CronJob = require('cron').CronJob; var LunarCalendar = require('lunar-calendar-zh'); +var DBus = require('dbus-native'); /* setup indicator object */ GNode.startLoop(); Gtk.init(null); var indicator = AppIndicator3.Indicator.new( "lunar-indicator", - __dirname + '/鼠.svg', + __dirname + '/icons/鼠.svg', AppIndicator3.IndicatorCategory.APPLICATION_STATUS ); indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE); @@ -70,9 +71,17 @@ function update_indicator() { long_date += '\n' + lunar.hour + '時'; /* output to indicator */ - indicator.set_icon(__dirname + '/' + lunar.zodiac + '.svg'); + indicator.set_icon(__dirname + '/icons/' + lunar.zodiac + '.svg'); indicator.set_label(compact_date, ''); item.set_label(long_date); + + console.log('Indicator updated. ' + lunar.hour + ' Time: ' + new Date()); + /* DO NOT REMOVE THE ABOVE LINE. + * I have no absolutely no idea why but the indicator doesn't get + * updated if this line is removed. + * It wasn't needed though before implementing the DBus section below. + * So perhaps some kind of conflict between the two? + */ } var job = new CronJob({ @@ -82,4 +91,23 @@ var job = new CronJob({ }); update_indicator(); + +/* Detect resume from suspend and update date/time */ +var bus = DBus.systemBus(); +var service = bus.getService('org.freedesktop.login1'); +service.getInterface( + '/org/freedesktop/login1', + 'org.freedesktop.login1.Manager', + function(err, nm) { + nm.addListener('PrepareForSleep', function(arg) { + // PrepareForSleep returns false when resuming from suspend + if(!arg) { + job.stop(); // force cronjob to recalculate time + job.start(); + update_indicator(); + } + }); + } +); + Gtk.main();