feat(about): editable hostname input
This commit is contained in:
parent
44a333d070
commit
9963844b58
6 changed files with 294 additions and 155 deletions
355
Cargo.lock
generated
355
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -48,6 +48,9 @@ itoa = "1.0.10"
|
||||||
futures = { package = "futures-lite", version = "2.2.0" }
|
futures = { package = "futures-lite", version = "2.2.0" }
|
||||||
xkb-data = "0.1.0"
|
xkb-data = "0.1.0"
|
||||||
udev = "0.8.0"
|
udev = "0.8.0"
|
||||||
|
hostname-validator = "1.1.1"
|
||||||
|
hostname1-zbus = "0.1.0"
|
||||||
|
zbus = { version = "3.15.2", features = ["tokio"] }
|
||||||
|
|
||||||
[dependencies.i18n-embed]
|
[dependencies.i18n-embed]
|
||||||
version = "0.14.1"
|
version = "0.14.1"
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,26 @@
|
||||||
// Copyright 2023 System76 <info@system76.com>
|
// Copyright 2023 System76 <info@system76.com>
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
|
use cosmic::iced::Length;
|
||||||
use cosmic_settings_page::{self as page, section, Section};
|
use cosmic_settings_page::{self as page, section, Section};
|
||||||
|
|
||||||
use cosmic::widget::{list_column, settings, text};
|
use cosmic::widget::{self, editable_input, list_column, settings, text};
|
||||||
use cosmic::{command, Command};
|
use cosmic::{command, Apply, Command};
|
||||||
use cosmic_settings_system::about::Info;
|
use cosmic_settings_system::about::Info;
|
||||||
use slotmap::SlotMap;
|
use slotmap::SlotMap;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum Message {
|
pub enum Message {
|
||||||
|
HostnameEdit(bool),
|
||||||
|
HostnameInput(String),
|
||||||
|
HostnameSubmit,
|
||||||
Info(Box<Info>),
|
Info(Box<Info>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct Page {
|
pub struct Page {
|
||||||
|
editing_device_name: bool,
|
||||||
info: Info,
|
info: Info,
|
||||||
// support_page: page::Entity,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl page::AutoBind<crate::pages::Message> for Page {}
|
impl page::AutoBind<crate::pages::Message> for Page {}
|
||||||
|
|
@ -50,6 +54,48 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
impl Page {
|
impl Page {
|
||||||
pub fn update(&mut self, message: Message) {
|
pub fn update(&mut self, message: Message) {
|
||||||
match message {
|
match message {
|
||||||
|
Message::HostnameEdit(editing) => {
|
||||||
|
self.editing_device_name = editing;
|
||||||
|
}
|
||||||
|
|
||||||
|
Message::HostnameInput(hostname) => {
|
||||||
|
self.info.device_name = hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
Message::HostnameSubmit => {
|
||||||
|
let hostname = &self.info.device_name;
|
||||||
|
if hostname_validator::is_valid(hostname) {
|
||||||
|
// TODO: display errors
|
||||||
|
self.editing_device_name = false;
|
||||||
|
let hostname = hostname.clone();
|
||||||
|
tokio::task::spawn(async move {
|
||||||
|
let connection = match zbus::Connection::system().await {
|
||||||
|
Ok(conn) => conn,
|
||||||
|
Err(why) => {
|
||||||
|
tracing::error!(?why, "failed to establish connection to dbus");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let hostname1 = match hostname1_zbus::Hostname1Proxy::new(&connection).await
|
||||||
|
{
|
||||||
|
Ok(proxy) => proxy,
|
||||||
|
Err(why) => {
|
||||||
|
tracing::error!(
|
||||||
|
?why,
|
||||||
|
"failed to connect to org.freedesktop.hostname1"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(why) = hostname1.set_static_hostname(&hostname, false).await {
|
||||||
|
tracing::error!(?why, "failed to set static hostname");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Message::Info(info) => self.info = *info,
|
Message::Info(info) => self.info = *info,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -63,11 +109,28 @@ fn device() -> Section<crate::pages::Message> {
|
||||||
])
|
])
|
||||||
.view::<Page>(|_binder, page, section| {
|
.view::<Page>(|_binder, page, section| {
|
||||||
let desc = §ion.descriptions;
|
let desc = §ion.descriptions;
|
||||||
|
|
||||||
|
let hostname_input = editable_input(
|
||||||
|
"",
|
||||||
|
&page.info.device_name,
|
||||||
|
page.editing_device_name,
|
||||||
|
Message::HostnameEdit,
|
||||||
|
)
|
||||||
|
.on_input(Message::HostnameInput)
|
||||||
|
.on_submit(Message::HostnameSubmit);
|
||||||
|
|
||||||
|
let hostname_row = widget::row::with_capacity(2)
|
||||||
|
.push(widget::horizontal_space(Length::Fill))
|
||||||
|
.push(hostname_input);
|
||||||
|
|
||||||
let device_name = settings::item::builder(&*desc[0])
|
let device_name = settings::item::builder(&*desc[0])
|
||||||
.description(&*desc[1])
|
.description(&*desc[1])
|
||||||
.control(text(&page.info.device_name));
|
.control(hostname_row);
|
||||||
|
|
||||||
list_column().add(device_name).into()
|
list_column()
|
||||||
|
.add(device_name)
|
||||||
|
.apply(cosmic::Element::from)
|
||||||
|
.map(crate::pages::Message::About)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
1
debian/install
vendored
1
debian/install
vendored
|
|
@ -16,6 +16,7 @@
|
||||||
/usr/share/applications/com.system76.CosmicSettings.Wallpaper.desktop
|
/usr/share/applications/com.system76.CosmicSettings.Wallpaper.desktop
|
||||||
/usr/share/applications/com.system76.CosmicSettings.Workspaces.desktop
|
/usr/share/applications/com.system76.CosmicSettings.Workspaces.desktop
|
||||||
/usr/share/metainfo/com.system76.CosmicSettings.metainfo.xml
|
/usr/share/metainfo/com.system76.CosmicSettings.metainfo.xml
|
||||||
|
/usr/share/polkit-1/rules.d/cosmic-settings.rules
|
||||||
/usr/share/cosmic/com.system76.CosmicTheme.Dark
|
/usr/share/cosmic/com.system76.CosmicTheme.Dark
|
||||||
/usr/share/cosmic/com.system76.CosmicTheme.Dark.Builder
|
/usr/share/cosmic/com.system76.CosmicTheme.Dark.Builder
|
||||||
/usr/share/cosmic/com.system76.CosmicTheme.Light
|
/usr/share/cosmic/com.system76.CosmicTheme.Light
|
||||||
|
|
|
||||||
5
justfile
5
justfile
|
|
@ -20,6 +20,9 @@ metainfo := appid + '.metainfo.xml'
|
||||||
metainfo-src := 'resources' / metainfo
|
metainfo-src := 'resources' / metainfo
|
||||||
metainfo-dst := clean(rootdir / prefix) / 'share' / 'metainfo' / metainfo
|
metainfo-dst := clean(rootdir / prefix) / 'share' / 'metainfo' / metainfo
|
||||||
|
|
||||||
|
polkit-rules-src := 'resources' / 'polkit-1' / 'rules.d' / 'cosmic-settings.rules'
|
||||||
|
polkit-rules-dst := clean(rootdir / prefix) / 'share' / 'polkit-1' / 'rules.d' / 'cosmic-settings.rules'
|
||||||
|
|
||||||
# Desktop entries
|
# Desktop entries
|
||||||
entry-settings := appid + '.desktop'
|
entry-settings := appid + '.desktop'
|
||||||
entry-about := appid + '.About.desktop'
|
entry-about := appid + '.About.desktop'
|
||||||
|
|
@ -62,7 +65,7 @@ install-desktop-entries:
|
||||||
install -Dm0644 'resources/{{entry-workspaces}}' '{{appdir}}/{{entry-workspaces}}'
|
install -Dm0644 'resources/{{entry-workspaces}}' '{{appdir}}/{{entry-workspaces}}'
|
||||||
|
|
||||||
# Install everything
|
# Install everything
|
||||||
install: install-desktop-entries (install-bin bin-src bin-dest) (install-file metainfo-src metainfo-dst)
|
install: install-desktop-entries (install-bin bin-src bin-dest) (install-file metainfo-src metainfo-dst) (install-file polkit-rules-src polkit-rules-dst)
|
||||||
find 'resources'/'default_schema' -type f -exec echo {} \; | rev | cut -d'/' -f-3 | rev | xargs -d '\n' -I {} install -Dm0644 'resources'/'default_schema'/{} {{default-schema-target}}/{}
|
find 'resources'/'default_schema' -type f -exec echo {} \; | rev | cut -d'/' -f-3 | rev | xargs -d '\n' -I {} install -Dm0644 'resources'/'default_schema'/{} {{default-schema-target}}/{}
|
||||||
find 'resources'/'icons' -type f -exec echo {} \; | rev | cut -d'/' -f-3 | rev | xargs -d '\n' -I {} install -Dm0644 'resources'/'icons'/{} {{iconsdir}}/{}
|
find 'resources'/'icons' -type f -exec echo {} \; | rev | cut -d'/' -f-3 | rev | xargs -d '\n' -I {} install -Dm0644 'resources'/'icons'/{} {{iconsdir}}/{}
|
||||||
|
|
||||||
|
|
|
||||||
12
resources/polkit-1/rules.d/cosmic-settings.rules
Normal file
12
resources/polkit-1/rules.d/cosmic-settings.rules
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
polkit.addRule(function(action, subject) {
|
||||||
|
if ((action.id == "org.freedesktop.locale1.set-locale" ||
|
||||||
|
action.id == "org.freedesktop.locale1.set-keyboard" ||
|
||||||
|
action.id == "org.freedesktop.ModemManager1.Device.Control" ||
|
||||||
|
action.id == "org.freedesktop.hostname1.set-static-hostname" ||
|
||||||
|
action.id == "org.freedesktop.hostname1.set-hostname") &&
|
||||||
|
subject.local &&
|
||||||
|
subject.active &&
|
||||||
|
subject.isInGroup ("sudo")) {
|
||||||
|
return polkit.Result.YES;
|
||||||
|
}
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue