extends Node var tray_icon: StatusIndicator var tray_menu: PopupMenu func _ready() -> void: setup_tray() func setup_tray() -> void: # 1. Initialize the StatusIndicator tray_icon = StatusIndicator.new() tray_icon.icon = load("res://ship-icon-256.png") # Path to your 16x16 or 32x32 icon tray_icon.tooltip = "EnvoyOS" add_child(tray_icon) # 2. Bind the click event to restore the window tray_icon.pressed.connect(_on_tray_icon_pressed) # 3. Optional: Create a right-click context menu tray_menu = PopupMenu.new() tray_menu.add_item("Show Window", 0) tray_menu.add_item("Quit", 1) tray_menu.id_pressed.connect(_on_menu_item_pressed) add_child(tray_menu) # Assign menu to the tray icon tray_icon.menu = tray_menu.get_path() # Handle window close interception func _notification(what: int) -> void: if what == NOTIFICATION_WM_CLOSE_REQUEST: minimize_to_tray() # Hides the application entirely from desktop view func minimize_to_tray() -> void: # Hide window from taskbar and ignore standard user inputs DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_NO_FOCUS, true) # Hide the actual window frame DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MINIMIZED) # Restores the application window back to normal func restore_from_tray() -> void: DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_NO_FOCUS, false) DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) # Handle clicking directly on the tray icon func _on_tray_icon_pressed(mouse_button: int, _device_id: int) -> void: if mouse_button == MOUSE_BUTTON_LEFT: restore_from_tray() # Handle context menu actions func _on_menu_item_pressed(id: int) -> void: match id: 0: restore_from_tray() 1: get_tree().quit() # Ensure clean termination when explicitly chosen