Skip to content

Commit

Permalink
refactor: reuse prompt css (#255)
Browse files Browse the repository at this point in the history
* refactor: reuse prompt css

* chore: remove todo
  • Loading branch information
pewsheen authored Dec 5, 2024
1 parent 9701e3d commit 6f17f66
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 127 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ headers = "0.3"
versoview_messages = { path = "./versoview_messages" }
serde_json = "1.0"
serde = { workspace = true }
mime = "0.3"

[target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies]
muda = "0.15"
Expand Down
36 changes: 5 additions & 31 deletions resources/components/prompt/alert.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
<html>
<head>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
display: flex;
justify-content: center;
align-items: center;
padding: 0;
margin: 0;
background-color: #7d818644;
}
.dialog {
display: flex;
background: #ffffff;
width: 400px;
min-height: 110px;
max-height: 300px;
flex-direction: column;
align-items: center;
border-radius: 10px;
box-shadow: 0 0 50px #ccc;
box-sizing: border-box;
padding: 8px;
gap: 8px;
}
.msg {
display: inline-block;
width: 100%;
min-height: 90px;
text-align: center;
}
</style>
<link
rel="stylesheet"
type="text/css"
href="verso://resources/components/prompt/prompt.css"
/>
</head>
<body>
<div class="dialog">
Expand Down
36 changes: 5 additions & 31 deletions resources/components/prompt/ok_cancel.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
<html>
<head>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
display: flex;
justify-content: center;
align-items: center;
padding: 0;
margin: 0;
background-color: #7d818644;
}
.dialog {
display: flex;
background: #ffffff;
width: 400px;
min-height: 110px;
max-height: 300px;
flex-direction: column;
align-items: center;
border-radius: 10px;
box-shadow: 0 0 50px #ccc;
box-sizing: border-box;
padding: 8px;
gap: 8px;
}
.msg {
display: inline-block;
width: 100%;
min-height: 90px;
text-align: center;
}
</style>
<link
rel="stylesheet"
type="text/css"
href="verso://resources/components/prompt/prompt.css"
/>
</head>
<body>
<div class="dialog">
Expand Down
29 changes: 29 additions & 0 deletions resources/components/prompt/prompt.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
body {
font-family: Arial, Helvetica, sans-serif;
display: flex;
justify-content: center;
align-items: center;
padding: 0;
margin: 0;
background-color: #7d818644;
}
.dialog {
display: flex;
background: #ffffff;
width: 400px;
min-height: 110px;
max-height: 300px;
flex-direction: column;
align-items: center;
border-radius: 10px;
box-shadow: 0 0 50px #ccc;
box-sizing: border-box;
padding: 8px;
gap: 8px;
}
.msg {
display: inline-block;
width: 100%;
min-height: 90px;
text-align: center;
}
36 changes: 5 additions & 31 deletions resources/components/prompt/prompt.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
<html>
<head>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
display: flex;
justify-content: center;
align-items: center;
padding: 0;
margin: 0;
background-color: #7d818644;
}
.dialog {
display: flex;
background: #ffffff;
width: 400px;
min-height: 110px;
max-height: 300px;
flex-direction: column;
align-items: center;
border-radius: 10px;
box-shadow: 0 0 50px #ccc;
box-sizing: border-box;
padding: 8px;
gap: 8px;
}
.msg {
display: inline-block;
width: 100%;
min-height: 90px;
text-align: center;
}
</style>
<link
rel="stylesheet"
type="text/css"
href="verso://resources/components/prompt/prompt.css"
/>
</head>
<body>
<div class="dialog">
Expand Down
36 changes: 5 additions & 31 deletions resources/components/prompt/yes_no.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,10 @@
<html>
<head>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
display: flex;
justify-content: center;
align-items: center;
padding: 0;
margin: 0;
background-color: #7d818644;
}
.dialog {
display: flex;
background: #ffffff;
width: 400px;
min-height: 110px;
max-height: 300px;
flex-direction: column;
align-items: center;
border-radius: 10px;
box-shadow: 0 0 50px #ccc;
box-sizing: border-box;
padding: 8px;
gap: 8px;
}
.msg {
display: inline-block;
width: 100%;
min-height: 90px;
text-align: center;
}
</style>
<link
rel="stylesheet"
type="text/css"
href="verso://resources/components/prompt/prompt.css"
/>
</head>
<body>
<div class="dialog">
Expand Down
17 changes: 14 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,26 @@ impl ProtocolHandler for ResourceReader {
let path = current_url.path();
let path = self.0.join(path.strip_prefix('/').unwrap_or(path));

let response = if let Ok(file) = fs::read(path) {
let response = if let Ok(file) = fs::read(path.clone()) {
let mut response = Response::new(
request.current_url(),
ResourceFetchTiming::new(request.timing_type()),
);

// Set Content-Type header.
// TODO: We assume it's HTML for now. This should be updated once we have IPC interface.
response.headers.typed_insert(ContentType::html());
if let Some(ext) = path.extension() {
match ext.to_str() {
Some("css") => response
.headers
.typed_insert(ContentType::from(mime::TEXT_CSS)),
Some("js") => response
.headers
.typed_insert(ContentType::from(mime::TEXT_JAVASCRIPT)),
Some("json") => response.headers.typed_insert(ContentType::json()),
Some("html") => response.headers.typed_insert(ContentType::html()),
_ => response.headers.typed_insert(ContentType::octet_stream()),
}
}

*response.body.lock().unwrap() = ResponseBody::Done(file);

Expand Down

0 comments on commit 6f17f66

Please sign in to comment.