-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat: check if webview runtime is accessible when creating a webview #13406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e0cf2dd
feat: check if webview runtime is accessible when creating a webview
amrbashir af9bc3b
license headers
amrbashir fd1dcb2
Update crates/tauri-runtime-wry/src/dialog/windows.rs
amrbashir 99bb35a
Update crates/tauri-runtime-wry/src/dialog/windows.rs
amrbashir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "tauri": "patch:enhance" | ||
| "tauri-runtime-wry": "patch:enhance" | ||
| --- | ||
|
|
||
| Check if the webview runtime is accessible when creating a webview, returning an error if it doesn't. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright 2019-2024 Tauri Programme within The Commons Conservancy | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #[cfg(windows)] | ||
| mod windows; | ||
|
|
||
| pub fn error<S: AsRef<str>>(err: S) { | ||
| #[cfg(windows)] | ||
| windows::error(err); | ||
|
|
||
| #[cfg(not(windows))] | ||
| { | ||
| unimplemented!("Error dialog is not implemented for this platform"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| // Copyright 2019-2024 Tauri Programme within The Commons Conservancy | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| use windows::core::{w, HSTRING, PCWSTR}; | ||
|
|
||
| enum Level { | ||
| Error, | ||
| #[allow(unused)] | ||
| Warning, | ||
| #[allow(unused)] | ||
| Info, | ||
| } | ||
|
|
||
| pub fn error<S: AsRef<str>>(err: S) { | ||
| dialog_inner(err.as_ref(), Level::Error); | ||
| } | ||
|
|
||
| fn dialog_inner(err: &str, level: Level) { | ||
| let title = match level { | ||
| Level::Warning => w!("Warning"), | ||
| Level::Error => w!("Error"), | ||
| Level::Info => w!("Info"), | ||
| }; | ||
|
|
||
| #[cfg(not(feature = "common-controls-v6"))] | ||
| { | ||
| use windows::Win32::UI::WindowsAndMessaging::*; | ||
|
|
||
| let err = remove_hyperlink(err); | ||
| let err = HSTRING::from(err); | ||
|
|
||
| unsafe { | ||
| MessageBoxW( | ||
| None, | ||
| err, | ||
| title, | ||
| match level { | ||
| Level::Warning => MB_ICONWARNING, | ||
| Level::Error => MB_ICONERROR, | ||
| Level::Info => MB_ICONINFORMATION, | ||
| }, | ||
| ) | ||
| }; | ||
| } | ||
|
|
||
| #[cfg(feature = "common-controls-v6")] | ||
| { | ||
| use windows::core::HRESULT; | ||
| use windows::Win32::Foundation::*; | ||
| use windows::Win32::UI::Controls::*; | ||
| use windows::Win32::UI::Shell::*; | ||
| use windows::Win32::UI::WindowsAndMessaging::*; | ||
|
|
||
| extern "system" fn task_dialog_callback( | ||
| _hwnd: HWND, | ||
| msg: TASKDIALOG_NOTIFICATIONS, | ||
| _wparam: WPARAM, | ||
| lparam: LPARAM, | ||
| _data: isize, | ||
| ) -> HRESULT { | ||
| if msg == TDN_HYPERLINK_CLICKED { | ||
| let link = PCWSTR(lparam.0 as _); | ||
| let _ = unsafe { ShellExecuteW(None, None, link, None, None, SW_SHOWNORMAL) }; | ||
| } | ||
|
|
||
| S_OK | ||
| } | ||
|
|
||
| let err = HSTRING::from(err); | ||
| let err = PCWSTR(err.as_ptr()); | ||
|
|
||
| let task_dialog_config = TASKDIALOGCONFIG { | ||
| cbSize: std::mem::size_of::<TASKDIALOGCONFIG>() as u32, | ||
| dwFlags: TDF_ALLOW_DIALOG_CANCELLATION | TDF_ENABLE_HYPERLINKS, | ||
| pszWindowTitle: title, | ||
| pszContent: err, | ||
| Anonymous1: TASKDIALOGCONFIG_0 { | ||
| pszMainIcon: match level { | ||
| Level::Warning => TD_WARNING_ICON, | ||
| Level::Error => TD_ERROR_ICON, | ||
| Level::Info => TD_INFORMATION_ICON, | ||
| }, | ||
| }, | ||
| dwCommonButtons: TDCBF_OK_BUTTON, | ||
| pfCallback: Some(task_dialog_callback), | ||
| ..Default::default() | ||
| }; | ||
|
|
||
| let _ = unsafe { TaskDialogIndirect(&task_dialog_config, None, None, None) }; | ||
| } | ||
| } | ||
|
|
||
| #[cfg(not(feature = "common-controls-v6"))] | ||
| fn remove_hyperlink(str: &str) -> String { | ||
| let mut result = String::new(); | ||
| let mut in_hyperlink = false; | ||
|
|
||
| for c in str.chars() { | ||
| if c == '<' { | ||
| in_hyperlink = true; | ||
| } else if c == '>' { | ||
| in_hyperlink = false; | ||
| } else if !in_hyperlink { | ||
| result.push(c); | ||
| } | ||
| } | ||
|
|
||
| result | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| #[cfg(not(feature = "common-controls-v6"))] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_remove_hyperlink() { | ||
| let input = "This is a <A href=\"some link\">test</A> string."; | ||
| let expected = "This is a test string."; | ||
| let result = remove_hyperlink(input); | ||
| assert_eq!(result, expected); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.