2022-05-26 11:59:09 -04:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2022-02-18 10:31:12 -05:00
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
|
extern crate relm4_macros;
|
|
|
|
|
|
2022-02-22 12:50:23 -05:00
|
|
|
pub mod session_manager;
|
2022-02-18 12:10:01 -05:00
|
|
|
pub mod ui;
|
|
|
|
|
|
2022-07-01 22:29:06 -07:00
|
|
|
use gtk4::{gio::ApplicationFlags, prelude::*, Align, Button, Label, Orientation, Separator};
|
2022-02-18 10:31:12 -05:00
|
|
|
use once_cell::sync::Lazy;
|
2022-06-10 18:10:26 -07:00
|
|
|
use std::process::Command;
|
2022-02-18 10:31:12 -05:00
|
|
|
use tokio::runtime::Runtime;
|
|
|
|
|
|
|
|
|
|
static RT: Lazy<Runtime> = Lazy::new(|| Runtime::new().expect("failed to build tokio runtime"));
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
let application = gtk4::Application::new(
|
2022-07-27 15:41:33 -04:00
|
|
|
None,
|
2022-02-18 10:31:12 -05:00
|
|
|
ApplicationFlags::default(),
|
|
|
|
|
);
|
|
|
|
|
application.connect_activate(build_ui);
|
|
|
|
|
application.run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn build_ui(application: >k4::Application) {
|
2022-05-26 12:52:34 -04:00
|
|
|
view! {
|
2022-07-05 14:41:09 -07:00
|
|
|
window = libcosmic_applet::AppletWindow {
|
2022-07-01 22:29:06 -07:00
|
|
|
set_title: Some("COSMIC Power Applet"),
|
|
|
|
|
set_application: Some(application),
|
|
|
|
|
// TODO adjust battery icon based on charge
|
|
|
|
|
#[wrap(Some)]
|
2022-07-05 14:41:09 -07:00
|
|
|
set_child = &libcosmic_applet::AppletButton {
|
|
|
|
|
set_button_icon_name: "system-shutdown-symbolic",
|
|
|
|
|
#[wrap(Some)]
|
|
|
|
|
set_popover_child: main_box = >k4::Box {
|
|
|
|
|
set_orientation: Orientation::Vertical,
|
|
|
|
|
set_spacing: 10,
|
|
|
|
|
set_margin_top: 20,
|
|
|
|
|
set_margin_bottom: 20,
|
|
|
|
|
set_margin_start: 24,
|
|
|
|
|
set_margin_end: 24,
|
|
|
|
|
append: settings_button = &Button {
|
|
|
|
|
#[wrap(Some)]
|
|
|
|
|
set_child = &Label {
|
|
|
|
|
set_label: "Settings...",
|
|
|
|
|
set_halign: Align::Start,
|
|
|
|
|
set_hexpand: true
|
|
|
|
|
},
|
|
|
|
|
connect_clicked => move |_| {
|
|
|
|
|
let _ = Command::new("cosmic-settings").spawn();
|
|
|
|
|
}
|
2022-07-01 22:29:06 -07:00
|
|
|
},
|
2022-07-05 14:41:09 -07:00
|
|
|
append = &Separator {},
|
|
|
|
|
append: &ui::session::build(),
|
|
|
|
|
append: second_separator = &Separator {},
|
|
|
|
|
append: &ui::system::build(),
|
|
|
|
|
}
|
2022-07-01 22:29:06 -07:00
|
|
|
}
|
2022-02-18 10:31:12 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
window.show();
|
|
|
|
|
}
|