feat(core) Use rfd for message dialogs (#1887)

This commit is contained in:
Poly 2021-05-21 20:44:29 +02:00 committed by GitHub
parent 35a2052771
commit 74714177e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 15 deletions

View File

@ -51,7 +51,6 @@ ignore = "0.4"
either = "1.6"
tar = "0.4"
flate2 = "1.0"
tinyfiledialogs = "3.3"
http = "0.2"
state = "0.4"
bincode = "1.3"
@ -80,7 +79,7 @@ shared_child = { version = "0.3", optional = true }
os_pipe = { version = "0.9", optional = true }
# Dialogs
rfd = { version = "0.3", optional = true }
rfd = "0.4"
# Updater
minisign-verify = { version = "0.1", optional = true }
@ -127,8 +126,8 @@ shell-all = [ "shell-open", "shell-execute" ]
shell-execute = [ "shared_child", "os_pipe" ]
shell-open = [ "open" ]
dialog-all = [ "dialog-open", "dialog-save" ]
dialog-open = [ "rfd" ]
dialog-save = [ "rfd" ]
dialog-open = [ ]
dialog-save = [ ]
http-all = [ ]
http-request = [ ]
notification-all = [ "notify-rust" ]

View File

@ -5,8 +5,6 @@
#[cfg(any(dialog_open, dialog_save))]
use std::path::{Path, PathBuf};
use tinyfiledialogs::{message_box_ok, message_box_yes_no, MessageBoxIcon, YesNo};
/// The file dialog builder.
/// Constructs file picker dialogs that can select single/multiple files or directories.
#[cfg(any(dialog_open, dialog_save))]
@ -69,18 +67,24 @@ pub enum AskResponse {
/// Displays a dialog with a message and an optional title with a "yes" and a "no" button
pub fn ask(title: impl AsRef<str>, message: impl AsRef<str>) -> AskResponse {
match message_box_yes_no(
title.as_ref(),
message.as_ref(),
MessageBoxIcon::Question,
YesNo::No,
) {
YesNo::Yes => AskResponse::Yes,
YesNo::No => AskResponse::No,
match rfd::MessageDialog::new()
.set_title(title.as_ref())
.set_description(message.as_ref())
.set_buttons(rfd::MessageButtons::YesNo)
.set_level(rfd::MessageLevel::Info)
.show()
{
true => AskResponse::Yes,
false => AskResponse::No,
}
}
/// Displays a message dialog
pub fn message(title: impl AsRef<str>, message: impl AsRef<str>) {
message_box_ok(title.as_ref(), message.as_ref(), MessageBoxIcon::Info);
rfd::MessageDialog::new()
.set_title(title.as_ref())
.set_description(message.as_ref())
.set_buttons(rfd::MessageButtons::Ok)
.set_level(rfd::MessageLevel::Info)
.show();
}