UI: Added tray icon
This commit is contained in:
parent
f166da1621
commit
7b48535a98
@ -6,6 +6,8 @@ from .app import MainApplication
|
|||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: Trayicon support
|
||||||
|
# https://github.com/nicotine-plus/nicotine-plus/blob/b08552584eb6f35782ad77da93ae4aae3362bf64/pynicotine/gtkgui/widgets/trayicon.py#L982
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
app = MainApplication()
|
app = MainApplication()
|
||||||
return app.run(sys.argv)
|
return app.run(sys.argv)
|
||||||
|
@ -16,6 +16,7 @@ from clan_vm_manager.models.interfaces import ClanConfig
|
|||||||
from clan_vm_manager.models.use_join import GLib, GObject
|
from clan_vm_manager.models.use_join import GLib, GObject
|
||||||
from clan_vm_manager.models.use_vms import VMS
|
from clan_vm_manager.models.use_vms import VMS
|
||||||
|
|
||||||
|
from .trayicon import TrayIcon
|
||||||
from .windows.main_window import MainWindow
|
from .windows.main_window import MainWindow
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -29,9 +30,11 @@ class MainApplication(Adw.Application):
|
|||||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
||||||
super().__init__(
|
super().__init__(
|
||||||
*args,
|
*args,
|
||||||
|
application_id="lol.clan.vm.manager",
|
||||||
flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
|
flags=Gio.ApplicationFlags.HANDLES_COMMAND_LINE,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
self.tray_icon: TrayIcon | None = None
|
||||||
|
|
||||||
self.add_main_option(
|
self.add_main_option(
|
||||||
"debug",
|
"debug",
|
||||||
@ -42,7 +45,7 @@ class MainApplication(Adw.Application):
|
|||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.win: Adw.ApplicationWindow | None = None
|
self.window: Adw.ApplicationWindow | None = None
|
||||||
self.connect("shutdown", self.on_shutdown)
|
self.connect("shutdown", self.on_shutdown)
|
||||||
self.connect("activate", self.show_window)
|
self.connect("activate", self.show_window)
|
||||||
|
|
||||||
@ -70,19 +73,33 @@ class MainApplication(Adw.Application):
|
|||||||
|
|
||||||
def on_shutdown(self, app: Gtk.Application) -> None:
|
def on_shutdown(self, app: Gtk.Application) -> None:
|
||||||
log.debug("Shutting down")
|
log.debug("Shutting down")
|
||||||
|
|
||||||
|
if self.tray_icon is not None:
|
||||||
|
self.tray_icon.destroy()
|
||||||
|
|
||||||
VMS.use().kill_all()
|
VMS.use().kill_all()
|
||||||
|
|
||||||
|
def on_window_hide_unhide(self, *_args: Any) -> None:
|
||||||
|
assert self.window is not None
|
||||||
|
if self.window.is_visible():
|
||||||
|
self.window.hide()
|
||||||
|
return
|
||||||
|
|
||||||
|
self.window.present()
|
||||||
|
|
||||||
|
def dummy_menu_entry(self) -> None:
|
||||||
|
log.info("Dummy menu entry called")
|
||||||
|
|
||||||
def do_activate(self) -> None:
|
def do_activate(self) -> None:
|
||||||
self.show_window()
|
self.show_window()
|
||||||
|
|
||||||
def show_window(self, app: Any = None) -> None:
|
def show_window(self, app: Any = None) -> None:
|
||||||
if not self.win:
|
if not self.window:
|
||||||
self.init_style()
|
self.init_style()
|
||||||
self.win = MainWindow(config=ClanConfig(initial_view="list"))
|
self.window = MainWindow(config=ClanConfig(initial_view="list"))
|
||||||
self.win.set_application(self)
|
self.window.set_application(self)
|
||||||
icon_path = assets.loc / "clan_black.png"
|
self.tray_icon = TrayIcon(self)
|
||||||
self.win.set_default_icon_name(str(icon_path))
|
self.window.present()
|
||||||
self.win.present()
|
|
||||||
|
|
||||||
# TODO: For css styling
|
# TODO: For css styling
|
||||||
def init_style(self) -> None:
|
def init_style(self) -> None:
|
||||||
|
1237
pkgs/clan-vm-manager/clan_vm_manager/trayicon.py
Normal file
1237
pkgs/clan-vm-manager/clan_vm_manager/trayicon.py
Normal file
File diff suppressed because it is too large
Load Diff
@ -100,12 +100,10 @@ class ClanList(Gtk.Box):
|
|||||||
box.set_valign(Gtk.Align.CENTER)
|
box.set_valign(Gtk.Align.CENTER)
|
||||||
|
|
||||||
add_button = Gtk.MenuButton()
|
add_button = Gtk.MenuButton()
|
||||||
add_button.set_icon_name("list-add")
|
|
||||||
add_button.set_has_frame(False)
|
add_button.set_has_frame(False)
|
||||||
add_button.set_menu_model(menu_model)
|
add_button.set_menu_model(menu_model)
|
||||||
|
add_button.set_label("Add machine")
|
||||||
box.append(add_button)
|
box.append(add_button)
|
||||||
box.append(Gtk.Label.new("Add machine"))
|
|
||||||
|
|
||||||
grp.set_header_suffix(box)
|
grp.set_header_suffix(box)
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
, clan-cli
|
, clan-cli
|
||||||
, makeDesktopItem
|
, makeDesktopItem
|
||||||
, libadwaita
|
, libadwaita
|
||||||
|
, libayatana-appindicator
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
source = ./.;
|
source = ./.;
|
||||||
@ -30,6 +31,7 @@ python3.pkgs.buildPythonApplication {
|
|||||||
copyDesktopItems
|
copyDesktopItems
|
||||||
wrapGAppsHook
|
wrapGAppsHook
|
||||||
gobject-introspection
|
gobject-introspection
|
||||||
|
libayatana-appindicator
|
||||||
];
|
];
|
||||||
|
|
||||||
buildInputs = [ gtk4 libadwaita gnome.adwaita-icon-theme ];
|
buildInputs = [ gtk4 libadwaita gnome.adwaita-icon-theme ];
|
||||||
@ -57,7 +59,7 @@ python3.pkgs.buildPythonApplication {
|
|||||||
'';
|
'';
|
||||||
desktopItems = [
|
desktopItems = [
|
||||||
(makeDesktopItem {
|
(makeDesktopItem {
|
||||||
name = "clan-vm-manager";
|
name = "lol.clan.vm.manager";
|
||||||
exec = "clan-vm-manager %u";
|
exec = "clan-vm-manager %u";
|
||||||
icon = ./clan_vm_manager/assets/clan_white.png;
|
icon = ./clan_vm_manager/assets/clan_white.png;
|
||||||
desktopName = "cLAN Manager";
|
desktopName = "cLAN Manager";
|
||||||
|
@ -20,18 +20,18 @@ mkShell {
|
|||||||
|
|
||||||
ln -snf ${clan-vm-manager} result
|
ln -snf ${clan-vm-manager} result
|
||||||
|
|
||||||
|
|
||||||
# install desktop file
|
# install desktop file
|
||||||
set -eou pipefail
|
set -eou pipefail
|
||||||
DESKTOP_DST=~/.local/share/applications/clan-vm-manager.desktop
|
DESKTOP_FILE_NAME=lol.clan.vm.manager.desktop
|
||||||
DESKTOP_SRC=${clan-vm-manager}/share/applications/clan-vm-manager.desktop
|
DESKTOP_DST=~/.local/share/applications/$DESKTOP_FILE_NAME
|
||||||
|
DESKTOP_SRC=${clan-vm-manager}/share/applications/$DESKTOP_FILE_NAME
|
||||||
# UI_BIN="env GTK_DEBUG=interactive ${clan-vm-manager}/bin/clan-vm-manager"
|
# UI_BIN="env GTK_DEBUG=interactive ${clan-vm-manager}/bin/clan-vm-manager"
|
||||||
UI_BIN="${clan-vm-manager}/bin/clan-vm-manager"
|
UI_BIN="${clan-vm-manager}/bin/clan-vm-manager"
|
||||||
|
|
||||||
cp -f $DESKTOP_SRC $DESKTOP_DST
|
cp -f $DESKTOP_SRC $DESKTOP_DST
|
||||||
sleep 2
|
sleep 2
|
||||||
sed -i "s|Exec=.*clan-vm-manager|Exec=$UI_BIN|" $DESKTOP_DST
|
sed -i "s|Exec=.*clan-vm-manager|Exec=$UI_BIN|" $DESKTOP_DST
|
||||||
xdg-mime default clan-vm-manager.desktop x-scheme-handler/clan
|
xdg-mime default $DESKTOP_FILE_NAME x-scheme-handler/clan
|
||||||
echo "==== Validating desktop file installation ===="
|
echo "==== Validating desktop file installation ===="
|
||||||
set -x
|
set -x
|
||||||
desktop-file-validate $DESKTOP_DST
|
desktop-file-validate $DESKTOP_DST
|
||||||
|
Loading…
Reference in New Issue
Block a user