mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
servoshell: Port Authentication dialog code to use egui intead of tinyfiledialogs (#35507)
Signed-off-by: L Ashwin B <lashwinib@gmail.com>
This commit is contained in:
parent
df6d636168
commit
b0561c78c7
2 changed files with 78 additions and 9 deletions
|
@ -172,7 +172,13 @@ impl RunningAppState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn for_each_active_dialog(&self, callback: impl Fn(&mut Dialog) -> bool) {
|
pub(crate) fn for_each_active_dialog(&self, callback: impl Fn(&mut Dialog) -> bool) {
|
||||||
let Some(webview_id) = self.focused_webview().as_ref().map(WebView::id) else {
|
let last_created_webview_id = self.inner().creation_order.last().cloned();
|
||||||
|
let Some(webview_id) = self
|
||||||
|
.focused_webview()
|
||||||
|
.as_ref()
|
||||||
|
.map(WebView::id)
|
||||||
|
.or(last_created_webview_id)
|
||||||
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -392,19 +398,17 @@ impl WebViewDelegate for RunningAppState {
|
||||||
|
|
||||||
fn request_authentication(
|
fn request_authentication(
|
||||||
&self,
|
&self,
|
||||||
_webview: WebView,
|
webview: WebView,
|
||||||
authentication_request: AuthenticationRequest,
|
authentication_request: AuthenticationRequest,
|
||||||
) {
|
) {
|
||||||
if self.inner().headless {
|
if self.inner().headless {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let (Some(username), Some(password)) = (
|
self.add_dialog(
|
||||||
tinyfiledialogs::input_box("", "username", ""),
|
webview,
|
||||||
tinyfiledialogs::input_box("", "password", ""),
|
Dialog::new_authentication_dialog(authentication_request),
|
||||||
) {
|
);
|
||||||
authentication_request.authenticate(username, password);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn request_open_auxiliary_webview(
|
fn request_open_auxiliary_webview(
|
||||||
|
|
|
@ -9,7 +9,7 @@ use egui::Modal;
|
||||||
use egui_file_dialog::{DialogState, FileDialog as EguiFileDialog};
|
use egui_file_dialog::{DialogState, FileDialog as EguiFileDialog};
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use servo::ipc_channel::ipc::IpcSender;
|
use servo::ipc_channel::ipc::IpcSender;
|
||||||
use servo::{FilterPattern, PromptResult};
|
use servo::{AuthenticationRequest, FilterPattern, PromptResult};
|
||||||
|
|
||||||
pub enum Dialog {
|
pub enum Dialog {
|
||||||
File {
|
File {
|
||||||
|
@ -30,6 +30,11 @@ pub enum Dialog {
|
||||||
input_text: String,
|
input_text: String,
|
||||||
sender: IpcSender<Option<String>>,
|
sender: IpcSender<Option<String>>,
|
||||||
},
|
},
|
||||||
|
Authentication {
|
||||||
|
username: String,
|
||||||
|
password: String,
|
||||||
|
request: Option<AuthenticationRequest>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dialog {
|
impl Dialog {
|
||||||
|
@ -82,6 +87,14 @@ impl Dialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_authentication_dialog(authentication_request: AuthenticationRequest) -> Self {
|
||||||
|
Dialog::Authentication {
|
||||||
|
username: String::new(),
|
||||||
|
password: String::new(),
|
||||||
|
request: Some(authentication_request),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, ctx: &egui::Context) -> bool {
|
pub fn update(&mut self, ctx: &egui::Context) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Dialog::File {
|
Dialog::File {
|
||||||
|
@ -196,6 +209,58 @@ impl Dialog {
|
||||||
});
|
});
|
||||||
is_open
|
is_open
|
||||||
},
|
},
|
||||||
|
Dialog::Authentication {
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
ref mut request,
|
||||||
|
} => {
|
||||||
|
let mut is_open = true;
|
||||||
|
Modal::new("input".into()).show(ctx, |ui| {
|
||||||
|
let mut frame = egui::Frame::default().inner_margin(10.0).begin(ui);
|
||||||
|
frame.content_ui.set_min_width(150.0);
|
||||||
|
|
||||||
|
if let Some(ref request) = request {
|
||||||
|
let url =
|
||||||
|
egui::RichText::new(request.url().origin().unicode_serialization());
|
||||||
|
frame.content_ui.heading(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
frame.content_ui.add_space(10.0);
|
||||||
|
|
||||||
|
frame
|
||||||
|
.content_ui
|
||||||
|
.label("This site is asking you to sign in.");
|
||||||
|
frame.content_ui.add_space(10.0);
|
||||||
|
|
||||||
|
frame.content_ui.label("Username:");
|
||||||
|
frame.content_ui.text_edit_singleline(username);
|
||||||
|
frame.content_ui.add_space(10.0);
|
||||||
|
|
||||||
|
frame.content_ui.label("Password:");
|
||||||
|
frame
|
||||||
|
.content_ui
|
||||||
|
.add(egui::TextEdit::singleline(password).password(true));
|
||||||
|
|
||||||
|
frame.end(ui);
|
||||||
|
|
||||||
|
egui::Sides::new().show(
|
||||||
|
ui,
|
||||||
|
|_ui| {},
|
||||||
|
|ui| {
|
||||||
|
if ui.button("Sign in").clicked() {
|
||||||
|
let request =
|
||||||
|
request.take().expect("non-None until dialog is closed");
|
||||||
|
request.authenticate(username.clone(), password.clone());
|
||||||
|
is_open = false;
|
||||||
|
}
|
||||||
|
if ui.button("Cancel").clicked() {
|
||||||
|
is_open = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
is_open
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue