-
-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use http instead of file for windows custom protocol workaround (#173)
* Use http instead of file for windows custom protocol workaround Fix #170 * Add change file * Add custom protocol example * Replace `tauri` for `wry`
- Loading branch information
Showing
5 changed files
with
103 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
"wry": minor | ||
--- | ||
|
||
Fix `history.pushState` in webview2. |
This file contains 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 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,91 @@ | ||
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-License-Identifier: MIT | ||
|
||
fn main() -> wry::Result<()> { | ||
use wry::{ | ||
application::{ | ||
event::{Event, StartCause, WindowEvent}, | ||
event_loop::{ControlFlow, EventLoop}, | ||
window::WindowBuilder, | ||
}, | ||
webview::WebViewBuilder, | ||
}; | ||
|
||
let event_loop = EventLoop::new(); | ||
let window = WindowBuilder::new() | ||
.with_title("Hello World") | ||
.build(&event_loop) | ||
.unwrap(); | ||
|
||
let _webview = WebViewBuilder::new(window) | ||
.unwrap() | ||
.with_custom_protocol("wry.dev".into(), move |requested_asset_path| { | ||
// remove the protocol from the path for easiest match | ||
let requested_asset_path = requested_asset_path.replace("wry.dev://", ""); | ||
|
||
// sample index.html file | ||
// files can be bundled easilly into the binary | ||
// with https://doc.rust-lang.org/std/macro.include_bytes.html | ||
|
||
let index_html = r#" | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
</head> | ||
<body> | ||
<h1>Welcome to WRY!</h1> | ||
<a href="/hello.html">Link</a> | ||
<script type="text/javascript" src="/hello.js"></script> | ||
</body> | ||
</html>"#; | ||
|
||
// sample hello.js file | ||
let hello_js = "console.log(\"hello from javascript\");"; | ||
|
||
// sample hello.html file | ||
let hello_html = r#" | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
</head> | ||
<body> | ||
<h1>Sample page!</h1> | ||
<a href="/index.html">Back home</a> | ||
<script type="text/javascript" src="/hello.js"></script> | ||
</body> | ||
</html>"#; | ||
|
||
match requested_asset_path.as_str() { | ||
// if our path match /hello.html | ||
"/hello.html" => Ok(hello_html.as_bytes().into()), | ||
// if our path match /hello.js | ||
"/hello.js" => Ok(hello_js.as_bytes().into()), | ||
// other paths should resolve index | ||
// more logic can be applied here | ||
_ => Ok(index_html.as_bytes().into()), | ||
} | ||
}) | ||
// tell the webview to load the custom protocol | ||
.with_url("wry.dev://")? | ||
.build()?; | ||
|
||
event_loop.run(move |event, _, control_flow| { | ||
*control_flow = ControlFlow::Poll; | ||
|
||
match event { | ||
Event::NewEvents(StartCause::Init) => println!("Wry application started!"), | ||
Event::WindowEvent { | ||
event: WindowEvent::CloseRequested, | ||
.. | ||
} => *control_flow = ControlFlow::Exit, | ||
_ => (), | ||
} | ||
}); | ||
} |
This file contains 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 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