Merge branch 'run_executables' of https://github.com/francesco-gaglione/cosmic-files into francesco-gaglione-run_executables
This commit is contained in:
commit
b0ac065742
2 changed files with 77 additions and 11 deletions
|
|
@ -66,6 +66,11 @@ apply-to-all = Apply to all
|
||||||
keep-both = Keep both
|
keep-both = Keep both
|
||||||
skip = Skip
|
skip = Skip
|
||||||
|
|
||||||
|
## Execution permission Dialog
|
||||||
|
add-permission-title = Add execution permission
|
||||||
|
add-permission-control = Add execution permission to {$path}
|
||||||
|
add-permission = Add permission
|
||||||
|
|
||||||
## Metadata Dialog
|
## Metadata Dialog
|
||||||
owner = Owner
|
owner = Owner
|
||||||
group = Group
|
group = Group
|
||||||
|
|
|
||||||
83
src/app.rs
83
src/app.rs
|
|
@ -43,9 +43,13 @@ use slotmap::Key as SlotMapKey;
|
||||||
use std::{
|
use std::{
|
||||||
any::TypeId,
|
any::TypeId,
|
||||||
collections::{BTreeMap, HashMap, HashSet, VecDeque},
|
collections::{BTreeMap, HashMap, HashSet, VecDeque},
|
||||||
env, fmt, fs,
|
env,
|
||||||
|
ffi::OsStr,
|
||||||
|
fmt, fs,
|
||||||
future::pending,
|
future::pending,
|
||||||
|
io::{BufRead, BufReader},
|
||||||
num::NonZeroU16,
|
num::NonZeroU16,
|
||||||
|
os::unix::fs::PermissionsExt,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
process,
|
process,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
|
|
@ -246,6 +250,7 @@ impl MenuAction for NavMenuAction {
|
||||||
pub enum Message {
|
pub enum Message {
|
||||||
AddToSidebar(Option<Entity>),
|
AddToSidebar(Option<Entity>),
|
||||||
AppTheme(AppTheme),
|
AppTheme(AppTheme),
|
||||||
|
AddExecutablePermission(PathBuf),
|
||||||
CloseToast(widget::ToastId),
|
CloseToast(widget::ToastId),
|
||||||
Compress(Option<Entity>),
|
Compress(Option<Entity>),
|
||||||
Config(Config),
|
Config(Config),
|
||||||
|
|
@ -411,6 +416,10 @@ pub enum DialogPage {
|
||||||
name: String,
|
name: String,
|
||||||
dir: bool,
|
dir: bool,
|
||||||
},
|
},
|
||||||
|
AddExecutablePermission {
|
||||||
|
file_path: PathBuf,
|
||||||
|
run: bool,
|
||||||
|
},
|
||||||
Replace {
|
Replace {
|
||||||
from: tab::Item,
|
from: tab::Item,
|
||||||
to: tab::Item,
|
to: tab::Item,
|
||||||
|
|
@ -1457,12 +1466,31 @@ impl Application for App {
|
||||||
let to = parent.join(name);
|
let to = parent.join(name);
|
||||||
self.operation(Operation::Rename { from, to });
|
self.operation(Operation::Rename { from, to });
|
||||||
}
|
}
|
||||||
|
DialogPage::AddExecutablePermission { file_path, run } => {
|
||||||
|
let mut perms = fs::metadata(&file_path)
|
||||||
|
.expect("Failed to get metadata")
|
||||||
|
.permissions();
|
||||||
|
|
||||||
|
let current_mode = perms.mode();
|
||||||
|
let new_mode = current_mode | 0o100;
|
||||||
|
perms.set_mode(new_mode);
|
||||||
|
fs::set_permissions(&file_path, perms)
|
||||||
|
.expect("Failed to set permissions");
|
||||||
|
|
||||||
|
if run {
|
||||||
|
log::info!("running app: {:?}", file_path);
|
||||||
|
let _ = std::process::Command::new(file_path).spawn();
|
||||||
|
}
|
||||||
|
}
|
||||||
DialogPage::Replace { .. } => {
|
DialogPage::Replace { .. } => {
|
||||||
log::warn!("replace dialog should be completed with replace result");
|
log::warn!("replace dialog should be completed with replace result");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Message::AddExecutablePermission(file_path) => {
|
||||||
|
return Command::batch([self.update(Message::AddExecutablePermission(file_path))]);
|
||||||
|
}
|
||||||
Message::DialogPush(dialog_page) => {
|
Message::DialogPush(dialog_page) => {
|
||||||
self.dialog_pages.push_back(dialog_page);
|
self.dialog_pages.push_back(dialog_page);
|
||||||
}
|
}
|
||||||
|
|
@ -2254,18 +2282,33 @@ impl Application for App {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if !found_desktop_exec {
|
if !found_desktop_exec {
|
||||||
match open::that_detached(&path) {
|
let file_extension = path.extension();
|
||||||
Ok(()) => {
|
match file_extension {
|
||||||
let _ = recently_used_xbel::update_recently_used(
|
Some(ext) if ext == OsStr::new("AppImage") => {
|
||||||
&path,
|
let mut perms = fs::metadata(&path)
|
||||||
App::APP_ID.to_string(),
|
.expect("Failed to get metadata")
|
||||||
"cosmic-files".to_string(),
|
.permissions();
|
||||||
None,
|
|
||||||
|
self.dialog_pages.push_back(
|
||||||
|
DialogPage::AddExecutablePermission {
|
||||||
|
file_path: path.clone(),
|
||||||
|
run: true,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
_ => match open::that_detached(&path) {
|
||||||
log::warn!("failed to open {:?}: {}", path, err);
|
Ok(()) => {
|
||||||
}
|
let _ = recently_used_xbel::update_recently_used(
|
||||||
|
&path,
|
||||||
|
App::APP_ID.to_string(),
|
||||||
|
"cosmic-files".to_string(),
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
log::warn!("failed to open {:?}: {}", path, err);
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3049,6 +3092,24 @@ impl Application for App {
|
||||||
.spacing(space_xxs),
|
.spacing(space_xxs),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
DialogPage::AddExecutablePermission { file_path, run } => {
|
||||||
|
let mut dialog = widget::dialog(fl!("add-permission-title"))
|
||||||
|
.primary_action(
|
||||||
|
widget::button::text(fl!("add-permission"))
|
||||||
|
.style(theme::Button::Suggested)
|
||||||
|
.on_press(Message::DialogComplete),
|
||||||
|
)
|
||||||
|
.secondary_action(
|
||||||
|
widget::button::text("cancell")
|
||||||
|
.style(theme::Button::Destructive)
|
||||||
|
.on_press(Message::DialogCancel),
|
||||||
|
)
|
||||||
|
.control(widget::column().push(widget::text::text(fl!(
|
||||||
|
"add-permission-control",
|
||||||
|
path = file_path.as_os_str().to_str()
|
||||||
|
))));
|
||||||
|
dialog
|
||||||
|
}
|
||||||
DialogPage::RenameItem {
|
DialogPage::RenameItem {
|
||||||
from,
|
from,
|
||||||
parent,
|
parent,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue