Initial commit

This commit is contained in:
Teddy Cornaut 2022-03-24 15:03:05 +01:00
commit f406524aa3
8 changed files with 209 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
config.json

5
README.md Normal file
View File

@ -0,0 +1,5 @@
# Installation
- Extraire le contenu du dossier dans `~/.local/share/gnome-shell/extensions`
- Copier `config.json.dist` vers `config.json` et y entrer votre clé API Ninebadge
- Recharger votre session Gnome (ALT + F2, entrer "r" puis appuyer sur Entrée)

3
config.json.dist Normal file
View File

@ -0,0 +1,3 @@
{
"key": "change_me"
}

144
extension.js Normal file
View File

@ -0,0 +1,144 @@
// Example#8
imports.gi.versions.Gtk = "4.0";
const { Gtk } = imports.gi;
const Main = imports.ui.main;
const St = imports.gi.St;
const ByteArray = imports.byteArray;
const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gio = imports.gi.Gio;
const Soup = imports.gi.Soup;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const version = Gtk.get_major_version();
log(`GTK version is ${version}`);
let myPopup;
let started = false;
let key = get_config('key');
const MyPopup = GObject.registerClass(
class MyPopup extends PanelMenu.Button {
_init () {
super._init(0);
let icon = new St.Icon({
//icon_name : 'security-low-symbolic',
gicon : Gio.icon_new_for_string( Me.dir.get_path() + '/logo.png' ),
style_class : 'system-status-icon',
});
this.add_child(icon);
let today = new Date()
let time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
let timeItem = new PopupMenu.PopupMenuItem('');
let timeLabel = new St.Label({text:'Capital actuel : +0:00'});
timeItem.add(timeLabel);
this.menu.addMenuItem(timeItem);
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
let startItem = new PopupMenu.PopupMenuItem('');
let label = new St.Label({
text:'DÉBUT POINTAGE',
style_class:'timer-btn'
});
startItem.add(label);
this.menu.addMenuItem(startItem);
this.menu.connect('open-state-changed', (menu, open) => {
if (open) {
log('opened');
let result = send_request('https://badge.cadoles.com/ninebadge/rest/showtimers', 'POST', key)
timeLabel.set_text('Capital actuel : ' + result.capitaltime)
let status = send_request('https://badge.cadoles.com/ninebadge/rest/status', 'POST', key)
if(status.status == "started") {
label.set_text('FIN POINTAGE');
started = true
} else {
started = false
label.set_text('DÉBUT POINTAGE');
}
}
});
startItem.connect('activate', () => {
try {
let result = send_request('https://badge.cadoles.com/ninebadge/rest/showtimers', 'POST', key)
timeLabel.set_text('CAPITAL : ' + result.capitaltime)
} catch(error) {
log(error);
}
if(started){
send_request('https://badge.cadoles.com/ninebadge/rest/clockout', 'POST', key)
started = false
label.set_text('DÉBUT POINTAGE');
} else {
send_request('https://badge.cadoles.com/ninebadge/rest/clockin', 'POST', key)
label.set_text('FIN POINTAGE');
started = true
}
log(started);
});
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
let validateItem = new PopupMenu.PopupMenuItem('');
let validateLabel = new St.Label({
text:'VALIDER MA JOURNÉE',
style_class:'validate-btn'
});
validateItem.add(validateLabel);
this.menu.addMenuItem(validateItem);
validateItem.connect('activate', () => {
send_request('https://badge.cadoles.com/ninebadge/rest/clockout', 'POST', key)
started = false
label.set_text('DÉBUT POINTAGE');
send_request('https://badge.cadoles.com/ninebadge/rest/validate', 'POST', key)
});
// you can close, open and toggle the menu with
// this.menu.close();
// this.menu.open();
// this.menu.toggle();
}
});
function send_request(url, type='POST', key) {
let [ok, out, err, exit] = GLib.spawn_command_line_sync(`/usr/bin/curl --insecure -X ${type} -d '{"key": "${key}"}' -H "Content-Type: application/json" ${url} -o /tmp/test.json`);
let text = GLib.file_get_contents('/tmp/test.json')[1];
let json_result = JSON.parse(text);
return json_result
}
function get_config(property) {
let text = GLib.file_get_contents(Me.dir.get_path() + '/config.json')[1];
let json_result = JSON.parse(text);
return json_result[property];
}
function init() {
}
function enable() {
myPopup = new MyPopup();
Main.panel.addToStatusArea('myPopup', myPopup, 1);
}
function disable() {
myPopup.destroy();
}

35
icon.svg Normal file
View File

@ -0,0 +1,35 @@
<?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" id="svg8" version="1.1" viewBox="0 0 26.458333 26.458334" height="100" width="100">
<defs id="defs2">
</defs>
<metadata id="metadata5">
</metadata>
<g id="layer1">
<circle style="fill:#00ccff;fill-opacity:1;stroke:none;stroke-width:2.33575;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none" id="circle875" cx="13.229167" cy="13.229167" r="9.5763607"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 943 B

BIN
logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

12
metadata.json Normal file
View File

@ -0,0 +1,12 @@
{
"name" : "Ninebadge Gnome Extension",
"description" : "Ninebadge Gnome Extension",
"shell-version" : [
"3.36",
"40",
"41"
],
"url" : "",
"uuid" : "ninebadge-gnome-extension@cadoles.com",
"version" : 1.0
}

9
stylesheet.css Normal file
View File

@ -0,0 +1,9 @@
.timer-btn{
background:green;
padding:5px 15px;
}
.validate-btn{
background:#C82333;
padding:5px 15px;
}