permission dialog
This commit is contained in:
parent
360f8c42cc
commit
54e9be6459
2 changed files with 53 additions and 7 deletions
|
|
@ -66,6 +66,11 @@ apply-to-all = Apply to all
|
|||
keep-both = Keep both
|
||||
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
|
||||
owner = Owner
|
||||
group = Group
|
||||
|
|
|
|||
55
src/app.rs
55
src/app.rs
|
|
@ -256,6 +256,7 @@ impl MenuAction for NavMenuAction {
|
|||
pub enum Message {
|
||||
AddToSidebar(Option<Entity>),
|
||||
AppTheme(AppTheme),
|
||||
AddExecutablePermission(PathBuf),
|
||||
CloseToast(widget::ToastId),
|
||||
Compress(Option<Entity>),
|
||||
Config(Config),
|
||||
|
|
@ -416,6 +417,10 @@ pub enum DialogPage {
|
|||
name: String,
|
||||
dir: bool,
|
||||
},
|
||||
AddExecutablePermission {
|
||||
file_path: PathBuf,
|
||||
run: bool,
|
||||
},
|
||||
Replace {
|
||||
from: tab::Item,
|
||||
to: tab::Item,
|
||||
|
|
@ -1546,12 +1551,31 @@ impl Application for App {
|
|||
let to = parent.join(name);
|
||||
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 { .. } => {
|
||||
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) => {
|
||||
self.dialog_pages.push_back(dialog_page);
|
||||
}
|
||||
|
|
@ -2357,17 +2381,16 @@ impl Application for App {
|
|||
let file_extension = path.extension();
|
||||
match file_extension {
|
||||
Some(ext) if ext == OsStr::new("AppImage") => {
|
||||
// Set the executable permission to the file
|
||||
let mut perms = fs::metadata(&path)
|
||||
.expect("Failed to get metadata")
|
||||
.permissions();
|
||||
// Set the executable permission to the file
|
||||
perms.set_mode(0o755);
|
||||
fs::set_permissions(&path, perms)
|
||||
.expect("Failed to set permissions");
|
||||
|
||||
log::info!("running app: {:?}", ext);
|
||||
let _ = std::process::Command::new(path).spawn();
|
||||
self.dialog_pages.push_back(
|
||||
DialogPage::AddExecutablePermission {
|
||||
file_path: path.clone(),
|
||||
run: true,
|
||||
},
|
||||
);
|
||||
}
|
||||
_ => match open::that_detached(&path) {
|
||||
Ok(()) => {
|
||||
|
|
@ -3109,6 +3132,24 @@ impl Application for App {
|
|||
.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 {
|
||||
from,
|
||||
parent,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue