diff --git a/Cargo.toml b/Cargo.toml index 15bce68..5eaa0ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ include = [ [dependencies] -relm4 = { version = "0.6.2", features = ["macros", "libadwaita", "gnome_44"] } +relm4 = { version = "0.6.2", features = ["macros", "libadwaita", "gnome_42"] } pangocairo = "0.17.10" tokio = { version = "1.32.0", features = ["full"] } gdk-pixbuf = "0.17.2" diff --git a/release.nu b/release.nu new file mode 100644 index 0000000..2784f45 --- /dev/null +++ b/release.nu @@ -0,0 +1,143 @@ +#!/usr/bin/env nu + +use std assert + +export def main [version: string] { + # make sure the working tree is clean + assert_repo_is_clean + + let read_version = version_read_cargo_toml + let requested_version = $version | version_parse + let requested_version_tag = $requested_version | version_to_string + + $"Updating version from ($read_version | version_print) to ($requested_version | version_print)" | echo_section_headline + + if not (is_newer $read_version $requested_version) { + echo "Requested version is older than current verion. Aborting." + exit 1 + } + + # update the cargo toml + patch_cargo_toml $requested_version + + # update cargo lock + update_cargo_lock + + # commit + git_commit $requested_version_tag + + # tag a new git version + git_tag $requested_version_tag + + # build artifact + build_artifact + + ## from here on we go online! + # push + git_push + + # create release + github_release $requested_version_tag + + # upload artifact + upload_artifact $requested_version_tag +} + + +def echo_section_headline []: string -> nothing { + echo $"\n(ansi yellow)++ ($in)(ansi reset)" +} + +def assert_repo_is_clean [] { + if (git diff --quiet | complete | get exit_code) != 0 { + echo "The git repository is not clean! Aborting..." + exit 1 + } else {} +} + +def git_tag [tag: string] { + assert_repo_is_clean + + $"Creating Git Tag ($tag) " | echo_section_headline + git tag ($tag) +} + +def git_push [] { + "Pushing to GitHub" | echo_section_headline + git push; git push --tags +} + +def patch_cargo_toml [version: list] { + "Updating Cargo.toml" | echo_section_headline + let sed_string = $"'/package/,/version =/{s/version.*/version = \"($version | str join '.')\"/}'" + sed -i $sed_string Cargo.toml + git --no-pager diff +} + +def update_cargo_lock [] { + "Updating Cargo.lock" | echo_section_headline + cargo generate-lockfile +} + +def git_commit [tag: string] { + "Commiting..." | echo_section_headline + git commit -am $"Updating version to ($tag)" +} + +def github_release [tag: string] { + $"Creating GitHub release ($tag)" | echo_section_headline + gh release create $tag +} + +def build_artifact [] { + "Building Artifact" | echo_section_headline + make package +} + +def upload_artifact [tag: string] { + "Uploading Artifact" | echo_section_headline + gh release upload $tag $"satty-($tag)-x86_64.tar.gz" +} + +def version_parse []: string -> list { + $in | str trim -c 'v' --left | split row '.' | each {|n| into int } +} + +def version_to_string []: list -> string { + $"v($in | str join '.')" +} + +def version_read_cargo_toml []: nothing -> list { + open Cargo.toml | get package.version | version_parse +} + +def version_print []: list -> nothing { + echo $"($in | version_to_string)" +} + +def is_newer [ + old: list, + new: list + ]: nothing -> bool { + + let length = [($old | length) ($new | length)] | math min + + for i in 0..<($length) { + if ($new | get $i) > ($old | get $i) { + return true + } else {} + if ($new | get $i) < ($old | get $i) { + return false + } else {} + } + + return false +} + +#[test] +def test_versions [] { + assert (is_newer [1 0 0] [2 0 0]) "major version" + assert (is_newer [1 0 0] [1 1]) "minor version, shorter" + assert not (is_newer [1 1 0] [1 1]) "minor version, shorter" + assert not (is_newer [1 1 0] [0 1]) "minor version, shorter" +} \ No newline at end of file diff --git a/src/ui/toolbars.rs b/src/ui/toolbars.rs index 4c8d00c..b0f0fd4 100644 --- a/src/ui/toolbars.rs +++ b/src/ui/toolbars.rs @@ -12,7 +12,7 @@ use gdk_pixbuf::{ }; use relm4::{ actions::{ActionablePlus, RelmAction, RelmActionGroup}, - gtk::{prelude::*, Align, ColorDialog, Window}, + gtk::{prelude::*, Align, ColorChooserDialog, ResponseType}, prelude::*, }; @@ -228,22 +228,29 @@ pub enum ColorButtons { } impl StyleToolbar { - fn show_color_dialog(&self, sender: ComponentSender, root: Option) { + fn show_color_dialog(&self, sender: ComponentSender) { let current_color = Some(self.custom_color.into()); relm4::spawn_local(async move { - let dialog = ColorDialog::builder() + let dialog = ColorChooserDialog::builder() .modal(true) .title("Choose Color") - .with_alpha(true) + .hide_on_close(true) .build(); + dialog.set_use_alpha(true); + if let Some(color) = current_color.as_ref() { + dialog.set_rgba(color); + } - let color = dialog - .choose_rgba_future(root.as_ref(), current_color.as_ref()) - .await - .ok() - .map(Color::from_gdk); + let dialog_copy = dialog.clone(); + dialog.connect_response(move |_, r| { + if r == ResponseType::Ok { + dialog_copy.hide(); + let color = Color::from_gdk(dialog_copy.rgba()); + sender.input(StyleToolbarInput::ColorDialogFinished(Some(color))); + } + }); - sender.input(StyleToolbarInput::ColorDialogFinished(color)); + dialog.show(); }); } @@ -371,10 +378,10 @@ impl Component for StyleToolbar { }, } - fn update(&mut self, message: Self::Input, sender: ComponentSender, root: &Self::Root) { + fn update(&mut self, message: Self::Input, sender: ComponentSender, _root: &Self::Root) { match message { StyleToolbarInput::ShowColorDialog => { - self.show_color_dialog(sender, root.toplevel_window()); + self.show_color_dialog(sender); } StyleToolbarInput::ColorDialogFinished(color) => { if let Some(color) = color {