chore: clippy
This commit is contained in:
parent
a8d8e14413
commit
b3be053f33
27 changed files with 654 additions and 706 deletions
|
|
@ -121,11 +121,11 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
|
|
||||||
let mut local_list = mime_apps::List::default();
|
let mut local_list = mime_apps::List::default();
|
||||||
|
|
||||||
if let Some(path) = mime_apps::local_list_path() {
|
if let Some(path) = mime_apps::local_list_path()
|
||||||
if let Ok(buffer) = std::fs::read_to_string(&path) {
|
&& let Ok(buffer) = std::fs::read_to_string(&path)
|
||||||
|
{
|
||||||
local_list.load_from(&buffer);
|
local_list.load_from(&buffer);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let assocs = mime_apps::associations::by_app();
|
let assocs = mime_apps::associations::by_app();
|
||||||
|
|
||||||
|
|
@ -245,11 +245,12 @@ impl Page {
|
||||||
meta.selected = Some(id);
|
meta.selected = Some(id);
|
||||||
let appid = &meta.app_ids[id];
|
let appid = &meta.app_ids[id];
|
||||||
|
|
||||||
if category == Category::Terminal && self.shortcuts_config.is_some() {
|
if category == Category::Terminal
|
||||||
if let Some(config) = self.shortcuts_config.as_ref() {
|
&& self.shortcuts_config.is_some()
|
||||||
|
&& let Some(config) = self.shortcuts_config.as_ref()
|
||||||
|
{
|
||||||
assign_default_terminal(config, appid);
|
assign_default_terminal(config, appid);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for mime in mime_types {
|
for mime in mime_types {
|
||||||
if let Ok(mime) = mime.parse() {
|
if let Ok(mime) = mime.parse() {
|
||||||
|
|
@ -450,8 +451,9 @@ fn assign_default_terminal(config: &cosmic_config::Config, appid: &str) {
|
||||||
if let Some(resolved_path) = resolved_path {
|
if let Some(resolved_path) = resolved_path {
|
||||||
let desktop_entry = DesktopEntry::from_path(resolved_path, Some(&get_languages_from_env()));
|
let desktop_entry = DesktopEntry::from_path(resolved_path, Some(&get_languages_from_env()));
|
||||||
|
|
||||||
if let Ok(desktop_entry) = desktop_entry {
|
if let Ok(desktop_entry) = desktop_entry
|
||||||
if let Some(exec) = desktop_entry.exec() {
|
&& let Some(exec) = desktop_entry.exec()
|
||||||
|
{
|
||||||
actions.insert(System::Terminal, String::from(exec));
|
actions.insert(System::Terminal, String::from(exec));
|
||||||
|
|
||||||
if let Err(why) = config.set("system_actions", actions) {
|
if let Err(why) = config.set("system_actions", actions) {
|
||||||
|
|
@ -459,7 +461,6 @@ fn assign_default_terminal(config: &cosmic_config::Config, appid: &str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn load_defaults(assocs: &BTreeMap<Arc<str>, Arc<App>>, for_mimes: &[&str]) -> AppMeta {
|
async fn load_defaults(assocs: &BTreeMap<Arc<str>, Arc<App>>, for_mimes: &[&str]) -> AppMeta {
|
||||||
|
|
@ -500,11 +501,11 @@ async fn load_defaults(assocs: &BTreeMap<Arc<str>, Arc<App>>, for_mimes: &[&str]
|
||||||
let mut icons = Vec::new();
|
let mut icons = Vec::new();
|
||||||
|
|
||||||
for (id, (appid, app)) in unsorted.iter().enumerate() {
|
for (id, (appid, app)) in unsorted.iter().enumerate() {
|
||||||
if let Some(current_app) = current_app {
|
if let Some(current_app) = current_app
|
||||||
if app.name.as_ref() == current_app.name.as_ref() {
|
&& app.name.as_ref() == current_app.name.as_ref()
|
||||||
|
{
|
||||||
selected = Some(id);
|
selected = Some(id);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
app_ids.push(appid.as_ref().into());
|
app_ids.push(appid.as_ref().into());
|
||||||
apps.push(app.name.as_ref().into());
|
apps.push(app.name.as_ref().into());
|
||||||
|
|
@ -562,12 +563,13 @@ async fn load_terminal_apps(assocs: &BTreeMap<Arc<str>, Arc<App>>) -> AppMeta {
|
||||||
|
|
||||||
// Scan desktop entries for terminal applications
|
// Scan desktop entries for terminal applications
|
||||||
for path in DesktopEntryIter::new(default_paths()) {
|
for path in DesktopEntryIter::new(default_paths()) {
|
||||||
if let Ok(bytes) = std::fs::read_to_string(&path) {
|
if let Ok(bytes) = std::fs::read_to_string(&path)
|
||||||
if let Ok(entry) = DesktopEntry::from_str(&path, &bytes, None::<&[&str]>) {
|
&& let Ok(entry) = DesktopEntry::from_str(&path, &bytes, None::<&[&str]>)
|
||||||
|
{
|
||||||
// Check if it's a terminal application
|
// Check if it's a terminal application
|
||||||
if entry
|
if entry
|
||||||
.categories()
|
.categories()
|
||||||
.map(|cats| cats.iter().any(|c| *c == "TerminalEmulator"))
|
.map(|cats| cats.contains(&"TerminalEmulator"))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
{
|
{
|
||||||
let id = entry.id();
|
let id = entry.id();
|
||||||
|
|
@ -580,7 +582,6 @@ async fn load_terminal_apps(assocs: &BTreeMap<Arc<str>, Arc<App>>) -> AppMeta {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
terminals.sort_unstable_by_key(|(_, app): &(Arc<str>, Arc<App>)| app.name.clone());
|
terminals.sort_unstable_by_key(|(_, app): &(Arc<str>, Arc<App>)| app.name.clone());
|
||||||
terminals.dedup_by(|a, b| a.0 == b.0);
|
terminals.dedup_by(|a, b| a.0 == b.0);
|
||||||
|
|
@ -591,11 +592,11 @@ async fn load_terminal_apps(assocs: &BTreeMap<Arc<str>, Arc<App>>) -> AppMeta {
|
||||||
let mut icons = Vec::new();
|
let mut icons = Vec::new();
|
||||||
|
|
||||||
for (id, (appid, app)) in terminals.iter().enumerate() {
|
for (id, (appid, app)) in terminals.iter().enumerate() {
|
||||||
if let Some(ref current_app) = current_app {
|
if let Some(ref current_app) = current_app
|
||||||
if app.name.as_ref() == current_app.name.as_ref() {
|
&& app.name.as_ref() == current_app.name.as_ref()
|
||||||
|
{
|
||||||
selected = Some(id);
|
selected = Some(id);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
app_ids.push(appid.to_string());
|
app_ids.push(appid.to_string());
|
||||||
apps.push(app.name.as_ref().into());
|
apps.push(app.name.as_ref().into());
|
||||||
|
|
|
||||||
|
|
@ -138,12 +138,12 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
let (randr_task, randr_handle) =
|
let (randr_task, randr_handle) =
|
||||||
Task::stream(async_fn_stream::fn_stream(|emitter| async move {
|
Task::stream(async_fn_stream::fn_stream(|emitter| async move {
|
||||||
while let Ok(message) = rx.recv().await {
|
while let Ok(message) = rx.recv().await {
|
||||||
if let cosmic_randr::Message::ManagerDone = message {
|
if let cosmic_randr::Message::ManagerDone = message
|
||||||
if !refresh_pending.swap(true, Ordering::SeqCst) {
|
&& !refresh_pending.swap(true, Ordering::SeqCst)
|
||||||
|
{
|
||||||
_ = emitter.emit(on_enter().await).await;
|
_ = emitter.emit(on_enter().await).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
.abortable();
|
.abortable();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -157,9 +157,10 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dialog(&self) -> Option<crate::pages::Element<'_>> {
|
fn dialog(&self) -> Option<crate::pages::Element<'_>> {
|
||||||
if let Some(app_to_remove) = &self.app_to_remove {
|
if let Some(app_to_remove) = &self.app_to_remove
|
||||||
if let Some(cached_startup_apps) = &self.cached_startup_apps {
|
&& let Some(cached_startup_apps) = &self.cached_startup_apps
|
||||||
if let Some(target_directory_type) = &self.target_directory_type {
|
&& let Some(target_directory_type) = &self.target_directory_type
|
||||||
|
{
|
||||||
return Some(
|
return Some(
|
||||||
widget::dialog()
|
widget::dialog()
|
||||||
.title(fl!(
|
.title(fl!(
|
||||||
|
|
@ -186,8 +187,6 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
.apply(Element::from),
|
.apply(Element::from),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -228,8 +227,9 @@ impl Page {
|
||||||
|
|
||||||
_ = std::fs::create_dir_all(directory_to_target.as_path());
|
_ = std::fs::create_dir_all(directory_to_target.as_path());
|
||||||
|
|
||||||
if let Ok(exists) = std::fs::exists(directory_to_target.join(file_name.clone())) {
|
if let Ok(exists) = std::fs::exists(directory_to_target.join(file_name.clone()))
|
||||||
if !exists {
|
&& !exists
|
||||||
|
{
|
||||||
// when adding an application, we want to symlink to be more user-friendly
|
// when adding an application, we want to symlink to be more user-friendly
|
||||||
// this ensures that, as an application gets updated / removed, so does the
|
// this ensures that, as an application gets updated / removed, so does the
|
||||||
// symlink
|
// symlink
|
||||||
|
|
@ -238,8 +238,7 @@ impl Page {
|
||||||
directory_to_target.join(file_name),
|
directory_to_target.join(file_name),
|
||||||
) {
|
) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
if let Some(ref mut cached_startup_apps) = self.cached_startup_apps
|
if let Some(ref mut cached_startup_apps) = self.cached_startup_apps {
|
||||||
{
|
|
||||||
let target_apps = cached_startup_apps.apps.get(&directory_type);
|
let target_apps = cached_startup_apps.apps.get(&directory_type);
|
||||||
if let Some(target_apps) = target_apps {
|
if let Some(target_apps) = target_apps {
|
||||||
let mut new_apps = target_apps.clone();
|
let mut new_apps = target_apps.clone();
|
||||||
|
|
@ -256,7 +255,6 @@ impl Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
self.context = None;
|
self.context = None;
|
||||||
}
|
}
|
||||||
|
|
@ -273,16 +271,14 @@ impl Page {
|
||||||
let directory_to_target =
|
let directory_to_target =
|
||||||
directories.first().expect("Always at least one directory");
|
directories.first().expect("Always at least one directory");
|
||||||
if let Ok(exists) = std::fs::exists(directory_to_target.join(file_name.clone()))
|
if let Ok(exists) = std::fs::exists(directory_to_target.join(file_name.clone()))
|
||||||
|
&& exists
|
||||||
{
|
{
|
||||||
if exists {
|
|
||||||
// remove_file works for both regular files & symlinks
|
// remove_file works for both regular files & symlinks
|
||||||
match std::fs::remove_file(directory_to_target.join(file_name)) {
|
match std::fs::remove_file(directory_to_target.join(file_name)) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
if let Some(ref mut cached_startup_apps) =
|
if let Some(ref mut cached_startup_apps) = self.cached_startup_apps
|
||||||
self.cached_startup_apps
|
|
||||||
{
|
{
|
||||||
let target_apps =
|
let target_apps = cached_startup_apps.apps.get(&directory_type);
|
||||||
cached_startup_apps.apps.get(&directory_type);
|
|
||||||
if let Some(target_apps) = target_apps {
|
if let Some(target_apps) = target_apps {
|
||||||
let mut new_apps = Vec::new();
|
let mut new_apps = Vec::new();
|
||||||
for old_app in target_apps {
|
for old_app in target_apps {
|
||||||
|
|
@ -302,7 +298,6 @@ impl Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
self.app_to_remove = None;
|
self.app_to_remove = None;
|
||||||
self.target_directory_type = None;
|
self.target_directory_type = None;
|
||||||
self.context = None;
|
self.context = None;
|
||||||
|
|
@ -330,19 +325,18 @@ impl Page {
|
||||||
|
|
||||||
if let Some(startup_apps) = &self.cached_startup_apps {
|
if let Some(startup_apps) = &self.cached_startup_apps {
|
||||||
for app in &startup_apps.all_apps {
|
for app in &startup_apps.all_apps {
|
||||||
if let Some(name) = app.name(&startup_apps.locales) {
|
if let Some(name) = app.name(&startup_apps.locales)
|
||||||
if let Some(exec) = app.exec() {
|
&& let Some(exec) = app.exec()
|
||||||
if search_input.is_empty()
|
&& (search_input.is_empty()
|
||||||
|| exec.to_lowercase().contains(search_input)
|
|| exec.to_lowercase().contains(search_input)
|
||||||
|| name.to_lowercase().contains(search_input)
|
|| name.to_lowercase().contains(search_input))
|
||||||
{
|
{
|
||||||
let mut row = widget::row::with_capacity(3)
|
let mut row = widget::row::with_capacity(3)
|
||||||
.spacing(space_xs)
|
.spacing(space_xs)
|
||||||
.align_y(Alignment::Center);
|
.align_y(Alignment::Center);
|
||||||
|
|
||||||
row = row.push(
|
row = row.push(
|
||||||
icon::from_name(app.icon().unwrap_or("application-default"))
|
icon::from_name(app.icon().unwrap_or("application-default")).size(32),
|
||||||
.size(32),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(name) = app.name(&startup_apps.locales) {
|
if let Some(name) = app.name(&startup_apps.locales) {
|
||||||
|
|
@ -350,22 +344,14 @@ impl Page {
|
||||||
} else {
|
} else {
|
||||||
row = row.push(text(&app.appid).width(Length::Fill));
|
row = row.push(text(&app.appid).width(Length::Fill));
|
||||||
}
|
}
|
||||||
row = row.push(
|
row = row.push(widget::button::text(fl!("add")).on_press(
|
||||||
widget::button::text(fl!("add")).on_press(
|
Message::AddStartupApplication(directory_type.clone(), app.clone()).into(),
|
||||||
Message::AddStartupApplication(
|
));
|
||||||
directory_type.clone(),
|
|
||||||
app.clone(),
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
list = list.add(row)
|
list = list.add(row)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
list.into()
|
list.into()
|
||||||
}
|
}
|
||||||
|
|
@ -467,17 +453,17 @@ fn get_all_apps(locales: Vec<String>) -> Vec<DesktopEntry> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip if we can't run this in COSMIC
|
// skip if we can't run this in COSMIC
|
||||||
if let Some(only_show_in) = entry.only_show_in() {
|
if let Some(only_show_in) = entry.only_show_in()
|
||||||
if !only_show_in.contains(&"COSMIC") {
|
&& !only_show_in.contains(&"COSMIC")
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(not_show_in) = entry.not_show_in() {
|
if let Some(not_show_in) = entry.not_show_in()
|
||||||
if not_show_in.contains(&"COSMIC") {
|
&& not_show_in.contains(&"COSMIC")
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
result.push(entry.clone());
|
result.push(entry.clone());
|
||||||
dedupe.insert(app_id.to_owned());
|
dedupe.insert(app_id.to_owned());
|
||||||
|
|
|
||||||
|
|
@ -98,12 +98,13 @@ impl Model {
|
||||||
|
|
||||||
self.update_status();
|
self.update_status();
|
||||||
|
|
||||||
if let Some((path, existing)) = self.get_selected_adapter_mut() {
|
if let Some((path, existing)) = self.get_selected_adapter_mut()
|
||||||
if existing.enabled == Active::Enabled && existing.scanning == Active::Disabled {
|
&& existing.enabled == Active::Enabled
|
||||||
|
&& existing.scanning == Active::Disabled
|
||||||
|
{
|
||||||
existing.scanning = Active::Enabling;
|
existing.scanning = Active::Enabling;
|
||||||
return Some(start_discovery(connection, path));
|
return Some(start_discovery(connection, path));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,11 +136,11 @@ impl Content {
|
||||||
Some(c) => self.font_config.search(input.to_string(), c),
|
Some(c) => self.font_config.search(input.to_string(), c),
|
||||||
},
|
},
|
||||||
FontMessage::Select(font) => {
|
FontMessage::Select(font) => {
|
||||||
if let Some(context_view) = context_view {
|
if let Some(context_view) = context_view
|
||||||
if let Some(task) = self.font_config.select(font.to_string(), context_view) {
|
&& let Some(task) = self.font_config.select(font.to_string(), context_view)
|
||||||
|
{
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -185,18 +185,19 @@ pub async fn fetch() -> Message {
|
||||||
if is_hidden.trim() == "true" {
|
if is_hidden.trim() == "true" {
|
||||||
continue 'icon_dir;
|
continue 'icon_dir;
|
||||||
}
|
}
|
||||||
} else if name.is_none() {
|
} else if name.is_none()
|
||||||
if let Some(value) = buffer.strip_prefix("Name=") {
|
&& let Some(value) = buffer.strip_prefix("Name=")
|
||||||
|
{
|
||||||
name = Some(value.trim().to_owned());
|
name = Some(value.trim().to_owned());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if valid_dirs.is_empty() {
|
if valid_dirs.is_empty()
|
||||||
if let Some(value) = buffer.strip_prefix("Inherits=") {
|
&& let Some(value) = buffer.strip_prefix("Inherits=")
|
||||||
|
{
|
||||||
valid_dirs.extend(value.trim().split(',').map(|fallback| {
|
valid_dirs.extend(value.trim().split(',').map(|fallback| {
|
||||||
if let Some(path) = theme_paths.get(fallback) {
|
if let Some(path) = theme_paths.get(fallback) {
|
||||||
path.iter()
|
path.iter()
|
||||||
.last()
|
.next_back()
|
||||||
.and_then(|os| os.to_str().map(ToOwned::to_owned))
|
.and_then(|os| os.to_str().map(ToOwned::to_owned))
|
||||||
.unwrap_or_else(|| fallback.to_owned())
|
.unwrap_or_else(|| fallback.to_owned())
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -204,7 +205,6 @@ pub async fn fetch() -> Message {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
}
|
}
|
||||||
|
|
@ -213,7 +213,7 @@ pub async fn fetch() -> Message {
|
||||||
// Name of the directory theme was found in (e.g. Pop for Pop)
|
// Name of the directory theme was found in (e.g. Pop for Pop)
|
||||||
valid_dirs.push(
|
valid_dirs.push(
|
||||||
path.iter()
|
path.iter()
|
||||||
.last()
|
.next_back()
|
||||||
.and_then(|os| os.to_str().map(ToOwned::to_owned))
|
.and_then(|os| os.to_str().map(ToOwned::to_owned))
|
||||||
.unwrap_or_else(|| name.clone()),
|
.unwrap_or_else(|| name.clone()),
|
||||||
);
|
);
|
||||||
|
|
@ -288,7 +288,7 @@ fn preview_handles(theme: String, inherits: Vec<String>) -> [icon::Handle; ICON_
|
||||||
fn icon_handle(icon_name: &str, alternate: &str, valid_dirs: &[String]) -> icon::Handle {
|
fn icon_handle(icon_name: &str, alternate: &str, valid_dirs: &[String]) -> icon::Handle {
|
||||||
ICON_TRY_SIZES
|
ICON_TRY_SIZES
|
||||||
.iter()
|
.iter()
|
||||||
.zip(std::iter::repeat(icon_name).take(ICON_TRY_SIZES.len()))
|
.zip(std::iter::repeat_n(icon_name, ICON_TRY_SIZES.len()))
|
||||||
// Try fallback icon name after the default
|
// Try fallback icon name after the default
|
||||||
.chain(
|
.chain(
|
||||||
ICON_TRY_SIZES
|
ICON_TRY_SIZES
|
||||||
|
|
@ -316,8 +316,10 @@ fn icon_handle(icon_name: &str, alternate: &str, valid_dirs: &[String]) -> icon:
|
||||||
theme_dir = parent;
|
theme_dir = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(dir_name) =
|
if let Some(dir_name) = theme_dir
|
||||||
theme_dir.iter().last().and_then(std::ffi::OsStr::to_str)
|
.iter()
|
||||||
|
.next_back()
|
||||||
|
.and_then(std::ffi::OsStr::to_str)
|
||||||
{
|
{
|
||||||
valid_dirs
|
valid_dirs
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
||||||
|
|
@ -247,14 +247,14 @@ impl Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
Message::DrawerColor(u) => {
|
Message::DrawerColor(u) => {
|
||||||
if let Some(context_view) = self.context_view.as_ref() {
|
if let Some(context_view) = self.context_view.as_ref()
|
||||||
if self.drawer.update_color(&mut tasks, u, context_view) {
|
&& self.drawer.update_color(&mut tasks, u, context_view)
|
||||||
|
{
|
||||||
theme_staged = self
|
theme_staged = self
|
||||||
.theme_manager
|
.theme_manager
|
||||||
.set_color(self.drawer.current_color(context_view), context_view);
|
.set_color(self.drawer.current_color(context_view), context_view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Message::DrawerIcon(message) => {
|
Message::DrawerIcon(message) => {
|
||||||
if let Some(context_view) = self.context_view.as_ref() {
|
if let Some(context_view) = self.context_view.as_ref() {
|
||||||
|
|
@ -462,11 +462,11 @@ impl Page {
|
||||||
Message::ImportSuccess(builder) => {
|
Message::ImportSuccess(builder) => {
|
||||||
tracing::trace!("Import successful");
|
tracing::trace!("Import successful");
|
||||||
let new_is_dark = builder.palette.is_dark();
|
let new_is_dark = builder.palette.is_dark();
|
||||||
if new_is_dark != self.theme_manager.mode().is_dark {
|
if new_is_dark != self.theme_manager.mode().is_dark
|
||||||
if let Err(err) = self.theme_manager.dark_mode(new_is_dark) {
|
&& let Err(err) = self.theme_manager.dark_mode(new_is_dark)
|
||||||
|
{
|
||||||
tracing::error!(?err, "Error setting dark mode");
|
tracing::error!(?err, "Error setting dark mode");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
self.theme_manager
|
self.theme_manager
|
||||||
.selected_customizer_mut()
|
.selected_customizer_mut()
|
||||||
|
|
@ -552,8 +552,9 @@ impl Page {
|
||||||
(panel_config.name == "Dock").then_some(panel_config)
|
(panel_config.name == "Dock").then_some(panel_config)
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(panel_config_helper) = panel_config_helper.as_ref() {
|
if let Some(panel_config_helper) = panel_config_helper.as_ref()
|
||||||
if let Some(panel_config) = panel_config.as_mut() {
|
&& let Some(panel_config) = panel_config.as_mut()
|
||||||
|
{
|
||||||
let radii = if panel_config.anchor_gap || !panel_config.expand_to_edges {
|
let radii = if panel_config.anchor_gap || !panel_config.expand_to_edges {
|
||||||
let cornder_radii: CornerRadii = roundness.into();
|
let cornder_radii: CornerRadii = roundness.into();
|
||||||
cornder_radii.radius_xl[0] as u32
|
cornder_radii.radius_xl[0] as u32
|
||||||
|
|
@ -564,11 +565,11 @@ impl Page {
|
||||||
if let Err(why) = panel_config.set_border_radius(panel_config_helper, radii) {
|
if let Err(why) = panel_config.set_border_radius(panel_config_helper, radii) {
|
||||||
tracing::error!(?why, "Error updating panel corner radii");
|
tracing::error!(?why, "Error updating panel corner radii");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(dock_config_helper) = dock_config_helper.as_ref() {
|
if let Some(dock_config_helper) = dock_config_helper.as_ref()
|
||||||
if let Some(dock_config) = dock_config.as_mut() {
|
&& let Some(dock_config) = dock_config.as_mut()
|
||||||
|
{
|
||||||
let radii = if dock_config.anchor_gap || !dock_config.expand_to_edges {
|
let radii = if dock_config.anchor_gap || !dock_config.expand_to_edges {
|
||||||
let cornder_radii: CornerRadii = roundness.into();
|
let cornder_radii: CornerRadii = roundness.into();
|
||||||
cornder_radii.radius_xl[0] as u32
|
cornder_radii.radius_xl[0] as u32
|
||||||
|
|
@ -579,7 +580,6 @@ impl Page {
|
||||||
if let Err(why) = dock_config.set_border_radius(dock_config_helper, radii) {
|
if let Err(why) = dock_config.set_border_radius(dock_config_helper, radii) {
|
||||||
tracing::error!(?why, "Error updating dock corner radii");
|
tracing::error!(?why, "Error updating dock corner radii");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -596,8 +596,9 @@ impl Page {
|
||||||
(panel_config.name == "Dock").then_some(panel_config)
|
(panel_config.name == "Dock").then_some(panel_config)
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(panel_config_helper) = panel_config_helper.as_ref() {
|
if let Some(panel_config_helper) = panel_config_helper.as_ref()
|
||||||
if let Some(panel_config) = panel_config.as_mut() {
|
&& let Some(panel_config) = panel_config.as_mut()
|
||||||
|
{
|
||||||
let spacing = match density {
|
let spacing = match density {
|
||||||
Density::Compact => 0,
|
Density::Compact => 0,
|
||||||
_ => 4,
|
_ => 4,
|
||||||
|
|
@ -606,11 +607,11 @@ impl Page {
|
||||||
if let Err(err) = update {
|
if let Err(err) = update {
|
||||||
tracing::error!(?err, "Error updating panel spacing");
|
tracing::error!(?err, "Error updating panel spacing");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(dock_config_helper) = dock_config_helper.as_ref() {
|
if let Some(dock_config_helper) = dock_config_helper.as_ref()
|
||||||
if let Some(dock_config) = dock_config.as_mut() {
|
&& let Some(dock_config) = dock_config.as_mut()
|
||||||
|
{
|
||||||
let spacing = match density {
|
let spacing = match density {
|
||||||
Density::Compact => 0,
|
Density::Compact => 0,
|
||||||
_ => 4,
|
_ => 4,
|
||||||
|
|
@ -619,7 +620,6 @@ impl Page {
|
||||||
if let Err(err) = update {
|
if let Err(err) = update {
|
||||||
tracing::error!(?err, "Error updating dock spacing");
|
tracing::error!(?err, "Error updating dock spacing");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -244,14 +244,14 @@ impl Page {
|
||||||
.filter(|a| a.matches(&self.search))
|
.filter(|a| a.matches(&self.search))
|
||||||
{
|
{
|
||||||
if let Some(config) = self.current_config.as_ref() {
|
if let Some(config) = self.current_config.as_ref() {
|
||||||
if let Some(center) = config.plugins_center.as_ref() {
|
if let Some(center) = config.plugins_center.as_ref()
|
||||||
if center.iter().any(|a| a.as_str() == info.id.as_ref()) {
|
&& center.iter().any(|a| a.as_str() == info.id.as_ref())
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(wings) = config.plugins_wings.as_ref() {
|
if let Some(wings) = config.plugins_wings.as_ref()
|
||||||
if wings
|
&& wings
|
||||||
.0
|
.0
|
||||||
.iter()
|
.iter()
|
||||||
.chain(wings.1.iter())
|
.chain(wings.1.iter())
|
||||||
|
|
@ -260,7 +260,6 @@ impl Page {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
has_some = true;
|
has_some = true;
|
||||||
list_column = list_column.add(
|
list_column = list_column.add(
|
||||||
row::with_children(vec![
|
row::with_children(vec![
|
||||||
|
|
|
||||||
|
|
@ -468,12 +468,12 @@ impl PageInner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::FullReset => {
|
Message::FullReset => {
|
||||||
if let Some(container) = self.system_container.as_ref() {
|
if let Some(container) = self.system_container.as_ref()
|
||||||
if let Err(err) = container.write_entries() {
|
&& let Err(err) = container.write_entries()
|
||||||
|
{
|
||||||
tracing::error!(?err, "Error fully resetting the panel config.");
|
tracing::error!(?err, "Error fully resetting the panel config.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -571,12 +571,12 @@ impl PageInner {
|
||||||
return Task::none();
|
return Task::none();
|
||||||
}
|
}
|
||||||
Message::OutputRemoved(output) => {
|
Message::OutputRemoved(output) => {
|
||||||
if let Some((name, _)) = self.outputs_map.remove(&output.id()) {
|
if let Some((name, _)) = self.outputs_map.remove(&output.id())
|
||||||
if let Some(pos) = self.outputs.iter().position(|o| o == &name) {
|
&& let Some(pos) = self.outputs.iter().position(|o| o == &name)
|
||||||
|
{
|
||||||
self.outputs.remove(pos);
|
self.outputs.remove(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Message::PanelConfig(c) => {
|
Message::PanelConfig(c) => {
|
||||||
self.panel_config = Some(c);
|
self.panel_config = Some(c);
|
||||||
return Task::none();
|
return Task::none();
|
||||||
|
|
|
||||||
|
|
@ -109,8 +109,9 @@ impl Config {
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn default_folder() -> PathBuf {
|
pub fn default_folder() -> PathBuf {
|
||||||
if let Some(data_dirs) = env::var_os("XDG_DATA_DIRS") {
|
if let Some(data_dirs) = env::var_os("XDG_DATA_DIRS")
|
||||||
if let Some(data_dirs) = data_dirs.to_str() {
|
&& let Some(data_dirs) = data_dirs.to_str()
|
||||||
|
{
|
||||||
let data_dirs = data_dirs.split(":");
|
let data_dirs = data_dirs.split(":");
|
||||||
|
|
||||||
for data_dir in data_dirs {
|
for data_dir in data_dirs {
|
||||||
|
|
@ -120,7 +121,6 @@ impl Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
PathBuf::from("/usr/share").join(BACKGROUNDS_DIR)
|
PathBuf::from("/usr/share").join(BACKGROUNDS_DIR)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -587,12 +587,12 @@ impl Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
Category::RecentFolder(id) => {
|
Category::RecentFolder(id) => {
|
||||||
if let Some(path) = self.config.recent_folders().get(id).cloned() {
|
if let Some(path) = self.config.recent_folders().get(id).cloned()
|
||||||
if let Err(why) = self.config.set_current_folder(Some(path.clone())) {
|
&& let Err(why) = self.config.set_current_folder(Some(path.clone()))
|
||||||
|
{
|
||||||
tracing::error!(?path, ?why, "failed to set current folder");
|
tracing::error!(?path, ?why, "failed to set current folder");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Category::AddFolder => {
|
Category::AddFolder => {
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(feature = "xdg-portal")]
|
||||||
|
|
@ -815,12 +815,12 @@ impl Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
Message::ImageRemove(image) => {
|
Message::ImageRemove(image) => {
|
||||||
if let Some(path) = self.selection.remove_custom_image(image) {
|
if let Some(path) = self.selection.remove_custom_image(image)
|
||||||
if let Err(why) = self.config.remove_custom_image(&path) {
|
&& let Err(why) = self.config.remove_custom_image(&path)
|
||||||
|
{
|
||||||
tracing::error!(?why, "could not remove custom image from config");
|
tracing::error!(?why, "could not remove custom image from config");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Message::ChangeCategory(category) => {
|
Message::ChangeCategory(category) => {
|
||||||
return self.change_category(category);
|
return self.change_category(category);
|
||||||
|
|
@ -858,19 +858,15 @@ impl Page {
|
||||||
self.selection.active = Choice::Slideshow;
|
self.selection.active = Choice::Slideshow;
|
||||||
self.cache_display_image();
|
self.cache_display_image();
|
||||||
} else {
|
} else {
|
||||||
if let Some(output) = self.config_output() {
|
if let Some(output) = self.config_output()
|
||||||
if let Some(Source::Path(path)) = self.config.current_image(output) {
|
&& let Some(Source::Path(path)) = self.config.current_image(output)
|
||||||
if let Some(entity) = self.wallpaper_id_from_path(&path) {
|
&& let Some(entity) = self.wallpaper_id_from_path(&path)
|
||||||
if let Some(entry) =
|
&& let Some(entry) = self.config_wallpaper_entry(output.to_owned(), path)
|
||||||
self.config_wallpaper_entry(output.to_owned(), path)
|
|
||||||
{
|
{
|
||||||
self.select_wallpaper(&entry, entity, false);
|
self.select_wallpaper(&entry, entity, false);
|
||||||
self.config_apply();
|
self.config_apply();
|
||||||
return Task::none();
|
return Task::none();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.select_first_wallpaper();
|
self.select_first_wallpaper();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -337,11 +337,9 @@ pub fn focus_navigation() -> Section<crate::pages::Message> {
|
||||||
|
|
||||||
fn super_key_active_config() -> Option<usize> {
|
fn super_key_active_config() -> Option<usize> {
|
||||||
let super_binding = Binding::new(shortcuts::Modifiers::new().logo(), None);
|
let super_binding = Binding::new(shortcuts::Modifiers::new().logo(), None);
|
||||||
|
|
||||||
let config = shortcuts::context().ok()?;
|
let config = shortcuts::context().ok()?;
|
||||||
let shortcuts = shortcuts::shortcuts(&config);
|
|
||||||
|
|
||||||
let new_id = shortcuts
|
shortcuts::shortcuts(&config)
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(binding, _action)| binding == &&super_binding)
|
.find(|(binding, _action)| binding == &&super_binding)
|
||||||
.and_then(|(_, action)| match action {
|
.and_then(|(_, action)| match action {
|
||||||
|
|
@ -349,9 +347,7 @@ fn super_key_active_config() -> Option<usize> {
|
||||||
Action::System(shortcuts::action::System::WorkspaceOverview) => Some(1),
|
Action::System(shortcuts::action::System::WorkspaceOverview) => Some(1),
|
||||||
Action::System(shortcuts::action::System::AppLibrary) => Some(2),
|
Action::System(shortcuts::action::System::AppLibrary) => Some(2),
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
})
|
||||||
|
|
||||||
new_id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn super_key_set(action: Option<shortcuts::action::System>) {
|
fn super_key_set(action: Option<shortcuts::action::System>) {
|
||||||
|
|
|
||||||
|
|
@ -226,21 +226,21 @@ impl<Message: Clone> Widget<Message, cosmic::Theme, Renderer> for Arrangement<'_
|
||||||
| core::Event::Touch(touch::Event::FingerLifted { .. }) => {
|
| core::Event::Touch(touch::Event::FingerLifted { .. }) => {
|
||||||
let state = tree.state.downcast_mut::<State>();
|
let state = tree.state.downcast_mut::<State>();
|
||||||
if let Some((output_key, region)) = state.dragging.take() {
|
if let Some((output_key, region)) = state.dragging.take() {
|
||||||
if let Some(position) = cursor.position() {
|
if let Some(position) = cursor.position()
|
||||||
if position.distance(state.drag_from) < 4.0 {
|
&& position.distance(state.drag_from) < 4.0
|
||||||
|
{
|
||||||
if let Some(ref on_select) = self.on_select {
|
if let Some(ref on_select) = self.on_select {
|
||||||
for id in self.tab_model.iter() {
|
for id in self.tab_model.iter() {
|
||||||
if let Some(&key) = self.tab_model.data::<OutputKey>(id) {
|
if let Some(&key) = self.tab_model.data::<OutputKey>(id)
|
||||||
if key == output_key {
|
&& key == output_key
|
||||||
|
{
|
||||||
shell.publish(on_select(id));
|
shell.publish(on_select(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return event::Status::Captured;
|
return event::Status::Captured;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(ref on_placement) = self.on_placement {
|
if let Some(ref on_placement) = self.on_placement {
|
||||||
shell.publish(on_placement(
|
shell.publish(on_placement(
|
||||||
|
|
@ -309,11 +309,11 @@ impl<Message: Clone> Widget<Message, cosmic::Theme, Renderer> for Arrangement<'_
|
||||||
display_regions(self.tab_model, self.list, &bounds, state.max_dimensions).enumerate()
|
display_regions(self.tab_model, self.list, &bounds, state.max_dimensions).enumerate()
|
||||||
{
|
{
|
||||||
// If the output is being dragged, show its dragged position instead.
|
// If the output is being dragged, show its dragged position instead.
|
||||||
if let Some((dragged_key, dragged_region)) = state.dragging {
|
if let Some((dragged_key, dragged_region)) = state.dragging
|
||||||
if dragged_key == output_key {
|
&& dragged_key == output_key
|
||||||
|
{
|
||||||
region = dragged_region;
|
region = dragged_region;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let (background, border_color) = if Some(&output_key) == active_key {
|
let (background, border_color) = if Some(&output_key) == active_key {
|
||||||
let mut border_color = border_color;
|
let mut border_color = border_color;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ static DPI_SCALE_LABELS: LazyLock<Vec<String>> =
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct ColorDepth(usize);
|
pub struct ColorDepth(usize);
|
||||||
|
|
||||||
/// Identifies the content to display in the context drawer
|
// /// Identifies the content to display in the context drawer
|
||||||
// pub enum ContextDrawer {
|
// pub enum ContextDrawer {
|
||||||
// NightLight,
|
// NightLight,
|
||||||
// }
|
// }
|
||||||
|
|
@ -287,12 +287,12 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
let (randr_task, randr_handle) =
|
let (randr_task, randr_handle) =
|
||||||
Task::stream(async_fn_stream::fn_stream(|emitter| async move {
|
Task::stream(async_fn_stream::fn_stream(|emitter| async move {
|
||||||
while let Ok(message) = rx.recv().await {
|
while let Ok(message) = rx.recv().await {
|
||||||
if let cosmic_randr::Message::ManagerDone = message {
|
if let cosmic_randr::Message::ManagerDone = message
|
||||||
if !refreshing_page.swap(true, Ordering::SeqCst) {
|
&& !refreshing_page.swap(true, Ordering::SeqCst)
|
||||||
|
{
|
||||||
_ = emitter.emit(on_enter().await).await;
|
_ = emitter.emit(on_enter().await).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}))
|
}))
|
||||||
.abortable();
|
.abortable();
|
||||||
|
|
||||||
|
|
@ -931,15 +931,14 @@ impl Page {
|
||||||
return Task::none();
|
return Task::none();
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ref resolution) = self.config.resolution {
|
if let Some(ref resolution) = self.config.resolution
|
||||||
if let Some(rates) = self.cache.modes.get(resolution) {
|
&& let Some(rates) = self.cache.modes.get(resolution)
|
||||||
if let Some(&rate) = rates.get(option) {
|
&& let Some(&rate) = rates.get(option)
|
||||||
|
{
|
||||||
self.cache.refresh_rate_selected = Some(option);
|
self.cache.refresh_rate_selected = Some(option);
|
||||||
self.config.refresh_rate = Some(rate);
|
self.config.refresh_rate = Some(rate);
|
||||||
return self.exec_randr(output, Randr::RefreshRate(rate));
|
return self.exec_randr(output, Randr::RefreshRate(rate));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
@ -1329,7 +1328,7 @@ pub fn display_configuration() -> Section<crate::pages::Message> {
|
||||||
.button_alignment(Alignment::Center)
|
.button_alignment(Alignment::Center)
|
||||||
.on_activate(Message::Display);
|
.on_activate(Message::Display);
|
||||||
|
|
||||||
let mut display_enable = (page
|
let mut display_enable = if page
|
||||||
// Don't allow disabling display if it's the only active
|
// Don't allow disabling display if it's the only active
|
||||||
.list
|
.list
|
||||||
.outputs
|
.outputs
|
||||||
|
|
@ -1337,8 +1336,8 @@ pub fn display_configuration() -> Section<crate::pages::Message> {
|
||||||
.filter(|display| display.enabled)
|
.filter(|display| display.enabled)
|
||||||
.count()
|
.count()
|
||||||
> 1
|
> 1
|
||||||
|| !active_output.enabled)
|
|| !active_output.enabled
|
||||||
.then(|| {
|
{
|
||||||
list_column()
|
list_column()
|
||||||
.add(widget::settings::item(
|
.add(widget::settings::item(
|
||||||
&descriptions[enable_label],
|
&descriptions[enable_label],
|
||||||
|
|
@ -1351,8 +1350,9 @@ pub fn display_configuration() -> Section<crate::pages::Message> {
|
||||||
Message::Mirroring,
|
Message::Mirroring,
|
||||||
),
|
),
|
||||||
))
|
))
|
||||||
})
|
} else {
|
||||||
.unwrap_or_else(list_column);
|
list_column()
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(items) = display_options {
|
if let Some(items) = display_options {
|
||||||
for item in items {
|
for item in items {
|
||||||
|
|
|
||||||
|
|
@ -455,24 +455,22 @@ impl Page {
|
||||||
SourceContext::MoveDown(id) => {
|
SourceContext::MoveDown(id) => {
|
||||||
if let Some(pos) =
|
if let Some(pos) =
|
||||||
self.active_layouts.iter().position(|&active| active == id)
|
self.active_layouts.iter().position(|&active| active == id)
|
||||||
|
&& pos + 1 < self.active_layouts.len()
|
||||||
{
|
{
|
||||||
if pos + 1 < self.active_layouts.len() {
|
|
||||||
self.active_layouts.swap(pos, pos + 1);
|
self.active_layouts.swap(pos, pos + 1);
|
||||||
self.update_xkb_config();
|
self.update_xkb_config();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
SourceContext::MoveUp(id) => {
|
SourceContext::MoveUp(id) => {
|
||||||
if let Some(pos) =
|
if let Some(pos) =
|
||||||
self.active_layouts.iter().position(|&active| active == id)
|
self.active_layouts.iter().position(|&active| active == id)
|
||||||
|
&& pos > 0
|
||||||
{
|
{
|
||||||
if pos > 0 {
|
|
||||||
self.active_layouts.swap(pos, pos - 1);
|
self.active_layouts.swap(pos, pos - 1);
|
||||||
self.update_xkb_config();
|
self.update_xkb_config();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
SourceContext::Remove(id) => {
|
SourceContext::Remove(id) => {
|
||||||
if let Some(pos) =
|
if let Some(pos) =
|
||||||
|
|
|
||||||
|
|
@ -197,15 +197,16 @@ impl Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn dialog(&self) -> Option<Element<'_, ShortcutMessage>> {
|
pub(super) fn dialog(&self) -> Option<Element<'_, ShortcutMessage>> {
|
||||||
if let Some(&(id, _, _, ref action)) = self.replace_dialog.as_ref() {
|
if let Some(&(id, _, _, ref action)) = self.replace_dialog.as_ref()
|
||||||
if let Some(short_id) = self.shortcut_context {
|
&& let Some(short_id) = self.shortcut_context
|
||||||
if let Some(model) = self.shortcut_models.get(short_id) {
|
&& let Some(model) = self.shortcut_models.get(short_id)
|
||||||
if let Some(shortcut) = model.bindings.get(id) {
|
&& let Some(shortcut) = model.bindings.get(id)
|
||||||
let primary_action = button::suggested(fl!("replace"))
|
{
|
||||||
.on_press(ShortcutMessage::ApplyReplace);
|
let primary_action =
|
||||||
|
button::suggested(fl!("replace")).on_press(ShortcutMessage::ApplyReplace);
|
||||||
|
|
||||||
let secondary_action = button::standard(fl!("cancel"))
|
let secondary_action =
|
||||||
.on_press(ShortcutMessage::CancelReplace);
|
button::standard(fl!("cancel")).on_press(ShortcutMessage::CancelReplace);
|
||||||
|
|
||||||
let dialog = widget::dialog()
|
let dialog = widget::dialog()
|
||||||
.title(fl!("replace-shortcut-dialog"))
|
.title(fl!("replace-shortcut-dialog"))
|
||||||
|
|
@ -226,9 +227,6 @@ impl Model {
|
||||||
|
|
||||||
return Some(dialog.into());
|
return Some(dialog.into());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
@ -257,9 +255,9 @@ impl Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn on_context_drawer_close(&mut self) {
|
pub(super) fn on_context_drawer_close(&mut self) {
|
||||||
if let Some(short_id) = self.shortcut_context.take() {
|
if let Some(short_id) = self.shortcut_context.take()
|
||||||
if let Some(model) = self.shortcut_models.get_mut(short_id) {
|
&& let Some(model) = self.shortcut_models.get_mut(short_id)
|
||||||
if let Some(remove_id) = model
|
&& let Some(remove_id) = model
|
||||||
.bindings
|
.bindings
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(_, binding)| !binding.is_saved)
|
.find(|(_, binding)| !binding.is_saved)
|
||||||
|
|
@ -267,8 +265,6 @@ impl Model {
|
||||||
{
|
{
|
||||||
model.bindings.remove(remove_id);
|
model.bindings.remove(remove_id);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.editing = None;
|
self.editing = None;
|
||||||
}
|
}
|
||||||
|
|
@ -314,13 +310,12 @@ impl Model {
|
||||||
pub(super) fn update(&mut self, message: ShortcutMessage) -> Task<crate::app::Message> {
|
pub(super) fn update(&mut self, message: ShortcutMessage) -> Task<crate::app::Message> {
|
||||||
match message {
|
match message {
|
||||||
ShortcutMessage::AddAnotherKeybinding => {
|
ShortcutMessage::AddAnotherKeybinding => {
|
||||||
if let Some(short_id) = self.shortcut_context {
|
if let Some(short_id) = self.shortcut_context
|
||||||
if let Some(model) = self.shortcut_models.get_mut(short_id) {
|
&& let Some(model) = self.shortcut_models.get_mut(short_id)
|
||||||
|
{
|
||||||
// If an empty entry exists, focus it instead of creating a new input.
|
// If an empty entry exists, focus it instead of creating a new input.
|
||||||
for (binding_id, shortcut) in &mut model.bindings {
|
for (binding_id, shortcut) in &mut model.bindings {
|
||||||
if shortcut.binding.is_set()
|
if shortcut.binding.is_set() || Binding::from_str(&shortcut.input).is_ok() {
|
||||||
|| Binding::from_str(&shortcut.input).is_ok()
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -352,10 +347,10 @@ impl Model {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
ShortcutMessage::ApplyReplace => {
|
ShortcutMessage::ApplyReplace => {
|
||||||
if let Some((id, new_binding, ..)) = self.replace_dialog.take() {
|
if let Some((id, new_binding, ..)) = self.replace_dialog.take()
|
||||||
if let Some(short_id) = self.shortcut_context {
|
&& let Some(short_id) = self.shortcut_context
|
||||||
|
{
|
||||||
// Remove conflicting bindings that are saved on disk.
|
// Remove conflicting bindings that are saved on disk.
|
||||||
self.config_remove(&new_binding);
|
self.config_remove(&new_binding);
|
||||||
|
|
||||||
|
|
@ -373,8 +368,9 @@ impl Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the current model and save the binding to disk.
|
// Update the current model and save the binding to disk.
|
||||||
if let Some(model) = self.shortcut_models.get_mut(short_id) {
|
if let Some(model) = self.shortcut_models.get_mut(short_id)
|
||||||
if let Some(shortcut) = model.bindings.get_mut(id) {
|
&& let Some(shortcut) = model.bindings.get_mut(id)
|
||||||
|
{
|
||||||
let prev_binding = shortcut.binding.clone();
|
let prev_binding = shortcut.binding.clone();
|
||||||
|
|
||||||
shortcut.binding = new_binding.clone();
|
shortcut.binding = new_binding.clone();
|
||||||
|
|
@ -388,27 +384,24 @@ impl Model {
|
||||||
self.config_remove(&prev_binding);
|
self.config_remove(&prev_binding);
|
||||||
self.config_add(action, new_binding);
|
self.config_add(action, new_binding);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_ = self.on_enter();
|
_ = self.on_enter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
ShortcutMessage::CancelReplace => {
|
ShortcutMessage::CancelReplace => {
|
||||||
if let Some(((id, _, _, _), short_id)) =
|
if let Some(((id, _, _, _), short_id)) =
|
||||||
self.replace_dialog.take().zip(self.shortcut_context)
|
self.replace_dialog.take().zip(self.shortcut_context)
|
||||||
|
&& let Some(model) = self.shortcut_models.get_mut(short_id)
|
||||||
|
&& let Some(binding) = model.bindings.get_mut(id)
|
||||||
{
|
{
|
||||||
if let Some(model) = self.shortcut_models.get_mut(short_id) {
|
|
||||||
if let Some(binding) = model.bindings.get_mut(id) {
|
|
||||||
binding.reset();
|
binding.reset();
|
||||||
return cosmic::widget::text_input::focus(binding.id.clone());
|
return cosmic::widget::text_input::focus(binding.id.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
ShortcutMessage::DeleteBinding(id) => {
|
ShortcutMessage::DeleteBinding(id) => {
|
||||||
if let Some(short_id) = self.shortcut_context {
|
if let Some(short_id) = self.shortcut_context
|
||||||
if let Some(model) = self.shortcut_models.get_mut(short_id) {
|
&& let Some(model) = self.shortcut_models.get_mut(short_id)
|
||||||
|
{
|
||||||
let shortcut = model.bindings.remove(id);
|
let shortcut = model.bindings.remove(id);
|
||||||
if shortcut.is_default {
|
if shortcut.is_default {
|
||||||
self.config_add(Action::Disable, shortcut.binding.clone());
|
self.config_add(Action::Disable, shortcut.binding.clone());
|
||||||
|
|
@ -417,7 +410,6 @@ impl Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
ShortcutMessage::DeleteShortcut(id) => {
|
ShortcutMessage::DeleteShortcut(id) => {
|
||||||
let model = self.shortcut_models.remove(id);
|
let model = self.shortcut_models.remove(id);
|
||||||
for (_, shortcut) in model.bindings {
|
for (_, shortcut) in model.bindings {
|
||||||
|
|
@ -427,22 +419,22 @@ impl Model {
|
||||||
ShortcutMessage::EditBinding(id, enable) => {
|
ShortcutMessage::EditBinding(id, enable) => {
|
||||||
if !enable && self.editing == Some(id) {
|
if !enable && self.editing == Some(id) {
|
||||||
self.editing = None;
|
self.editing = None;
|
||||||
if let Some(short_id) = self.shortcut_context {
|
if let Some(short_id) = self.shortcut_context
|
||||||
if let Some(model) = self.shortcut_models.get_mut(short_id) {
|
&& let Some(model) = self.shortcut_models.get_mut(short_id)
|
||||||
if let Some(shortcut) = model.bindings.get_mut(id) {
|
&& let Some(shortcut) = model.bindings.get_mut(id)
|
||||||
|
{
|
||||||
shortcut.pending = shortcut.binding.clone();
|
shortcut.pending = shortcut.binding.clone();
|
||||||
shortcut.input = shortcut.binding.to_string();
|
shortcut.input = shortcut.binding.to_string();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return Task::batch(vec![
|
return Task::batch(vec![
|
||||||
cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone()),
|
cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone()),
|
||||||
iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard()
|
iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
if let Some(short_id) = self.shortcut_context {
|
if let Some(short_id) = self.shortcut_context
|
||||||
if let Some(model) = self.shortcut_models.get_mut(short_id) {
|
&& let Some(model) = self.shortcut_models.get_mut(short_id)
|
||||||
if let Some(shortcut) = model.bindings.get_mut(id) {
|
&& let Some(shortcut) = model.bindings.get_mut(id)
|
||||||
|
{
|
||||||
if enable {
|
if enable {
|
||||||
self.editing = Some(id);
|
self.editing = Some(id);
|
||||||
shortcut.input = shortcut.binding.to_string();
|
shortcut.input = shortcut.binding.to_string();
|
||||||
|
|
@ -456,8 +448,6 @@ impl Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
ShortcutMessage::InputBinding(bind_id, ..) => {
|
ShortcutMessage::InputBinding(bind_id, ..) => {
|
||||||
if self.editing.is_none() {
|
if self.editing.is_none() {
|
||||||
return self.update(ShortcutMessage::EditBinding(bind_id, true));
|
return self.update(ShortcutMessage::EditBinding(bind_id, true));
|
||||||
|
|
@ -491,13 +481,13 @@ impl Model {
|
||||||
crate::app::Message::OpenContextDrawer(self.entity),
|
crate::app::Message::OpenContextDrawer(self.entity),
|
||||||
)];
|
)];
|
||||||
|
|
||||||
if let Some(model) = self.shortcut_models.get(0) {
|
if let Some(model) = self.shortcut_models.get(0)
|
||||||
if let Some(shortcut) = model.bindings.get(0) {
|
&& let Some(shortcut) = model.bindings.get(0)
|
||||||
|
{
|
||||||
self.editing = Some(0);
|
self.editing = Some(0);
|
||||||
tasks.push(widget::text_input::focus(shortcut.id.clone()));
|
tasks.push(widget::text_input::focus(shortcut.id.clone()));
|
||||||
tasks.push(widget::text_input::select_all(shortcut.id.clone()));
|
tasks.push(widget::text_input::select_all(shortcut.id.clone()));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return Task::batch(tasks);
|
return Task::batch(tasks);
|
||||||
}
|
}
|
||||||
|
|
@ -509,11 +499,11 @@ impl Model {
|
||||||
panic!("{}", v);
|
panic!("{}", v);
|
||||||
}
|
}
|
||||||
ShortcutMessage::ModifiersChanged(modifiers) => {
|
ShortcutMessage::ModifiersChanged(modifiers) => {
|
||||||
if let Some((short_id, id)) = self.shortcut_context.zip(self.editing) {
|
if let Some((short_id, id)) = self.shortcut_context.zip(self.editing)
|
||||||
if let Some(model) = self.shortcut_models.get_mut(short_id) {
|
&& let Some(model) = self.shortcut_models.get_mut(short_id)
|
||||||
if let Some(shortcut) = model.bindings.get_mut(id) {
|
&& let Some(shortcut) = model.bindings.get_mut(id)
|
||||||
let mut cfg_modifiers =
|
{
|
||||||
cosmic_settings_config::shortcuts::Modifiers::new();
|
let mut cfg_modifiers = cosmic_settings_config::shortcuts::Modifiers::new();
|
||||||
if modifiers.alt() {
|
if modifiers.alt() {
|
||||||
cfg_modifiers = cfg_modifiers.alt()
|
cfg_modifiers = cfg_modifiers.alt()
|
||||||
}
|
}
|
||||||
|
|
@ -526,8 +516,7 @@ impl Model {
|
||||||
if modifiers.logo() {
|
if modifiers.logo() {
|
||||||
cfg_modifiers = cfg_modifiers.logo()
|
cfg_modifiers = cfg_modifiers.logo()
|
||||||
}
|
}
|
||||||
let old =
|
let old = std::mem::replace(&mut shortcut.pending.modifiers, cfg_modifiers);
|
||||||
std::mem::replace(&mut shortcut.pending.modifiers, cfg_modifiers);
|
|
||||||
|
|
||||||
if shortcut.pending.keycode.is_none() && modifiers.is_empty() {
|
if shortcut.pending.keycode.is_none() && modifiers.is_empty() {
|
||||||
if old.logo {
|
if old.logo {
|
||||||
|
|
@ -552,12 +541,11 @@ impl Model {
|
||||||
shortcut.input = shortcut.pending.to_string();
|
shortcut.input = shortcut.pending.to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
ShortcutMessage::KeyReleased(keycode, _, _) => {
|
ShortcutMessage::KeyReleased(keycode, _, _) => {
|
||||||
if let Some((short_id, id)) = self.shortcut_context.zip(self.editing) {
|
if let Some((short_id, id)) = self.shortcut_context.zip(self.editing)
|
||||||
if let Some(model) = self.shortcut_models.get_mut(short_id) {
|
&& let Some(model) = self.shortcut_models.get_mut(short_id)
|
||||||
if let Some(shortcut) = model.bindings.get_mut(id) {
|
&& let Some(shortcut) = model.bindings.get_mut(id)
|
||||||
|
{
|
||||||
// if the currently selected shortcut matches, finish selecting shortcut
|
// if the currently selected shortcut matches, finish selecting shortcut
|
||||||
if shortcut.pending.key.is_some()
|
if shortcut.pending.key.is_some()
|
||||||
&& shortcut.pending.keycode.is_some_and(|k| k == keycode)
|
&& shortcut.pending.keycode.is_some_and(|k| k == keycode)
|
||||||
|
|
@ -586,13 +574,12 @@ impl Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
ShortcutMessage::KeyPressed(keycode, unmodified_keysym, location, modifiers) => {
|
ShortcutMessage::KeyPressed(keycode, unmodified_keysym, location, modifiers) => {
|
||||||
if unmodified_keysym == Key::Named(Named::Escape) && modifiers.is_empty() {
|
if unmodified_keysym == Key::Named(Named::Escape) && modifiers.is_empty() {
|
||||||
if let Some((short_id, id)) = self.shortcut_context.zip(self.editing) {
|
if let Some((short_id, id)) = self.shortcut_context.zip(self.editing)
|
||||||
if let Some(model) = self.shortcut_models.get_mut(short_id) {
|
&& let Some(model) = self.shortcut_models.get_mut(short_id)
|
||||||
if let Some(binding) = model.bindings.get_mut(id) {
|
&& let Some(binding) = model.bindings.get_mut(id)
|
||||||
|
{
|
||||||
binding.reset();
|
binding.reset();
|
||||||
self.editing = None;
|
self.editing = None;
|
||||||
return Task::batch(vec![
|
return Task::batch(vec![
|
||||||
|
|
@ -600,13 +587,12 @@ impl Model {
|
||||||
iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard()
|
iced_winit::platform_specific::commands::keyboard_shortcuts_inhibit::inhibit_shortcuts(false).discard()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return Task::none();
|
return Task::none();
|
||||||
}
|
}
|
||||||
if let Some((short_id, id)) = self.shortcut_context.zip(self.editing) {
|
if let Some((short_id, id)) = self.shortcut_context.zip(self.editing)
|
||||||
if let Some(model) = self.shortcut_models.get_mut(short_id) {
|
&& let Some(model) = self.shortcut_models.get_mut(short_id)
|
||||||
if let Some(shortcut) = model.bindings.get_mut(id) {
|
&& let Some(shortcut) = model.bindings.get_mut(id)
|
||||||
|
{
|
||||||
shortcut.pending.keycode = Some(keycode);
|
shortcut.pending.keycode = Some(keycode);
|
||||||
shortcut.pending.key =
|
shortcut.pending.key =
|
||||||
iced_winit::platform_specific::wayland::keymap::key_to_keysym(
|
iced_winit::platform_specific::wayland::keymap::key_to_keysym(
|
||||||
|
|
@ -616,8 +602,6 @@ impl Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
@ -689,8 +673,9 @@ impl Model {
|
||||||
let mut apply_binding = None;
|
let mut apply_binding = None;
|
||||||
|
|
||||||
// Check for conflicts with the new binding.
|
// Check for conflicts with the new binding.
|
||||||
if let Some(model) = self.shortcut_models.get_mut(short_id) {
|
if let Some(model) = self.shortcut_models.get_mut(short_id)
|
||||||
if let Some(shortcut) = model.bindings.get_mut(id) {
|
&& let Some(shortcut) = model.bindings.get_mut(id)
|
||||||
|
{
|
||||||
if shortcut.input.is_empty() {
|
if shortcut.input.is_empty() {
|
||||||
return Task::none();
|
return Task::none();
|
||||||
}
|
}
|
||||||
|
|
@ -725,12 +710,12 @@ impl Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Apply if no conflict was found.
|
// Apply if no conflict was found.
|
||||||
if let Some(new_binding) = apply_binding {
|
if let Some(new_binding) = apply_binding
|
||||||
if let Some(model) = self.shortcut_models.get_mut(short_id) {
|
&& let Some(model) = self.shortcut_models.get_mut(short_id)
|
||||||
if let Some(shortcut) = model.bindings.get_mut(id) {
|
&& let Some(shortcut) = model.bindings.get_mut(id)
|
||||||
|
{
|
||||||
let prev_binding = mem::replace(&mut shortcut.binding, new_binding.clone());
|
let prev_binding = mem::replace(&mut shortcut.binding, new_binding.clone());
|
||||||
shortcut.is_saved = true;
|
shortcut.is_saved = true;
|
||||||
shortcut.reset();
|
shortcut.reset();
|
||||||
|
|
@ -746,11 +731,7 @@ impl Model {
|
||||||
self.config_remove(&prev_binding);
|
self.config_remove(&prev_binding);
|
||||||
}
|
}
|
||||||
self.config_add(action, new_binding);
|
self.config_add(action, new_binding);
|
||||||
return cosmic::widget::text_input::focus(
|
return cosmic::widget::text_input::focus(self.add_keybindings_button_id.clone());
|
||||||
self.add_keybindings_button_id.clone(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -431,8 +431,8 @@ impl Page {
|
||||||
hw_address,
|
hw_address,
|
||||||
..
|
..
|
||||||
} = dialog
|
} = dialog
|
||||||
|
&& let Some(nm) = self.nm_state.as_mut()
|
||||||
{
|
{
|
||||||
if let Some(nm) = self.nm_state.as_mut() {
|
|
||||||
self.connecting.insert(ssid.clone());
|
self.connecting.insert(ssid.clone());
|
||||||
_ = nm
|
_ = nm
|
||||||
.sender
|
.sender
|
||||||
|
|
@ -444,7 +444,6 @@ impl Page {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Message::TogglePasswordVisibility => {
|
Message::TogglePasswordVisibility => {
|
||||||
if let Some(WiFiDialog::Password {
|
if let Some(WiFiDialog::Password {
|
||||||
|
|
@ -848,20 +847,17 @@ fn connection_settings(conn: zbus::Connection) -> Task<crate::app::Message> {
|
||||||
})
|
})
|
||||||
// Reduce the settings list into a SSID->UUID map.
|
// Reduce the settings list into a SSID->UUID map.
|
||||||
.fold(BTreeMap::new(), |mut set, settings| async move {
|
.fold(BTreeMap::new(), |mut set, settings| async move {
|
||||||
if let Some(ref wifi) = settings.wifi {
|
if let Some(ref wifi) = settings.wifi
|
||||||
if let Some(ssid) = wifi
|
&& let Some(ssid) = wifi
|
||||||
.ssid
|
.ssid
|
||||||
.clone()
|
.clone()
|
||||||
.and_then(|ssid| String::from_utf8(ssid).ok())
|
.and_then(|ssid| String::from_utf8(ssid).ok())
|
||||||
|
&& let Some(ref connection) = settings.connection
|
||||||
|
&& let Some(uuid) = connection.uuid.clone()
|
||||||
{
|
{
|
||||||
if let Some(ref connection) = settings.connection {
|
|
||||||
if let Some(uuid) = connection.uuid.clone() {
|
|
||||||
set.insert(ssid.into(), uuid.into());
|
set.insert(ssid.into(), uuid.into());
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
set
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -319,16 +319,16 @@ impl Battery {
|
||||||
&& (percent - 100.0_f64).abs() < f64::EPSILON;
|
&& (percent - 100.0_f64).abs() < f64::EPSILON;
|
||||||
|
|
||||||
if !is_charging {
|
if !is_charging {
|
||||||
if let Ok(time) = proxy.time_to_empty().await {
|
if let Ok(time) = proxy.time_to_empty().await
|
||||||
if let Ok(dur) = Duration::from_std(std::time::Duration::from_secs(time as u64)) {
|
&& let Ok(dur) = Duration::from_std(std::time::Duration::from_secs(time as u64))
|
||||||
|
{
|
||||||
remaining_duration = dur;
|
remaining_duration = dur;
|
||||||
}
|
}
|
||||||
}
|
} else if let Ok(time) = proxy.time_to_full().await
|
||||||
} else if let Ok(time) = proxy.time_to_full().await {
|
&& let Ok(dur) = Duration::from_std(std::time::Duration::from_secs(time as u64))
|
||||||
if let Ok(dur) = Duration::from_std(std::time::Duration::from_secs(time as u64)) {
|
{
|
||||||
remaining_duration = dur;
|
remaining_duration = dur;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let battery_percent = if percent > 95.0 {
|
let battery_percent = if percent > 95.0 {
|
||||||
100
|
100
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ static SUSPEND_TIMES: &[Duration] = &[
|
||||||
|
|
||||||
fn format_time(duration: Duration) -> String {
|
fn format_time(duration: Duration) -> String {
|
||||||
let m = duration.as_secs() / 60;
|
let m = duration.as_secs() / 60;
|
||||||
if m % 60 == 0 {
|
if m.is_multiple_of(60) {
|
||||||
fl!("x-hours", number = (m / 60))
|
fl!("x-hours", number = (m / 60))
|
||||||
} else {
|
} else {
|
||||||
fl!("x-minutes", number = m)
|
fl!("x-minutes", number = m)
|
||||||
|
|
|
||||||
|
|
@ -27,13 +27,14 @@ pub fn passwd(range: (u64, u64)) -> Vec<PasswdUser> {
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(user) = line.trim().parse::<PasswdUser>() {
|
if let Ok(user) = line.trim().parse::<PasswdUser>()
|
||||||
if user.uid >= range.0 && user.uid <= range.1 {
|
&& user.uid >= range.0
|
||||||
|
&& user.uid <= range.1
|
||||||
|
{
|
||||||
users.push(user);
|
users.push(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
users
|
users
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -965,14 +965,14 @@ fn get_encrypt_method() -> String {
|
||||||
let reader = BufReader::new(login_defs);
|
let reader = BufReader::new(login_defs);
|
||||||
|
|
||||||
for line in reader.lines().map_while(Result::ok) {
|
for line in reader.lines().map_while(Result::ok) {
|
||||||
if !line.trim().is_empty() {
|
if !line.trim().is_empty()
|
||||||
if let Some(index) = line.find(|c: char| c.is_whitespace()) {
|
&& let Some(index) = line.find(|c: char| c.is_whitespace())
|
||||||
|
{
|
||||||
let key = line[0..index].trim();
|
let key = line[0..index].trim();
|
||||||
if key == "ENCRYPT_METHOD" {
|
if key == "ENCRYPT_METHOD" {
|
||||||
value = line[(index + 1)..].trim().to_string();
|
value = line[(index + 1)..].trim().to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -204,26 +204,24 @@ impl Page {
|
||||||
pub fn update(&mut self, message: Message) -> cosmic::Task<crate::app::Message> {
|
pub fn update(&mut self, message: Message) -> cosmic::Task<crate::app::Message> {
|
||||||
match message {
|
match message {
|
||||||
Message::AddLanguage(id) => {
|
Message::AddLanguage(id) => {
|
||||||
if let Some(language) = self.available_languages.get(id) {
|
if let Some(language) = self.available_languages.get(id)
|
||||||
if let Some((config, locales)) = self.config.as_mut() {
|
&& let Some((config, locales)) = self.config.as_mut()
|
||||||
if !locales.contains(&language.lang_code) {
|
&& !locales.contains(&language.lang_code)
|
||||||
|
{
|
||||||
locales.push(language.lang_code.clone());
|
locales.push(language.lang_code.clone());
|
||||||
_ = config.set("system_locales", &locales);
|
_ = config.set("system_locales", &locales);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Message::RemoveLanguage(id) => {
|
Message::RemoveLanguage(id) => {
|
||||||
if let Some(language) = self.available_languages.remove(id) {
|
if let Some(language) = self.available_languages.remove(id)
|
||||||
if let Some((config, locales)) = self.config.as_mut() {
|
&& let Some((config, locales)) = self.config.as_mut()
|
||||||
if let Some(pos) = locales.iter().position(|l| l == &language.lang_code) {
|
&& let Some(pos) = locales.iter().position(|l| l == &language.lang_code)
|
||||||
|
{
|
||||||
locales.remove(pos);
|
locales.remove(pos);
|
||||||
_ = config.set("system_locales", &locales);
|
_ = config.set("system_locales", &locales);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Message::SelectRegion(id) => {
|
Message::SelectRegion(id) => {
|
||||||
if let Some((region, language)) =
|
if let Some((region, language)) =
|
||||||
|
|
@ -235,11 +233,11 @@ impl Page {
|
||||||
let region = region.lang_code.clone();
|
let region = region.lang_code.clone();
|
||||||
|
|
||||||
return cosmic::task::future(async move {
|
return cosmic::task::future(async move {
|
||||||
if let Ok(exit_status) = set_locale(lang, region.clone()).await {
|
if let Ok(exit_status) = set_locale(lang, region.clone()).await
|
||||||
if exit_status.success() {
|
&& exit_status.success()
|
||||||
|
{
|
||||||
update_time_settings_after_region_change(region);
|
update_time_settings_after_region_change(region);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Message::Refresh(Arc::new(page_reload().await))
|
Message::Refresh(Arc::new(page_reload().await))
|
||||||
});
|
});
|
||||||
|
|
@ -315,8 +313,8 @@ impl Page {
|
||||||
|
|
||||||
_ = config.set("system_locales", &locales);
|
_ = config.set("system_locales", &locales);
|
||||||
|
|
||||||
if let Some(language_code) = locales.first() {
|
if let Some(language_code) = locales.first()
|
||||||
if let Some(language) = self
|
&& let Some(language) = self
|
||||||
.available_languages
|
.available_languages
|
||||||
.values()
|
.values()
|
||||||
.find(|lang| &lang.lang_code == language_code)
|
.find(|lang| &lang.lang_code == language_code)
|
||||||
|
|
@ -336,7 +334,6 @@ impl Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
cosmic::Task::none()
|
cosmic::Task::none()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,21 +25,16 @@ pub enum AccessibilityEvent {
|
||||||
Closed,
|
Closed,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)]
|
||||||
pub enum ColorFilter {
|
pub enum ColorFilter {
|
||||||
Greyscale,
|
Greyscale,
|
||||||
Deuteranopia,
|
Deuteranopia,
|
||||||
Protanopia,
|
Protanopia,
|
||||||
Tritanopia,
|
Tritanopia,
|
||||||
|
#[default]
|
||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ColorFilter {
|
|
||||||
fn default() -> Self {
|
|
||||||
ColorFilter::Unknown
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum AccessibilityRequest {
|
pub enum AccessibilityRequest {
|
||||||
Magnifier(bool),
|
Magnifier(bool),
|
||||||
|
|
|
||||||
|
|
@ -22,14 +22,10 @@ pub async fn handle_wireless_device(
|
||||||
let mut scan_changed = device.receive_last_scan_changed().await;
|
let mut scan_changed = device.receive_last_scan_changed().await;
|
||||||
|
|
||||||
if let Some(t) = scan_changed.next().await {
|
if let Some(t) = scan_changed.next().await {
|
||||||
match t.get().await {
|
if let Ok(-1) = t.get().await {
|
||||||
Ok(-1) => {
|
|
||||||
tracing::error!("wireless device scan errored");
|
tracing::error!("wireless device scan errored");
|
||||||
return Ok(Default::default());
|
return Ok(Default::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let access_points = device.get_access_points().await?;
|
let access_points = device.get_access_points().await?;
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,8 @@ pub struct KnownDeviceConnection {
|
||||||
pub uuid: Arc<str>,
|
pub uuid: Arc<str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list<'a>(
|
pub async fn list(
|
||||||
conn: &'a zbus::Connection,
|
conn: &zbus::Connection,
|
||||||
device_type_filter: fn(DeviceType) -> bool,
|
device_type_filter: fn(DeviceType) -> bool,
|
||||||
) -> zbus::Result<Vec<DeviceInfo>> {
|
) -> zbus::Result<Vec<DeviceInfo>> {
|
||||||
let nm = NetworkManager::new(conn).await?;
|
let nm = NetworkManager::new(conn).await?;
|
||||||
|
|
|
||||||
|
|
@ -16,19 +16,23 @@ impl HwAddress {
|
||||||
}
|
}
|
||||||
u64::from_str_radix(columnless_vec.join("").as_str(), 16)
|
u64::from_str_radix(columnless_vec.join("").as_str(), 16)
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|address| Some(HwAddress { address }))
|
.map(|address| HwAddress { address })
|
||||||
}
|
}
|
||||||
pub fn from_string(arg: &String) -> Option<Self> {
|
pub fn from_string(arg: &String) -> Option<Self> {
|
||||||
HwAddress::from_str(arg.as_str())
|
HwAddress::from_str(arg.as_str())
|
||||||
}
|
}
|
||||||
pub fn to_string(&self) -> String {
|
}
|
||||||
format!("{:#x}", self.address)
|
|
||||||
|
impl std::fmt::Display for HwAddress {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
let hex = format!("{:#x}", self.address)
|
||||||
.trim_start_matches("0x")
|
.trim_start_matches("0x")
|
||||||
.chars()
|
.chars()
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.chunks(2)
|
.chunks(2)
|
||||||
.map(|chunk| chunk.iter().cloned().collect::<String>())
|
.map(|chunk| chunk.iter().cloned().collect::<String>())
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join(":")
|
.join(":");
|
||||||
|
write!(f, "{}", hex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -620,7 +620,7 @@ impl NetworkManagerState {
|
||||||
|
|
||||||
std::str::from_utf8(&output.stdout)
|
std::str::from_utf8(&output.stdout)
|
||||||
.ok()
|
.ok()
|
||||||
.map_or(false, |stdout| stdout.contains("Soft blocked: yes"))
|
.is_some_and(|stdout| stdout.contains("Soft blocked: yes"))
|
||||||
}),
|
}),
|
||||||
network_manager
|
network_manager
|
||||||
.wireless_enabled()
|
.wireless_enabled()
|
||||||
|
|
@ -714,7 +714,7 @@ impl NetworkManagerState {
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|a| {
|
.filter(|a| {
|
||||||
known_ssid.contains(&a.ssid)
|
known_ssid.contains(&a.ssid)
|
||||||
&& !active_conns.iter().any(|ac| &ac.name() == a.ssid.as_ref())
|
&& !active_conns.iter().any(|ac| ac.name() == a.ssid.as_ref())
|
||||||
})
|
})
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
@ -733,7 +733,7 @@ impl NetworkManagerState {
|
||||||
self.wireless_access_points = Vec::new();
|
self.wireless_access_points = Vec::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn connect_wifi<'a>(
|
async fn connect_wifi(
|
||||||
&self,
|
&self,
|
||||||
conn: &zbus::Connection,
|
conn: &zbus::Connection,
|
||||||
ssid: &str,
|
ssid: &str,
|
||||||
|
|
@ -844,8 +844,8 @@ impl NetworkManagerState {
|
||||||
let (_, active_conn) = nm
|
let (_, active_conn) = nm
|
||||||
.add_and_activate_connection(conn_settings, device.inner().path(), &ap.path)
|
.add_and_activate_connection(conn_settings, device.inner().path(), &ap.path)
|
||||||
.await?;
|
.await?;
|
||||||
let dummy = ActiveConnectionProxy::new(&conn, active_conn).await?;
|
let dummy = ActiveConnectionProxy::new(conn, active_conn).await?;
|
||||||
let active = ActiveConnectionProxy::builder(&conn)
|
let active = ActiveConnectionProxy::builder(conn)
|
||||||
.destination(dummy.inner().destination().to_owned())
|
.destination(dummy.inner().destination().to_owned())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.interface(dummy.inner().interface().to_owned())
|
.interface(dummy.inner().interface().to_owned())
|
||||||
|
|
@ -867,14 +867,13 @@ impl NetworkManagerState {
|
||||||
} else if let Ok(enums::ActiveConnectionState::Deactivated) = state {
|
} else if let Ok(enums::ActiveConnectionState::Deactivated) = state {
|
||||||
return Err(Error::ConnectionActivate);
|
return Err(Error::ConnectionActivate);
|
||||||
}
|
}
|
||||||
match tokio::time::timeout(Duration::from_secs(20), changes.next()).await {
|
if let Ok(Some(s)) =
|
||||||
Ok(Some(s)) => {
|
tokio::time::timeout(Duration::from_secs(20), changes.next()).await
|
||||||
|
{
|
||||||
let state = s.get().await.unwrap_or_default().into();
|
let state = s.get().await.unwrap_or_default().into();
|
||||||
if matches!(state, enums::ActiveConnectionState::Activated) {
|
if matches!(state, enums::ActiveConnectionState::Activated) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
count -= 1;
|
count -= 1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue