Skip to content

Commit

Permalink
ci: fix bench please (#710)
Browse files Browse the repository at this point in the history
* ci: fix bench please

* remove dot from benches scheme

* fix uri usages

* don't bench pullrequests
  • Loading branch information
amrbashir committed Sep 29, 2022
1 parent 683f866 commit 7458952
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
8 changes: 4 additions & 4 deletions bench/tests/src/cpu_intensive.rs
Expand Up @@ -25,10 +25,10 @@ fn main() -> wry::Result<()> {
};
let webview = WebViewBuilder::new(window)
.unwrap()
.with_custom_protocol("wry.bench".into(), move |request| {
.with_custom_protocol("wrybench".into(), move |request| {
let path = request.uri().to_string();
let requested_asset_path = path.strip_prefix("wry.bench://").unwrap();
let (data, mimetype): (Vec<u8>, _) = match requested_asset_path {
let requested_asset_path = path.strip_prefix("wrybench://localhost").unwrap();
let (data, mimetype): (Vec<u8>, String) = match requested_asset_path {
"/index.css" => (
include_bytes!("static/index.css").to_vec(),
"text/css".into(),
Expand All @@ -52,7 +52,7 @@ fn main() -> wry::Result<()> {
.body(data)
.map_err(Into::into)
})
.with_url("wry.bench://")?
.with_url("wrybench://localhost")?
.with_ipc_handler(handler)
.build()?;

Expand Down
4 changes: 2 additions & 2 deletions bench/tests/src/custom_protocol.rs
Expand Up @@ -32,7 +32,7 @@ fn main() -> wry::Result<()> {
let _webview = WebViewBuilder::new(window)
.unwrap()
.with_ipc_handler(handler)
.with_custom_protocol("wry.bench".into(), move |_request| {
.with_custom_protocol("wrybench".into(), move |_request| {
let index_html = r#"
<!DOCTYPE html>
<html lang="en">
Expand All @@ -56,7 +56,7 @@ fn main() -> wry::Result<()> {
.body(index_html.into())
.map_err(Into::into)
})
.with_url("wry.bench://")?
.with_url("wrybench://localhost")?
.build()?;

event_loop.run(move |event, _, control_flow| {
Expand Down
18 changes: 13 additions & 5 deletions examples/custom_protocol.rs
Expand Up @@ -2,6 +2,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use std::path::PathBuf;

fn main() -> wry::Result<()> {
use std::fs::{canonicalize, read};

Expand All @@ -24,15 +26,21 @@ fn main() -> wry::Result<()> {
let webview = WebViewBuilder::new(window)
.unwrap()
.with_custom_protocol("wry".into(), move |request| {
let path = request.uri().to_string();
let path = path.strip_prefix("wry://").unwrap();
let path = &request.uri().path();
// Read the file content from file path
let content = read(canonicalize(&path)?)?;
let content = read(canonicalize(PathBuf::from("examples").join(
if path == &"/" {
"index.html"
} else {
// remove leading slash
&path[1..]
},
))?)?;

// Return asset contents and mime types based on file extentions
// If you don't want to do this manually, there are some crates for you.
// Such as `infer` and `mime_guess`.
let (data, meta) = if path.ends_with(".html") {
let (data, meta) = if path.ends_with(".html") || path == &"/" {
(content, "text/html")
} else if path.ends_with(".js") {
(content, "text/javascript")
Expand All @@ -48,7 +56,7 @@ fn main() -> wry::Result<()> {
.map_err(Into::into)
})
// tell the webview to load the custom protocol
.with_url("wry://examples/index.html")?
.with_url("wry://localhost")?
.with_devtools(true)
.build()?;

Expand Down
6 changes: 3 additions & 3 deletions examples/form_post.rs
Expand Up @@ -31,16 +31,16 @@ fn main() -> wry::Result<()> {
}
}

let path = request.uri().to_string();
let path = path.strip_prefix("wry://").unwrap();
// remove leading slash
let path = &request.uri().path()[1..];

Response::builder()
.header(CONTENT_TYPE, "text/html")
.body(read(canonicalize(&path)?)?)
.map_err(Into::into)
})
// tell the webview to load the custom protocol
.with_url("wry://examples/form.html")?
.with_url("wry://localhost/examples/form.html")?
.build()?;

event_loop.run(move |event, _, control_flow| {
Expand Down
4 changes: 2 additions & 2 deletions examples/stream.html
Expand Up @@ -13,15 +13,15 @@

<body>
<video id="video_source" style="width: 90vw; height: 90vh" controls="" autoplay="" name="media">
<source src="wry://examples/test_video.mp4" type="video/mp4" />
<source src="wry://localhost/examples/test_video.mp4" type="video/mp4" />
</video>

<script>
(function () {
if (navigator.userAgent.includes("Windows")) {
const video = document.getElementById("video_source");
const sources = video.getElementsByTagName("source");
sources[0].src = "https://wry.examples/test_video.mp4";
sources[0].src = "https://wry.localhost/examples/test_video.mp4";
video.load();
}
})();
Expand Down
6 changes: 3 additions & 3 deletions examples/stream_range.rs
Expand Up @@ -53,8 +53,8 @@ fn main() -> wry::Result<()> {
let _webview = WebViewBuilder::new(window)
.unwrap()
.with_custom_protocol("wry".into(), move |request| {
let path = request.uri().to_string();
let path = path.strip_prefix("wry://").unwrap();
// remove leading slash
let path = &request.uri().path()[1..];

// Read the file content from file path
let mut content = File::open(canonicalize(&path)?)?;
Expand Down Expand Up @@ -129,7 +129,7 @@ fn main() -> wry::Result<()> {
.map_err(Into::into)
})
// tell the webview to load the custom protocol
.with_url("wry://examples/stream.html")?
.with_url("wry://localhost/examples/stream.html")?
.build()?;

event_loop.run(move |event, _, control_flow| {
Expand Down

0 comments on commit 7458952

Please sign in to comment.