finish up tray icon
This commit is contained in:
parent
130a131214
commit
a6e1c031c3
@ -7,6 +7,17 @@ if build_gui
|
||||
install: true,
|
||||
install_dir: join_paths(get_option('datadir'), 'applications')
|
||||
)
|
||||
|
||||
if build_tray
|
||||
i18n.merge_file(
|
||||
input: 'tuf-tray.desktop.in',
|
||||
output: 'tuf-tray.desktop',
|
||||
po_dir: join_paths(meson.source_root(), 'po'),
|
||||
type: 'desktop',
|
||||
install: true,
|
||||
install_dir: join_paths(get_option('sysconfdir'), 'xdg', 'autostart')
|
||||
)
|
||||
endif
|
||||
endif
|
||||
|
||||
subdir('dbus')
|
||||
|
@ -2,8 +2,8 @@
|
||||
Type=Application
|
||||
Name=TUF Manager
|
||||
GenericName=TUF Manager
|
||||
Comment=Softare to manage the fan mode and rgb keyboard.
|
||||
Comment=Softare to manage the fan mode and rgb keyboard
|
||||
Icon=tuf-manager
|
||||
StartupNotify=true
|
||||
Exec=tuf-gui
|
||||
Categories=System;
|
||||
Categories=System;Settings;
|
||||
|
10
data/tuf-tray.desktop.in
Normal file
10
data/tuf-tray.desktop.in
Normal file
@ -0,0 +1,10 @@
|
||||
[Desktop Entry]
|
||||
Name=TUF Manager
|
||||
GenericName=TUF Manager
|
||||
Comment=Softare to manage the fan mode and rgb keyboard
|
||||
Icon=tuf-manager
|
||||
Categories=System;Settings;
|
||||
Exec=/usr/bin/tuf-tray
|
||||
Type=Application
|
||||
StartupNotify=true
|
||||
Terminal=false
|
@ -9,6 +9,7 @@ src/server.vala
|
||||
src/server-interface.vala
|
||||
src/server-main.vala
|
||||
data/tuf-manager.desktop.in
|
||||
data/tuf-tray.desktop.in
|
||||
data/gschema/org.tuf.manager.gschema.xml
|
||||
data/polkit/org.tuf.manager.policy.in
|
||||
data/ui/tuf.manager.window.ui
|
||||
|
13
po/es.po
13
po/es.po
@ -7,8 +7,8 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: tuf-manager\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-08-07 01:13-0400\n"
|
||||
"PO-Revision-Date: 2020-08-07 01:14-0400\n"
|
||||
"POT-Creation-Date: 2020-08-07 10:08-0400\n"
|
||||
"PO-Revision-Date: 2020-08-07 10:08-0400\n"
|
||||
"Last-Translator: Chris Cromer <chris@cromer.cl>\n"
|
||||
"Language-Team: none\n"
|
||||
"Language: es\n"
|
||||
@ -219,16 +219,17 @@ msgid "Could not acquire bus name!"
|
||||
msgstr "¡No se pudo adquirir el bus name!"
|
||||
|
||||
#: data/tuf-manager.desktop.in:4 data/tuf-manager.desktop.in:5
|
||||
#: data/tuf-tray.desktop.in:3 data/tuf-tray.desktop.in:4
|
||||
#: data/ui/tuf.manager.window.ui:41
|
||||
msgid "TUF Manager"
|
||||
msgstr "Administrador TUF"
|
||||
|
||||
#: data/tuf-manager.desktop.in:6
|
||||
msgid "Softare to manage the fan mode and rgb keyboard."
|
||||
msgstr "Software para gestionar el modo ventilador y el teclado rgb."
|
||||
#: data/tuf-manager.desktop.in:6 data/tuf-tray.desktop.in:5
|
||||
msgid "Softare to manage the fan mode and rgb keyboard"
|
||||
msgstr "Software para gestionar el modo ventilador y el teclado rgb"
|
||||
|
||||
# Not translatable
|
||||
#: data/tuf-manager.desktop.in:7
|
||||
#: data/tuf-manager.desktop.in:7 data/tuf-tray.desktop.in:6
|
||||
msgid "tuf-manager"
|
||||
msgstr ""
|
||||
|
||||
|
@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: tuf-manager\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-08-07 01:13-0400\n"
|
||||
"POT-Creation-Date: 2020-08-07 10:08-0400\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@ -213,15 +213,16 @@ msgid "Could not acquire bus name!"
|
||||
msgstr ""
|
||||
|
||||
#: data/tuf-manager.desktop.in:4 data/tuf-manager.desktop.in:5
|
||||
#: data/tuf-tray.desktop.in:3 data/tuf-tray.desktop.in:4
|
||||
#: data/ui/tuf.manager.window.ui:41
|
||||
msgid "TUF Manager"
|
||||
msgstr ""
|
||||
|
||||
#: data/tuf-manager.desktop.in:6
|
||||
msgid "Softare to manage the fan mode and rgb keyboard."
|
||||
#: data/tuf-manager.desktop.in:6 data/tuf-tray.desktop.in:5
|
||||
msgid "Softare to manage the fan mode and rgb keyboard"
|
||||
msgstr ""
|
||||
|
||||
#: data/tuf-manager.desktop.in:7
|
||||
#: data/tuf-manager.desktop.in:7 data/tuf-tray.desktop.in:6
|
||||
msgid "tuf-manager"
|
||||
msgstr ""
|
||||
|
||||
|
@ -149,7 +149,7 @@ namespace TUFManager {
|
||||
* Used to restore the previous config from donf
|
||||
* TODO: Move this to a status bar app and/or user daemon
|
||||
*/
|
||||
public void restore () {
|
||||
private void restore () {
|
||||
var mode = settings.get_int ("fan-mode");
|
||||
if (mode >= 0 && mode <= 2) {
|
||||
if (get_fan_mode () != mode) {
|
||||
|
@ -49,7 +49,8 @@ if build_gui
|
||||
tray_dependencies = [
|
||||
appindicator_dep,
|
||||
gtk_dep,
|
||||
libnotify_dep
|
||||
libnotify_dep,
|
||||
meson.get_compiler('vala').find_library('posix')
|
||||
]
|
||||
endif
|
||||
endif
|
||||
@ -126,7 +127,8 @@ if build_gui
|
||||
tray_vala_sources = files(
|
||||
'tray.vala',
|
||||
'tray-icon.vala',
|
||||
'server-interface.vala'
|
||||
'server-interface.vala',
|
||||
'common.vala'
|
||||
)
|
||||
endif
|
||||
endif
|
||||
|
@ -20,24 +20,66 @@ namespace TUFManager {
|
||||
* The tray namespace handles everything related to the system tray
|
||||
*/
|
||||
namespace Tray {
|
||||
private TUFManagerApp parent;
|
||||
private Thread<void>? thread = null;
|
||||
private bool poll = true;
|
||||
public class TrayIcon {
|
||||
private AppIndicator.Indicator indicator;
|
||||
private Notify.Notification notification;
|
||||
private Gtk.IconTheme icon_theme;
|
||||
|
||||
public TrayIcon (TUFManagerApp parent) {
|
||||
/**
|
||||
* The settings object from gschema/dconf
|
||||
*/
|
||||
private Settings settings;
|
||||
|
||||
public TrayIcon () {
|
||||
Process.signal (ProcessSignal.INT, on_exit);
|
||||
Process.signal (ProcessSignal.TERM, on_exit);
|
||||
|
||||
settings = new Settings ("org.tuf.manager");
|
||||
try {
|
||||
connect_tuf_server ();
|
||||
}
|
||||
catch (TUFError e) {
|
||||
warning (e.message);
|
||||
}
|
||||
|
||||
icon_theme = Gtk.IconTheme.get_default ();
|
||||
icon_theme.changed.connect (on_icon_theme_changed);
|
||||
|
||||
indicator = new AppIndicator.Indicator (_ ("TUF Manager"), "tuf-manager", AppIndicator.IndicatorCategory.APPLICATION_STATUS);
|
||||
|
||||
indicator.set_status (AppIndicator.IndicatorStatus.ACTIVE);
|
||||
var menu = new Gtk.Menu ();
|
||||
var item = new Gtk.MenuItem.with_label (_ ("TUF Manager"));
|
||||
var item = new Gtk.MenuItem.with_mnemonic (_ ("_TUF Manager"));
|
||||
item.activate.connect (execute_manager);
|
||||
menu.append (item);
|
||||
item = new Gtk.MenuItem.with_mnemonic (_ ("_Quit"));
|
||||
item.activate.connect (parent.release);
|
||||
|
||||
// Submenu fan
|
||||
item = new Gtk.MenuItem.with_mnemonic (_ ("_Fan"));
|
||||
menu.append (item);
|
||||
var submenu = new Gtk.Menu ();
|
||||
item.set_submenu (submenu);
|
||||
|
||||
// Fan modes
|
||||
var subitem = new Gtk.MenuItem.with_mnemonic (_ ("_Balanced"));
|
||||
subitem.activate.connect (set_fan_balanced);
|
||||
submenu.append (subitem);
|
||||
|
||||
subitem = new Gtk.MenuItem.with_mnemonic (_ ("_Turbo"));
|
||||
subitem.activate.connect (set_fan_turbo);
|
||||
submenu.append (subitem);
|
||||
|
||||
subitem = new Gtk.MenuItem.with_mnemonic (_ ("_Silent"));
|
||||
subitem.activate.connect (set_fan_silent);
|
||||
submenu.append (subitem);
|
||||
|
||||
// Quit
|
||||
item = new Gtk.MenuItem.with_mnemonic (_ ("_Quit"));
|
||||
item.activate.connect (quit);
|
||||
menu.append (item);
|
||||
|
||||
menu.show_all ();
|
||||
|
||||
indicator.set_menu (menu);
|
||||
@ -48,13 +90,55 @@ namespace TUFManager {
|
||||
|
||||
Timeout.add_seconds (30, () => {
|
||||
indicator.set_status (AppIndicator.IndicatorStatus.ACTIVE);
|
||||
show_notification ("TUF Manager started");
|
||||
close_notification ();
|
||||
return false;
|
||||
});
|
||||
|
||||
Notify.init (_ ("TUF Manager"));
|
||||
|
||||
//show_notification ("test");
|
||||
//update_notification ("test2");
|
||||
restore ();
|
||||
thread = new Thread<void> ("poll_fan", this.poll_fan);
|
||||
}
|
||||
|
||||
private void quit () {
|
||||
on_exit (ProcessSignal.TERM);
|
||||
}
|
||||
|
||||
private static void on_exit (int signum) {
|
||||
poll = false;
|
||||
if (thread != null) {
|
||||
thread.join ();
|
||||
}
|
||||
parent.release () ;
|
||||
}
|
||||
|
||||
private void poll_fan () {
|
||||
int ret;
|
||||
Posix.pollfd[] fan_fd = {};
|
||||
fan_fd += Posix.pollfd ();
|
||||
fan_fd[0].fd = Posix.open (THERMAL_PATH, Posix.O_RDONLY);
|
||||
fan_fd[0].events = Posix.POLLERR | Posix.POLLPRI;
|
||||
Posix.read (fan_fd[0].fd, null, 1);
|
||||
string content = "";
|
||||
while (poll) {
|
||||
ret = Posix.poll (fan_fd, 1000);
|
||||
if (ret > 0) {
|
||||
Posix.read (fan_fd[0].fd, content, 1);
|
||||
Posix.lseek (fan_fd[0].fd, Posix.SEEK_SET, 0);
|
||||
|
||||
int mode = int.parse (content);
|
||||
if (mode == 0) {
|
||||
show_notification (_ ("Fan set to balanced"));
|
||||
}
|
||||
else if (mode == 1) {
|
||||
show_notification (_ ("Fan set to turbo"));
|
||||
}
|
||||
else if (mode == 2) {
|
||||
show_notification (_ ("Fan set to silent"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void execute_manager () {
|
||||
@ -66,6 +150,54 @@ namespace TUFManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void set_fan_balanced () {
|
||||
set_fan_mode (0);
|
||||
//show_notification (_ ("Fan set to balanced"));
|
||||
settings.set_int ("fan-mode", 0);
|
||||
}
|
||||
|
||||
private void set_fan_turbo () {
|
||||
set_fan_mode (1);
|
||||
//show_notification (_ ("Fan set to turbo"));
|
||||
settings.set_int ("fan-mode", 1);
|
||||
}
|
||||
|
||||
private void set_fan_silent () {
|
||||
set_fan_mode (2);
|
||||
//show_notification (_ ("Fan set to silenced"));
|
||||
settings.set_int ("fan-mode", 2);
|
||||
}
|
||||
|
||||
private void restore () {
|
||||
var mode = settings.get_int ("fan-mode");
|
||||
if (mode >= 0 && mode <= 2) {
|
||||
if (get_fan_mode () != mode) {
|
||||
set_fan_mode (mode);
|
||||
}
|
||||
}
|
||||
|
||||
mode = settings.get_int ("keyboard-mode");
|
||||
if (mode >= 0 && mode <= 3) {
|
||||
if (get_keyboard_mode () != mode) {
|
||||
set_keyboard_mode (mode);
|
||||
}
|
||||
}
|
||||
|
||||
var speed = settings.get_int ("keyboard-speed");
|
||||
if (speed >= 0 && speed <= 2) {
|
||||
if (get_keyboard_speed () != speed) {
|
||||
set_keyboard_speed (speed);
|
||||
}
|
||||
}
|
||||
|
||||
var color = settings.get_string ("keyboard-color");
|
||||
var rgba = Gdk.RGBA ();
|
||||
rgba.parse (color);
|
||||
if (!get_keyboard_color ().equal (rgba)) {
|
||||
set_keyboard_color (rgba);
|
||||
}
|
||||
}
|
||||
|
||||
private void set_icon_visible (bool visible) {
|
||||
if (visible) {
|
||||
indicator.set_status (AppIndicator.IndicatorStatus.ACTIVE);
|
||||
@ -75,12 +207,12 @@ namespace TUFManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void show_notification (string info) {
|
||||
private void show_notification (string message) {
|
||||
try {
|
||||
close_notification ();
|
||||
notification = new Notify.Notification (_ ("TUF Manager"), info, "tuf-manager");
|
||||
notification = new Notify.Notification (_ ("TUF Manager"), message, "tuf-manager");
|
||||
notification.set_timeout (Notify.EXPIRES_DEFAULT);
|
||||
notification.add_action ("default", _ ("Details"), execute_manager);
|
||||
notification.add_action ("default", _ ("Details"), close_notification);
|
||||
notification.show ();
|
||||
}
|
||||
catch (Error e) {
|
||||
@ -88,23 +220,6 @@ namespace TUFManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void update_notification (string info) {
|
||||
try {
|
||||
if (notification != null) {
|
||||
if (notification.get_closed_reason () == -1 && notification.body != info) {
|
||||
notification.update (_ ("TUF Manager"), info, "tuf-manager");
|
||||
notification.show ();
|
||||
}
|
||||
}
|
||||
else {
|
||||
show_notification (info);
|
||||
}
|
||||
}
|
||||
catch (Error e) {
|
||||
warning (e.message);
|
||||
}
|
||||
}
|
||||
|
||||
private void close_notification () {
|
||||
try {
|
||||
if (notification != null && notification.get_closed_reason () == -1) {
|
||||
|
@ -26,7 +26,8 @@ namespace TUFManager {
|
||||
}
|
||||
|
||||
public override void activate () {
|
||||
new TrayIcon (this);
|
||||
parent = this;
|
||||
new TrayIcon ();
|
||||
}
|
||||
|
||||
public override void startup () {
|
||||
|
Loading…
Reference in New Issue
Block a user