|
1 | 1 | // SPDX-License-Identifier: GPL-3.0-only
|
2 | 2 |
|
3 |
| -use std::sync::{Arc, Condvar, Mutex}; |
| 3 | +use std::{ |
| 4 | + fs, io, |
| 5 | + sync::{Arc, Condvar, Mutex}, |
| 6 | +}; |
4 | 7 |
|
5 | 8 | // use ashpd::enumflags2::{bitflags, BitFlag, BitFlags};
|
6 | 9 | use cosmic::{iced::window, widget};
|
@@ -160,16 +163,49 @@ impl Background {
|
160 | 163 |
|
161 | 164 | /// Enable or disable autostart for an application
|
162 | 165 | ///
|
163 |
| - /// Deprecated but seemingly still in use |
| 166 | + /// Deprecated in terms of the portal but seemingly still in use |
| 167 | + /// Spec: https://specifications.freedesktop.org/autostart-spec/latest/ |
164 | 168 | pub async fn enable_autostart(
|
165 | 169 | &self,
|
166 | 170 | app_id: String,
|
167 | 171 | enable: bool,
|
168 | 172 | commandline: Vec<String>,
|
169 | 173 | flags: u32,
|
170 | 174 | ) -> fdo::Result<bool> {
|
171 |
| - log::warn!("Autostart not implemented"); |
172 |
| - Ok(enable) |
| 175 | + log::info!( |
| 176 | + "{} autostart for {app_id}", |
| 177 | + if enable { "Enabling" } else { "Disabling" } |
| 178 | + ); |
| 179 | + |
| 180 | + let Some((autostart, launch_entry)) = dirs::config_dir().map(|config| { |
| 181 | + let autostart = config.join("autostart"); |
| 182 | + (autostart, autostart.join(format!("{app_id}.desktop"))) |
| 183 | + }) else { |
| 184 | + return fdo::Error::FileNotFound("XDG_CONFIG_HOME"); |
| 185 | + }; |
| 186 | + |
| 187 | + if !enable { |
| 188 | + log::debug!("Removing autostart entry {}", launch_entry.display()); |
| 189 | + match fs::remove_file(launch_entry) { |
| 190 | + Ok(_) => Ok(false), |
| 191 | + Err(e) if e.kind() == io::ErrorKind::NotFound => { |
| 192 | + log::debug!("Autostart entry for {app_id} doesn't exist"); |
| 193 | + Ok(false) |
| 194 | + } |
| 195 | + Err(e) => { |
| 196 | + log::error!( |
| 197 | + "Error removing autostart entry for {app_id}\n\tPath: {}\n\tError: {e}", |
| 198 | + launch_entry.display() |
| 199 | + ); |
| 200 | + Err(fdo::Error::IOError(format!( |
| 201 | + "{e}: ({})", |
| 202 | + launch_entry.display() |
| 203 | + ))) |
| 204 | + } |
| 205 | + } |
| 206 | + } else { |
| 207 | + Ok(enable) |
| 208 | + } |
173 | 209 | }
|
174 | 210 |
|
175 | 211 | /// Emitted when running applications change their state
|
|
0 commit comments