improv(about): support custom license URLs

This commit is contained in:
Tony4dev 2025-09-03 12:49:35 +00:00 committed by GitHub
parent 4d06524f2c
commit 2dd6dce053
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View file

@ -71,6 +71,7 @@ impl cosmic::Application for App {
.version("0.1.0")
.author("System 76")
.license("GPL-3.0-only")
//.license_url("https://www.some-custom-license-url.com")
.developers([("Michael Murphy", "mmstick@system76.com")])
.links([
("Website", "https://system76.com/cosmic"),

View file

@ -25,6 +25,8 @@ pub struct About {
copyright: Option<String>,
/// The license name.
license: Option<String>,
/// The license url. If None spdx.org url is used.
license_url: Option<String>,
/// Artists who contributed to the application.
#[setters(skip)]
artists: Vec<(String, String)>,
@ -95,10 +97,12 @@ impl<'a> About {
self
}
fn license_url(&self) -> Option<String> {
self.license.as_ref().and_then(|license_str| {
let license: &dyn License = license_str.parse().ok()?;
Some(format!("https://spdx.org/licenses/{}.html", license.id()))
fn get_license_url(&self) -> Option<String> {
self.license_url.clone().or_else(|| {
self.license.as_ref().and_then(|license_str| {
let license: &dyn License = license_str.parse().ok()?;
Some(format!("https://spdx.org/licenses/{}.html", license.id()))
})
})
}
}
@ -153,7 +157,7 @@ pub fn about<'a, Message: Clone + 'static>(
let translators_section = section(&about.translators, "Translators");
let documenters_section = section(&about.documenters, "Documenters");
let license = about.license.as_ref().map(|license| {
let url = about.license_url();
let url = about.get_license_url();
widget::settings::section().title("License").add(
widget::button::custom(
widget::row()