diff --git a/Cargo.lock b/Cargo.lock index bb1dc81..6fdbd2b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -572,6 +572,27 @@ dependencies = [ "webxr-api", ] +[[package]] +name = "cargo-packager-resource-resolver" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13797f4d2ac4fb5a3b5b39380c0338c3a39de0d6ff7eb832129346f6ce7c9750" +dependencies = [ + "cargo-packager-utils", + "heck", + "log", + "thiserror", +] + +[[package]] +name = "cargo-packager-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d435b1a5799cfee502f151f857a0b415a04d3834562d83fea2bb8c6e33bfc167" +dependencies = [ + "ctor", +] + [[package]] name = "cc" version = "1.0.90" @@ -1046,6 +1067,16 @@ dependencies = [ "quote", ] +[[package]] +name = "ctor" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad291aa74992b9b7a7e88c38acbbf6ad7e107f1d90ee8775b7bc1fc3394f485c" +dependencies = [ + "quote", + "syn 2.0.52", +] + [[package]] name = "cursor-icon" version = "1.1.0" @@ -2000,6 +2031,12 @@ dependencies = [ "http", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.3.9" @@ -5517,6 +5554,7 @@ name = "verso" version = "0.0.1" dependencies = [ "block", + "cargo-packager-resource-resolver", "cfg_aliases", "cocoa 0.25.0", "core-graphics 0.23.1", diff --git a/Cargo.toml b/Cargo.toml index 3902a37..242bd68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = [] @@ -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" diff --git a/resources/icons/icon.ico b/resources/icons/icon.ico new file mode 100644 index 0000000..c340dfb Binary files /dev/null and b/resources/icons/icon.ico differ diff --git a/resources/icons/icon256x256.png b/resources/icons/icon256x256.png new file mode 100644 index 0000000..d1df8c6 Binary files /dev/null and b/resources/icons/icon256x256.png differ diff --git a/src/app.rs b/src/app.rs index 077abd8..8dc4499 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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 { @@ -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 diff --git a/src/main.rs b/src/main.rs index 8dcea95..1539378 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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")] diff --git a/src/resources.rs b/src/resources.rs index 29f2629..d1b56ee 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -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()))); @@ -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(); diff --git a/tests/general.rs b/tests/general.rs index 647fa15..ef0c744 100644 --- a/tests/general.rs +++ b/tests/general.rs @@ -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<()>) {}