Skip to content

Commit

Permalink
Add Cargo Packager support
Browse files Browse the repository at this point in the history
  • Loading branch information
naman-crabnebula committed Mar 26, 2024
1 parent d016ec4 commit 54d2c34
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 2 deletions.
38 changes: 38 additions & 0 deletions Cargo.lock

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

17 changes: 17 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ targets = [
"x86_64-apple-darwin",
]

[package.metadata.packager]
name = "verso"
product-name = "verso"
identifier = "com.crabnebula.verso"
version = "0.0.1"
before-each-package-command = "cargo build --release"
resources = [
"resources",
"demo.html"
]
icons=[
"resources/icons/icon256x256.png",
"resources/icons/icon.ico"
]

[features]
default = []

Expand All @@ -37,6 +52,8 @@ crossbeam-channel = "0.5"
getopts = "0.2.17"
surfman = { version = "0.9", features = ["chains", "sm-angle", "sm-angle-default", "sm-x11", "sm-raw-window-handle"] }
winit = { version = "0.29", features = ["rwh_05"] }
# Cargo Packager
cargo-packager-resource-resolver = { version = "0.1", features = ["auto-detect-format"] }

[target."cfg(any(target_os = \"ios\", target_os = \"macos\"))".dependencies]
block = "0.1"
Expand Down
Binary file added resources/icons/icon.ico
Binary file not shown.
Binary file added resources/icons/icon256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ use winit::{

use crate::{prefs, resources, webview::WebView};

#[cfg(not(debug_assertions))]
use cargo_packager_resource_resolver::{current_format, resources_dir};

/// Status of webview.
#[derive(Clone, Copy, Debug, Default)]
pub enum Status {
Expand Down Expand Up @@ -59,6 +62,12 @@ impl Verso {
);

let demo_path = std::env::current_dir().unwrap().join("demo.html");
// For production builds, use Resourse Resolver for demo file
#[cfg(not(debug_assertions))]
let demo_path = resources_dir(current_format().unwrap())
.unwrap()
.join("demo.html");

let url = ServoUrl::from_file_path(demo_path.to_str().unwrap()).unwrap();
init_servo
.servo
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use winit::{dpi::PhysicalSize, event_loop::EventLoop, window::WindowBuilder};
use verso::{Result, Status, Verso};
use winit::{dpi::PhysicalSize, event_loop::EventLoop, window::WindowBuilder};

/* window decoration */
#[cfg(target_os = "macos")]
Expand Down
9 changes: 9 additions & 0 deletions src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use servo::embedder_traits::resources::{self, Resource, ResourceReaderMethods};

struct ResourceReader(PathBuf);

#[cfg(not(debug_assertions))]
use cargo_packager_resource_resolver::{current_format, resources_dir};

/// Initialize resource files. We currently read from `resources` directory only.
pub fn init() {
resources::set(Box::new(ResourceReader(resources_dir_path())));
Expand All @@ -26,6 +29,12 @@ impl ResourceReaderMethods for ResourceReader {
}

fn resources_dir_path() -> PathBuf {
// For production builds, use Resourse Resolver
#[cfg(not(debug_assertions))]
return resources_dir(current_format().unwrap())
.unwrap()
.join("resources");

// Try ./resources relative to the directory containing the
// canonicalised executable path, then each of its ancestors.
let mut path = env::current_exe().unwrap().canonicalize().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion tests/general.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use winit::event_loop::EventLoopWindowTarget;
use verso::verso_test;
use winit::event_loop::EventLoopWindowTarget;

fn smoke(_elwt: &EventLoopWindowTarget<()>) {}
fn other_smoke(_elwt: &EventLoopWindowTarget<()>) {}
Expand Down

0 comments on commit 54d2c34

Please sign in to comment.