mirror of
https://github.com/oleid/gnome-shell-teatime.git
synced 2022-04-29 18:53:50 +00:00
initial import based upon version 0.2 from 20130318
This commit is contained in:
commit
f99dd297f5
183
extension.js
Normal file
183
extension.js
Normal file
@ -0,0 +1,183 @@
|
||||
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
||||
/* Olaf Leidinger <oleid@mescharet.de> 20130318 */
|
||||
|
||||
const Gdk = imports.gi.Gdk;
|
||||
const Gio = imports.gi.Gio;
|
||||
const GLib = imports.gi.GLib;
|
||||
const GnomeDesktop = imports.gi.GnomeDesktop;
|
||||
const Lang = imports.lang;
|
||||
const Mainloop = imports.mainloop; // timer
|
||||
const Shell = imports.gi.Shell;
|
||||
const St = imports.gi.St;
|
||||
const Clutter = imports.gi.Clutter;
|
||||
|
||||
const Main = imports.ui.main;
|
||||
const MessageTray = imports.ui.messageTray;
|
||||
const PanelMenu = imports.ui.panelMenu;
|
||||
const PopupMenu = imports.ui.popupMenu;
|
||||
const Panel = imports.ui.panel;
|
||||
|
||||
const Gettext = imports.gettext.domain('gnome-shell-extensions');
|
||||
const _ = Gettext.gettext;
|
||||
const N_ = function(e) { return e; };
|
||||
|
||||
const ExtensionUtils = imports.misc.extensionUtils;
|
||||
const Me = ExtensionUtils.getCurrentExtension();
|
||||
|
||||
// TODO: make this configurable via gsettings
|
||||
const defaultTeaList = [
|
||||
{name : "Green tea", time : 180 },
|
||||
{name : "Black tea", time : 210 },
|
||||
{name : "Fruit tea", time : 7 * 60},
|
||||
{name : "White tea", time : 120}
|
||||
];
|
||||
|
||||
const TeaTime = new Lang.Class({
|
||||
Name : 'TeaTime',
|
||||
Extends : PanelMenu.Button,
|
||||
|
||||
_init : function() {
|
||||
this.parent(0.0, "TeaTime");
|
||||
|
||||
this._logo = new St.Icon({
|
||||
icon_name : 'utilities-teatime',
|
||||
style_class : 'system-status-icon'
|
||||
});
|
||||
|
||||
// set timer widget
|
||||
|
||||
this._timer = new St.DrawingArea({
|
||||
reactive : true
|
||||
});
|
||||
this._timer.set_width(20);
|
||||
this._timer.set_height(20);
|
||||
this._timer.connect('repaint', Lang.bind(this, this._drawTimer));
|
||||
|
||||
this.actor.add_actor(this._logo);
|
||||
|
||||
this._dt = 4;
|
||||
this._idleTimeout = null;
|
||||
|
||||
this._createMenu();
|
||||
},
|
||||
|
||||
_createMenu : function() {
|
||||
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||
this._addTeaList();
|
||||
},
|
||||
_formatTime : function(seconds) {
|
||||
let a = new Date(0,0,0); // important: hour needs to be set to zero in _locale_ time
|
||||
|
||||
a.setTime(a.getTime()+ seconds * 1000); // set time in msec, adding the time we want
|
||||
|
||||
if (seconds > 3600)
|
||||
return a.toLocaleFormat("%H:%M:%S");
|
||||
else
|
||||
return a.toLocaleFormat("%M:%S");
|
||||
},
|
||||
_addTeaList : function(config, output) {
|
||||
let item = new PopupMenu.PopupMenuItem(_("brewing times"));
|
||||
item.label.add_style_class_name('display-subtitle');
|
||||
item.actor.reactive = false;
|
||||
item.actor.can_focus = false;
|
||||
this.menu.addMenuItem(item);
|
||||
this._callbacks = [];
|
||||
|
||||
defaultTeaList.sort(function(a, b) {
|
||||
return -1 * (a.time < b.time) + (a.time > b.time);
|
||||
});
|
||||
|
||||
for ( var i = 0; i < defaultTeaList.length; i++) {
|
||||
let tea = defaultTeaList[i];
|
||||
let item = new PopupMenu.PopupMenuItem(this._formatTime(tea.time) + " - " + tea.name);
|
||||
|
||||
this._callbacks.push( function() {this._initCountdown(tea.time); });
|
||||
item.connect('activate', Lang.bind(this, this._callbacks[i]));
|
||||
this.menu.addMenuItem(item);
|
||||
}
|
||||
},
|
||||
_showNotification : function(subject, text) {
|
||||
let source = new MessageTray.Source("TeaTime applet", 'utilities-teatime');
|
||||
Main.messageTray.add(source);
|
||||
|
||||
let notification = new MessageTray.Notification(source, subject, text);
|
||||
notification.setTransient(true);
|
||||
source.notify(notification);
|
||||
},
|
||||
_initCountdown : function(time) {
|
||||
this._startTime = new Date();
|
||||
this._stopTime = new Date();
|
||||
this._cntdownStart = time;
|
||||
this._progress = 0;
|
||||
this._stopTime.setTime(this._startTime.getTime() + time*1000); // in msec
|
||||
|
||||
this.actor.remove_actor(this._logo); // show timer instead of default icon
|
||||
this.actor.add_actor(this._timer);
|
||||
|
||||
this._showNotification("Timer set!", time + "s to go");
|
||||
this._idleTimeout = Mainloop.timeout_add_seconds(this._dt, Lang.bind(this, this._doCountdown));
|
||||
},
|
||||
_getRemainingSec: function() {
|
||||
let a = new Date();
|
||||
return (this._stopTime.getTime() - a.getTime()) * 1e-3;
|
||||
},
|
||||
_doCountdown : function() {
|
||||
let remainingTime = this._getRemainingSec();
|
||||
this._progress = (this._cntdownStart - remainingTime) / this._cntdownStart;
|
||||
|
||||
if (remainingTime <= 0) {
|
||||
// count down finished, switch display again
|
||||
this.actor.remove_actor(this._timer);
|
||||
this.actor.add_actor(this._logo);
|
||||
this._showNotification("Your tea is ready!",
|
||||
"Drink it, while it is hot!");
|
||||
this._idleTimeout = null;
|
||||
return false;
|
||||
} else {
|
||||
this._timer.queue_repaint();
|
||||
return true; // continue timer
|
||||
}
|
||||
},
|
||||
_drawTimer : function() {
|
||||
let[width, height] = this._timer.get_surface_size();
|
||||
let cr = this._timer.get_context();
|
||||
let pi = Math.PI;
|
||||
let r = Math.min(width, height) * 0.5;;
|
||||
|
||||
// TODO: get colors from current theme!
|
||||
cr.setSourceRGB(0, 0, 0);
|
||||
cr.rectangle(0, 0, width, height);
|
||||
cr.fill();
|
||||
|
||||
cr.translate(Math.floor(width / 2), Math.floor(height / 2));
|
||||
cr.save();
|
||||
|
||||
cr.setSourceRGB(0.2, 0.2, 0.2);
|
||||
cr.moveTo(0, 0);
|
||||
cr.arc(0, 0, r, 3 / 2 * pi + 2 * pi * this._progress, 3 / 2 * pi + 2
|
||||
* pi);
|
||||
cr.fill();
|
||||
|
||||
cr.setSourceRGB(0.8, 0.8, 0.8);
|
||||
cr.moveTo(0, 0);
|
||||
cr.arc(0, 0, r, 3 / 2 * pi, 3 / 2 * pi + 2 * pi * this._progress);
|
||||
cr.fill();
|
||||
}
|
||||
});
|
||||
|
||||
function init(metadata) {
|
||||
// TODO: at some point, add translations
|
||||
;
|
||||
}
|
||||
|
||||
let _TeaTime;
|
||||
|
||||
function enable() {
|
||||
_TeaTime = new TeaTime();
|
||||
Main.panel.addToStatusArea('teatime', _TeaTime);
|
||||
}
|
||||
|
||||
function disable() {
|
||||
if (_TeaTime._idleTimeout != null) Mainloop.source_remove(_TeaTime._idleTimeout);
|
||||
_TeaTime.destroy();
|
||||
};
|
11
install.sh
Executable file
11
install.sh
Executable file
@ -0,0 +1,11 @@
|
||||
NAME="TeaTime@oleid.mescharet.de"
|
||||
INST_DIR="$HOME/.local/share/gnome-shell-extensions/$NAME"
|
||||
|
||||
echo "Installing icon"
|
||||
sudo cp utilities-teatime.svg /usr/share/icons/hicolor/scalable/apps/
|
||||
sudo gtk-update-icon-cache /usr/share/icons/hicolor/
|
||||
|
||||
echo "Installing extension"
|
||||
mkdir -p "$INST_DIR"
|
||||
|
||||
cp *.js *.json "$INST_DIR"
|
1
metadata.json
Normal file
1
metadata.json
Normal file
@ -0,0 +1 @@
|
||||
{"shell-version": ["3.6"], "uuid": "TeaTime@oleid.mescharet.de", "name": "TeaTime", "description": "A tea brewing timer"}
|
68
utilities-teatime.svg
Normal file
68
utilities-teatime.svg
Normal file
@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
version="1.0"
|
||||
width="484.0643"
|
||||
height="295.29187"
|
||||
viewBox="0 0 387.25145 236.23349"
|
||||
preserveAspectRatio="xMidYMid meet"
|
||||
id="svg2"
|
||||
inkscape:version="0.48.4 r9939"
|
||||
sodipodi:docname="utilities-teatime.svg">
|
||||
<defs
|
||||
id="defs12" />
|
||||
<sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1027"
|
||||
id="namedview10"
|
||||
showgrid="false"
|
||||
fit-margin-top="0"
|
||||
fit-margin-left="0"
|
||||
fit-margin-right="0"
|
||||
fit-margin-bottom="0"
|
||||
inkscape:zoom="0.26700352"
|
||||
inkscape:cx="1738.6914"
|
||||
inkscape:cy="-58.371397"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="27"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="g6" />
|
||||
<metadata
|
||||
id="metadata4">
|
||||
Created by potrace 1.10, written by Peter Selinger 2001-2011
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
transform="matrix(0.1,0,0,-0.1,-57.589577,378.57122)"
|
||||
id="g6"
|
||||
style="fill:#800000;stroke:none">
|
||||
<path
|
||||
style="fill:#cccccc;fill-opacity:0.94117647"
|
||||
d="m 1599.0437,1573.9177 c -235.4892,257.2771 -410.9172,307.0416 -639.52404,523.818 -239.98241,192.756 -444.12233,501.9215 -367.10697,821.8921 38.7852,200.5961 248.27611,336.0011 446.84671,290.8161 140.2785,-17.7787 266.8099,-85.0946 387.0129,-155.5415 74.2781,124.4657 298.1841,153.0228 229.5089,329.9101 109.3355,93.2904 275.201,94.5077 412.7117,124.4857 65.4385,24.6741 304.7317,-9.5508 144.7011,56.4876 -101.917,152.0308 154.8854,242.0949 276.2029,215.2013 221.301,17.1274 185.843,-251.1767 60.175,-252.1853 248.6206,-20.1446 504.4064,-33.9528 739.5175,-123.2683 84.1199,-70.036 -35.4555,-202.8042 111.3126,-240.3189 101.8205,-78.4406 164.8623,-338.5003 310.0326,-157.8318 135.2599,104.6132 214.2352,323.1066 418.3717,295.2474 93.5126,-2.8298 436.4814,5.3717 278.6869,-142.0678 -159.5297,-98.6124 -325.2795,-228.4326 -356.5455,-425.8986 -75.7637,-262.5934 -248.0386,-367.4119 -455.0358,-567.049 -164.5176,-129.6551 -89.2139,-307.7161 -486.3504,-668.5647 -214.1213,-95.3861 -1128.9411,-129.9962 -1510.5178,74.8676 z m -356.907,736.2999 c -39.4266,157.4822 53.2887,327.3731 16.2311,476.437 -97.7858,101.3794 -355.93876,159.0896 -327.80798,-45.542 35.80376,-97.6021 218.31118,-439.8564 311.57688,-430.895 z"
|
||||
id="path8"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="ccccccccccccccccccccccc" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 3.1 KiB |
Loading…
Reference in New Issue
Block a user