Skip to content

Commit

Permalink
Style development version
Browse files Browse the repository at this point in the history
If the app ID indicates a development snapshot use our nightly icon, and
set the devel style on the main window.

Closes #56
  • Loading branch information
swsnr committed Dec 22, 2024
1 parent 60c94d6 commit c57fcb5
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
2 changes: 1 addition & 1 deletion resources/ui/turnon-application-window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ template $TurnOnApplicationWindow: Adw.ApplicationWindow {
Adw.StatusPage {
title: C_("application-window.status-page.title", "No devices");
description: C_("application-window.status-page.description", "Add a new device to turn it on.");
icon-name: "de.swsnr.turnon";
icon-name: bind template.startpage-icon-name;
vexpand: true;

child: Gtk.Button {
Expand Down
2 changes: 1 addition & 1 deletion resources/ui/turnon-application-window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
<object class="AdwStatusPage">
<property name="title" translatable="yes" context="application-window.status-page.title">No devices</property>
<property name="description" translatable="yes" context="application-window.status-page.description">Add a new device to turn it on.</property>
<property name="icon-name">de.swsnr.turnon</property>
<property name="icon-name" bind-source="TurnOnApplicationWindow" bind-property="startpage-icon-name" bind-flags="sync-create"/>
<property name="vexpand">true</property>
<property name="child">
<object class="GtkButton">
Expand Down
24 changes: 22 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ impl TurnOnApplication {
Some(crate::config::VERSION),
);

if app.is_development() {
dialog.set_version("devel");
dialog.set_application_icon(&app.application_id().unwrap());
}

glib::spawn_future_local(glib::clone!(
#[strong(rename_to = devices)]
app.devices(),
Expand Down Expand Up @@ -110,6 +115,12 @@ impl TurnOnApplication {
self.set_accels_for_action("window.close", &["<Control>w"]);
self.set_accels_for_action("app.quit", &["<Control>q"]);
}

fn is_development(&self) -> bool {
self.application_id()
.map(|id| id.ends_with(".Devel"))
.unwrap_or_default()
}
}

impl Default for TurnOnApplication {
Expand Down Expand Up @@ -293,7 +304,13 @@ mod imp {
fn startup(&self) {
self.parent_startup();
let app = self.obj();
glib::debug!("Application starting");

if app.is_development() {
glib::warn!("Application starting (DEVELOPMENT BUILD)");
} else {
glib::debug!("Application starting");
}

gtk::Window::set_default_icon_name(super::APP_ID);

app.setup_actions();
Expand Down Expand Up @@ -345,7 +362,10 @@ mod imp {
}
None => {
glib::debug!("Creating new application window");
let window = TurnOnApplicationWindow::new(app);
let window = TurnOnApplicationWindow::new(app, &app.application_id().unwrap());
if app.is_development() {
window.add_css_class("devel");
}
window.bind_model(&self.devices);
window.present();
}
Expand Down
43 changes: 24 additions & 19 deletions src/app/widgets/application_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ glib::wrapper! {

impl TurnOnApplicationWindow {
/// Create a new application window for the given `application`.
pub fn new(application: &impl IsA<gtk::Application>) -> Self {
pub fn new(application: &impl IsA<gtk::Application>, startpage_icon_name: &str) -> Self {
glib::Object::builder()
.property("application", application)
.property("startpage-icon-name", startpage_icon_name)
.build()
}

Expand Down Expand Up @@ -90,32 +91,18 @@ mod imp {

use super::super::DeviceRow;

#[derive(CompositeTemplate, Default)]
#[derive(CompositeTemplate, Default, glib::Properties)]
#[properties(wrapper_type = super::TurnOnApplicationWindow)]
#[template(resource = "/de/swsnr/turnon/ui/turnon-application-window.ui")]
pub struct TurnOnApplicationWindow {
#[property(get, set)]
startpage_icon_name: RefCell<String>,
#[template_child]
devices_list: TemplateChild<gtk::ListBox>,
#[template_child]
feedback: TemplateChild<ToastOverlay>,
}

#[glib::object_subclass]
impl ObjectSubclass for TurnOnApplicationWindow {
const NAME: &'static str = "TurnOnApplicationWindow";

type Type = super::TurnOnApplicationWindow;

type ParentType = adw::ApplicationWindow;

fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}

fn instance_init(obj: &InitializingObject<Self>) {
obj.init_template();
}
}

impl TurnOnApplicationWindow {
pub fn bind_model(&self, model: &Devices) {
self.devices_list.get().bind_model(
Expand Down Expand Up @@ -259,6 +246,24 @@ mod imp {
}
}

#[glib::object_subclass]
impl ObjectSubclass for TurnOnApplicationWindow {
const NAME: &'static str = "TurnOnApplicationWindow";

type Type = super::TurnOnApplicationWindow;

type ParentType = adw::ApplicationWindow;

fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}

fn instance_init(obj: &InitializingObject<Self>) {
obj.init_template();
}
}

#[glib::derived_properties]
impl ObjectImpl for TurnOnApplicationWindow {}

impl WidgetImpl for TurnOnApplicationWindow {}
Expand Down

0 comments on commit c57fcb5

Please sign in to comment.