initial tray work

This commit is contained in:
Chris Cromer 2020-08-07 00:32:22 -04:00
parent 7cf4b4284a
commit 9fd83b108c
Signed by: cromer
GPG Key ID: 39CC813FF3C8708A
9 changed files with 280 additions and 6 deletions

View File

@ -45,6 +45,10 @@ Build the cli interface.
Build the gui interface. Build the gui interface.
- build-tray
Build the tray icon
- always-authenticated - always-authenticated
Authentication is not required to use the TUF Server that runs in the background as a daemon, if this is set to false polkit is used for authentication. Setting this to false is more secure, but also makes things like auto restore of settings on login impossible to do without a password. Authentication is not required to use the TUF Server that runs in the background as a daemon, if this is set to false polkit is used for authentication. Setting this to false is more secure, but also makes things like auto restore of settings on login impossible to do without a password.
@ -67,22 +71,27 @@ Install a systemd unit. If this option is not set, the unit is still generated d
## Usage ## Usage
There are 2 programs and 1 daemon supplied by TUF Manager. There are 3 programs and 1 daemon supplied by TUF Manager.
- tuf-cli - tuf-cli
This allows controlling the TUF laptop functions via command line interface. This allows controlling the TUF laptop functions via command line interface.
- tuf-gui - tuf-gui
This supplies a graphical interface to control the TUF laptop. This supplies a graphical interface to control the TUF laptop.
- tuf-server - tuf-server
This is the daemon that runs in the background and handles all requests from both tuf-cli and tuf-gui. This is the daemon that runs in the background and handles all requests from both tuf-cli and tuf-gui.
- tuf-tray
This is the tray icon to control the TUF Manager program
## Future plans ## Future plans
- Manpage - Manpage
- Config options for both tuf-gui and tuf-cli - Config options for both tuf-gui and tuf-cli
- Status bar icon that allows control of the notebook
- Notifications of fan mode change via status bar - Notifications of fan mode change via status bar
- Restore last known settings on login via status bar icon - Restore last known settings on login via status bar icon

View File

@ -7,6 +7,9 @@ if docs_enabled
endif endif
if build_gui if build_gui
vala_doc_sources += gui_vala_sources vala_doc_sources += gui_vala_sources
if build_tray
vala_doc_sources += tray_vala_sources
endif
endif endif
vala_doc_sources += error_vala_sources vala_doc_sources += error_vala_sources
vala_doc_sources += config_data_file vala_doc_sources += config_data_file
@ -14,7 +17,9 @@ if docs_enabled
docs_deps = [ docs_deps = [
'--pkg=polkit-gobject-1', '--pkg=polkit-gobject-1',
'--pkg=posix', '--pkg=posix',
'--pkg=gtk+-3.0' '--pkg=gtk+-3.0',
'--pkg=libnotify',
'--pkg=appindicator3-0.1'
] ]
if valadocs_deps if valadocs_deps
docs_deps += ['--deps'] docs_deps += ['--deps']

View File

@ -21,6 +21,7 @@ add_global_arguments(
always_authenticated = get_option('always-authenticated') always_authenticated = get_option('always-authenticated')
build_cli = get_option('build-cli') build_cli = get_option('build-cli')
build_gui = get_option('build-gui') build_gui = get_option('build-gui')
build_tray = get_option('build-tray')
subdir('po') subdir('po')
subdir('data') subdir('data')

View File

@ -22,6 +22,12 @@ option(
value: true, value: true,
description: 'Build the graphical user interface to TUF Manager' description: 'Build the graphical user interface to TUF Manager'
) )
option(
'build-tray',
type : 'boolean',
value: true,
description: 'Build the tray icon, this option depends on build-gui'
)
option( option(
'always-authenticated', 'always-authenticated',
type : 'boolean', type : 'boolean',

View File

@ -23,7 +23,7 @@ namespace TUFManager {
/** /**
* This class contains the app that runs on the command line * This class contains the app that runs on the command line
*/ */
public class TUFManagerApp : Application { public class TUFManagerApp : Gtk.Application {
#if ALWAYS_AUTHENTICATED #if ALWAYS_AUTHENTICATED
#else #else
/** /**
@ -184,6 +184,8 @@ namespace TUFManager {
} }
catch (TUFError e) { catch (TUFError e) {
command_line.printerr (_ ("Error: ") + e.message + "\n"); command_line.printerr (_ ("Error: ") + e.message + "\n");
this.release ();
return 1;
} }
string[] args = command_line.get_arguments (); string[] args = command_line.get_arguments ();

View File

@ -1,7 +1,7 @@
server_dependencies = [ server_dependencies = [
dependency('glib-2.0'), dependency('glib-2.0'),
dependency('gio-unix-2.0'), dependency('gio-unix-2.0'),
dependency('gtk+-3.0', version: '>=3.0.0'), dependency('gtk+-3.0', version: '>=3.10.0'),
meson.get_compiler('c').find_library('m', required: true), meson.get_compiler('c').find_library('m', required: true),
meson.get_compiler('vala').find_library('posix') meson.get_compiler('vala').find_library('posix')
] ]
@ -14,7 +14,7 @@ endif
if build_cli if build_cli
cli_dependencies = [ cli_dependencies = [
dependency('glib-2.0'), dependency('glib-2.0'),
dependency('gtk+-3.0', version: '>=3.0.0'), dependency('gtk+-3.0', version: '>=3.10.0'),
meson.get_compiler('c').find_library('m', required: true) meson.get_compiler('c').find_library('m', required: true)
] ]
endif endif
@ -26,6 +26,14 @@ if build_gui
dependency('gtk+-3.0', version: '>=3.10.0'), dependency('gtk+-3.0', version: '>=3.10.0'),
dependency('gmodule-2.0', version: '>=2.0') # gmodule-export-2.0 is needed to connect the handlers from glade ui dependency('gmodule-2.0', version: '>=2.0') # gmodule-export-2.0 is needed to connect the handlers from glade ui
] ]
if build_tray
tray_dependencies = [
dependency('appindicator3-0.1'),
dependency('gtk+-3.0', version: '>=3.10.0'),
dependency('libnotify')
]
endif
endif endif
config_data = configuration_data() config_data = configuration_data()
@ -69,6 +77,12 @@ server_vala_sources_main = files(
'server-main.vala' 'server-main.vala'
) )
if build_tray
tray_vala_sources_main = files(
'tray-main.vala'
)
endif
server_vala_sources = files( server_vala_sources = files(
'server.vala', 'server.vala',
'server-interface.vala' 'server-interface.vala'
@ -89,6 +103,14 @@ if build_gui
'server-interface.vala', 'server-interface.vala',
'common.vala' 'common.vala'
) )
if build_tray
tray_vala_sources = files(
'tray.vala',
'tray-icon.vala',
'server-interface.vala'
)
endif
endif endif
server_sources = server_vala_sources server_sources = server_vala_sources
@ -109,6 +131,13 @@ if build_gui
gui_sources += error_vala_sources gui_sources += error_vala_sources
gui_sources += [tuf_manager_gresource] gui_sources += [tuf_manager_gresource]
gui_sources += config_data_file gui_sources += config_data_file
if build_tray
tray_sources = tray_vala_sources
tray_sources += tray_vala_sources_main
tray_sources += error_vala_sources
tray_sources += config_data_file
endif
endif endif
server_vala_args = [] server_vala_args = []
@ -154,4 +183,13 @@ if build_gui
vala_args: gui_vala_args, vala_args: gui_vala_args,
install: true install: true
) )
if build_tray
tray_exe = executable(
'tuf-tray',
tray_sources,
dependencies: tray_dependencies,
install: true
)
endif
endif endif

126
src/tray-icon.vala Normal file
View File

@ -0,0 +1,126 @@
/*
* Copyright 2020 Chris Cromer
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* The TUF Manager namespace
*/
namespace TUFManager {
/**
* The tray namespace handles everything related to the system tray
*/
namespace Tray {
public class TrayIcon {
private AppIndicator.Indicator indicator;
private Notify.Notification notification;
private Gtk.IconTheme icon_theme;
public TrayIcon (TUFManagerApp parent) {
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);
var menu = new Gtk.Menu ();
var item = new Gtk.MenuItem.with_label (_ ("TUF Manager"));
item.activate.connect (execute_manager);
menu.append (item);
item = new Gtk.MenuItem.with_mnemonic (_ ("_Quit"));
item.activate.connect (parent.release);
menu.append (item);
menu.show_all ();
indicator.set_menu (menu);
indicator.set_icon_full ("tuf-manager", "tuf-manager");
indicator.set_title (_ ("TUF Manager"));
set_icon_visible (true);
Timeout.add (200, () => {
indicator.set_status (AppIndicator.IndicatorStatus.ACTIVE);
return false;
});
Notify.init (_ ("TUF Manager"));
//show_notification ("test");
//update_notification ("test2");
}
private void execute_manager () {
try {
Process.spawn_command_line_async ("tuf-gui");
}
catch (SpawnError e) {
stderr.printf (_ ("Error: %s\n"), e.message);
}
}
private void set_icon_visible (bool visible) {
if (visible) {
indicator.set_status (AppIndicator.IndicatorStatus.ACTIVE);
}
else {
indicator.set_status (AppIndicator.IndicatorStatus.PASSIVE);
}
}
private void show_notification (string info) {
try {
close_notification ();
notification = new Notify.Notification (_ ("TUF Manager"), info, "tuf-manager");
notification.set_timeout (Notify.EXPIRES_DEFAULT);
notification.add_action ("default", _ ("Details"), execute_manager);
notification.show ();
}
catch (Error e) {
stderr.printf (_ ("Error: %s\n"), e.message);
}
}
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) {
stderr.printf (_ ("Error: %s\n"), e.message);
}
}
private void close_notification () {
try {
if (notification != null && notification.get_closed_reason () == -1) {
notification.close ();
notification = null;
}
}
catch (Error e) {
stderr.printf (_ ("Error: %s\n"), e.message);
}
}
private void on_icon_theme_changed () {
icon_theme = Gtk.IconTheme.get_default ();
indicator.set_icon_full ("tuf-manager", "tuf-manager");
}
}
}
}

45
src/tray-main.vala Normal file
View File

@ -0,0 +1,45 @@
/*
* Copyright 2020 Chris Cromer
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* The TUF Manager namespace
*/
namespace TUFManager {
/**
* The server namespace contains anything releated to working as a dbus daemon
* and handling root related tasks
*/
namespace Tray {
/**
* The entry point to the tray icon
*
* @param args Arguments passed from the command line
* @return Returns 0 on success
*/
public static int main (string[] args) {
var application = new Tray.TUFManagerApp ();
try {
application.register ();
}
catch (Error e) {
stderr.printf (_ ("Error: %s\n"), e.message);
}
if (application.get_is_remote ()) {
stderr.printf (_ ("Error: ") + _ ("Another instance of TUF Manager is already running!\n"));
return -1;
}
return application.run ();
}
}
}

42
src/tray.vala Normal file
View File

@ -0,0 +1,42 @@
/*
* Copyright 2020 Chris Cromer
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* The TUF Manager namespace
*/
namespace TUFManager {
/**
* The tray namespace handles everything related to the system tray
*/
namespace Tray {
public class TUFManagerApp : Gtk.Application {
public TUFManagerApp () {
application_id = "cl.cromer.tuf.manager.tray";
}
public override void activate () {
new TrayIcon (this);
}
public override void startup () {
Intl.textdomain ("tuf-manager");
Intl.setlocale (LocaleCategory.ALL, "");
base.startup ();
this.hold ();
}
}
}
}