diff --git a/CHANGELOG.md b/CHANGELOG.md index 8886c7b..f1668ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,8 @@ All notable changes to this project will be documented in this file. -The format is based on [Keep a Changelog], -and this project adheres to [Semantic Versioning]. +The format is based on [Keep a Changelog], and this project adheres to +[Semantic Versioning]. ## [0.5.6] - 2021-02-03 diff --git a/Cargo.lock b/Cargo.lock index 388d002..5e1ef90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,22 +1,12 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "anyhow" -version = "1.0.38" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" - -[[package]] -name = "atk-sys" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f530e4af131d94cc4fa15c5c9d0348f0ef28bac64ba660b6b2a1cf2605dedfce" -dependencies = [ - "glib-sys", - "gobject-sys", - "libc", - "system-deps", -] +checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b" [[package]] name = "autocfg" @@ -30,22 +20,6 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -[[package]] -name = "cairo-sys-rs" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ed2639b9ad5f1d6efa76de95558e11339e7318426d84ac4890b86c03e828ca7" -dependencies = [ - "libc", - "system-deps", -] - -[[package]] -name = "cargo_gn" -version = "0.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ba7d7f7b201dfcbc314b14f2176c92f8ba521dab538b40e426ffed25ed7cd80" - [[package]] name = "cc" version = "1.0.58" @@ -60,9 +34,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "deno_core" -version = "0.77.1" +version = "0.87.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ea6b5f04b9336050413741233eef45f01379ae7ac2ca88ff2ee1bb21081a131" +checksum = "8ce58831bbc265e1ec6fb35f196299e390c138b4085827ad4649b0cf5c5550fe" dependencies = [ "anyhow", "futures", @@ -74,19 +48,15 @@ dependencies = [ "rusty_v8", "serde", "serde_json", - "smallvec", + "serde_v8", "url", ] [[package]] -name = "deno_json_op" -version = "0.1.1" +name = "either" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f1e1d5bba7a8fb46d573a8ac66de5ed0f30ea19801c42c1b1905712b0997537" -dependencies = [ - "quote", - "syn", -] +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "form_urlencoded" @@ -110,9 +80,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.12" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9052a1a50244d8d5aa9bf55cbc2fb6f357c86cc52e46c62ed390a7180cf150" +checksum = "0e7e43a803dae2fa37c1f6a8fe121e1f7bf9548b4dfc0522a42f34145dadfc27" dependencies = [ "futures-channel", "futures-core", @@ -125,9 +95,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.12" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2d31b7ec7efab6eefc7c57233bb10b847986139d88cc2f5a02a1ae6871a1846" +checksum = "e682a68b29a882df0545c143dc3646daefe80ba479bcdede94d5a703de2871e2" dependencies = [ "futures-core", "futures-sink", @@ -135,15 +105,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.12" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79e5145dde8da7d1b3892dad07a9c98fc04bc39892b1ecc9692cf53e2b780a65" +checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1" [[package]] name = "futures-executor" -version = "0.3.12" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9e59fdc009a4b3096bf94f740a0f2424c082521f20a9b08c5c07c48d90fd9b9" +checksum = "badaa6a909fac9e7236d0620a2f57f7664640c56575b71a7552fbd68deafab79" dependencies = [ "futures-core", "futures-task", @@ -152,16 +122,17 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.12" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28be053525281ad8259d47e4de5de657b25e7bac113458555bb4b70bc6870500" +checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1" [[package]] name = "futures-macro" -version = "0.3.12" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c287d25add322d9f9abdcdc5927ca398917996600182178774032e9f8258fedd" +checksum = "a4c40298486cdf52cc00cd6d6987892ba502c7656a16a4192a9992b1ccedd121" dependencies = [ + "autocfg", "proc-macro-hack", "proc-macro2", "quote", @@ -170,25 +141,23 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.12" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caf5c69029bda2e743fddd0582d1083951d65cc9539aebf8812f36c3491342d6" +checksum = "a57bead0ceff0d6dde8f465ecd96c9338121bb7717d3e7b108059531870c4282" [[package]] name = "futures-task" -version = "0.3.12" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13de07eb8ea81ae445aca7b69f5f7bf15d7bf4912d8ca37d6645c77ae8a58d86" -dependencies = [ - "once_cell", -] +checksum = "8a16bef9fc1a4dddb5bee51c989e3fbba26569cbb0e31f5b303c184e3dd33dae" [[package]] name = "futures-util" -version = "0.3.12" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "632a8cd0f2a4b3fdea1657f08bde063848c3bd00f9bbf6e256b8be78802e624b" +checksum = "feb5c238d27e2bf94ffdfd27b2c29e3df4a68c4193bb6427384259e2bf191967" dependencies = [ + "autocfg", "futures-channel", "futures-core", "futures-io", @@ -203,103 +172,12 @@ dependencies = [ "slab", ] -[[package]] -name = "gdk-pixbuf-sys" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bfe468a7f43e97b8d193a762b6c5cf67a7d36cacbc0b9291dbcae24bfea1e8f" -dependencies = [ - "gio-sys", - "glib-sys", - "gobject-sys", - "libc", - "system-deps", -] - -[[package]] -name = "gdk-sys" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a9653cfc500fd268015b1ac055ddbc3df7a5c9ea3f4ccef147b3957bd140d69" -dependencies = [ - "cairo-sys-rs", - "gdk-pixbuf-sys", - "gio-sys", - "glib-sys", - "gobject-sys", - "libc", - "pango-sys", - "pkg-config", - "system-deps", -] - -[[package]] -name = "gio-sys" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e24fb752f8f5d2cf6bbc2c606fd2bc989c81c5e2fe321ab974d54f8b6344eac" -dependencies = [ - "glib-sys", - "gobject-sys", - "libc", - "system-deps", - "winapi", -] - -[[package]] -name = "glib-sys" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7e9b997a66e9a23d073f2b1abb4dbfc3925e0b8952f67efd8d9b6e168e4cdc1" -dependencies = [ - "libc", - "system-deps", -] - -[[package]] -name = "gobject-sys" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "952133b60c318a62bf82ee75b93acc7e84028a093e06b9e27981c2b6fe68218c" -dependencies = [ - "glib-sys", - "libc", - "system-deps", -] - -[[package]] -name = "gtk-sys" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89acda6f084863307d948ba64a4b1ef674e8527dddab147ee4cdcc194c880457" -dependencies = [ - "atk-sys", - "cairo-sys-rs", - "gdk-pixbuf-sys", - "gdk-sys", - "gio-sys", - "glib-sys", - "gobject-sys", - "libc", - "pango-sys", - "system-deps", -] - [[package]] name = "hashbrown" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" -[[package]] -name = "heck" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "idna" version = "0.2.0" @@ -313,9 +191,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.6.1" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" dependencies = [ "autocfg", "hashbrown", @@ -327,15 +205,6 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" -[[package]] -name = "javascriptcore-rs-sys" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f46ada8a08dcd75a10afae872fbfb51275df4a8ae0d46b8cc7c708f08dd2998" -dependencies = [ - "libc", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -344,9 +213,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.85" +version = "0.2.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ccac4b00700875e6a07c6cde370d44d32fa01c5a65cdd2fca6858c479d28bb3" +checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" [[package]] name = "log" @@ -369,24 +238,6 @@ version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" -[[package]] -name = "once_cell" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" - -[[package]] -name = "pango-sys" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d2650c8b62d116c020abd0cea26a4ed96526afda89b1c4ea567131fdefc890" -dependencies = [ - "glib-sys", - "gobject-sys", - "libc", - "system-deps", -] - [[package]] name = "percent-encoding" version = "2.1.0" @@ -395,18 +246,18 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pin-project" -version = "1.0.5" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96fa8ebb90271c4477f144354485b8068bd8f6b78b428b01ba892ca26caf0b63" +checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.0.5" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "758669ae3558c6f74bd2a18b41f7ac0b5a195aea6639d6a9b5e5d1ad5ba24c0b" +checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f" dependencies = [ "proc-macro2", "quote", @@ -463,12 +314,11 @@ dependencies = [ [[package]] name = "rusty_v8" -version = "0.16.0" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a50f63f3030b5a676b9f6e7d53bf1f880904973c2350a3f034dbf82facca0b4f" +checksum = "bda4f5a0179977a62af1a34eb5092e0a75069e9744709ed11617d6562778e6e9" dependencies = [ "bitflags", - "cargo_gn", "fslock", "lazy_static", "libc", @@ -483,18 +333,18 @@ checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "serde" -version = "1.0.123" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" +checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.123" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31" +checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" dependencies = [ "proc-macro2", "quote", @@ -503,9 +353,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.61" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fceb2595057b6891a4ee808f70054bd2d12f0e97f1cbb78689b59f676df325a" +checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" dependencies = [ "indexmap", "itoa", @@ -514,49 +364,20 @@ dependencies = [ ] [[package]] -name = "slab" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" - -[[package]] -name = "smallvec" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" - -[[package]] -name = "soup-sys" -version = "0.10.0" +name = "serde_v8" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c7adf08565630bbb71f955f11f8a68464817ded2703a3549747c235b58a13e" +checksum = "24ea79d2b7783a267f4c5aeb3d751f9280c26ee72a99f29e879249dfed12a756" dependencies = [ - "bitflags", - "gio-sys", - "glib-sys", - "gobject-sys", - "libc", - "pkg-config", - "system-deps", + "rusty_v8", + "serde", ] [[package]] -name = "strum" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57bd81eb48f4c437cadc685403cad539345bf703d78e63707418431cecd4522b" - -[[package]] -name = "strum_macros" -version = "0.18.0" +name = "slab" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87c85aa3f8ea653bfd3ddf25f7ee357ee4d204731f6aa9ad04002306f6e2774c" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] +checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "syn" @@ -569,56 +390,12 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "system-deps" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3ecc17269a19353b3558b313bba738b25d82993e30d62a18406a24aba4649b" -dependencies = [ - "heck", - "pkg-config", - "strum", - "strum_macros", - "thiserror", - "toml", - "version-compare", -] - -[[package]] -name = "thiserror" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tinyvec" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53953d2d3a5ad81d9f844a32f14ebb121f50b650cd59d0ee2a07cf13c617efed" -[[package]] -name = "toml" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75cf45bb0bef80604d001caaec0d09da99611b3c0fd39d3080468875cdb65645" -dependencies = [ - "serde", -] - [[package]] name = "unicode-bidi" version = "0.3.4" @@ -637,12 +414,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" - [[package]] name = "unicode-xid" version = "0.2.1" @@ -651,9 +422,9 @@ checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "url" -version = "2.2.0" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5909f2b0817350449ed73e8bcd81c8c3c8d9a7a5d8acba4b27db277f1868976e" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" dependencies = [ "form_urlencoded", "idna", @@ -663,67 +434,41 @@ dependencies = [ ] [[package]] -name = "version-compare" -version = "0.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d63556a25bae6ea31b52e640d7c41d1ab27faba4ccb600013837a3d0b3994ca1" - -[[package]] -name = "webkit2gtk-sys" -version = "0.12.0" +name = "webview-official-sys" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "389e5138c85a0d111b9bda05b59efa8562315e1d657d72451410e12c858f0619" +checksum = "c4aec5fdf5bc938ba5fe47d23b8e02d6beaee395a91e16f0b2eec984a9a9e1d2" dependencies = [ - "atk-sys", - "bitflags", - "cairo-sys-rs", - "gdk-pixbuf-sys", - "gdk-sys", - "gio-sys", - "glib-sys", - "gobject-sys", - "gtk-sys", - "javascriptcore-rs-sys", - "libc", - "pango-sys", + "cc", "pkg-config", - "soup-sys", ] [[package]] -name = "webview-sys" -version = "0.6.1" -source = "git+https://github.com/Boscop/web-view?rev=1c20b92#1c20b9256aa786163fe4eed291f517eb5d3f02d5" +name = "webview_deno" +version = "0.6.0-pre.0" dependencies = [ - "cc", - "gdk-sys", - "gio-sys", - "glib-sys", - "gobject-sys", - "gtk-sys", - "javascriptcore-rs-sys", - "libc", - "pkg-config", - "webkit2gtk-sys", + "deno_core", + "serde", + "webview_official", ] [[package]] -name = "webview_deno" -version = "0.5.6" +name = "webview_official" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b38277d3fa288b13db39eeb153f9b8ee3d8e3181648ade05264c1ba99e774999" dependencies = [ - "deno_core", - "deno_json_op", - "webview-sys", + "webview-official-sys", ] [[package]] name = "which" -version = "4.0.2" +version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87c14ef7e1b8b8ecfc75d5eca37949410046e66f15d185c01d70824f1f8111ef" +checksum = "b55551e42cbdf2ce2bedd2203d0cc08dba002c27510f86dab6d0ce304cba3dfe" dependencies = [ + "either", "libc", - "thiserror", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index b9d66a7..75e5a25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "webview_deno" -version = "0.5.6" +version = "0.6.0-pre.0" authors = ["Elias Sjögreen", "Filippo Rossi"] edition = "2018" @@ -8,9 +8,6 @@ edition = "2018" crate-type = ["cdylib"] [dependencies] -deno_core = "0.77.1" -deno_json_op = "0.1.1" -webview-sys = { git = "https://github.com/Boscop/web-view", rev = "1c20b92" } - -[features] -default = ["webview-sys/edge"] +deno_core = "0.87.0" +webview_official = "0.2.0" +serde = "1.0.125" diff --git a/README.md b/README.md index 11d0693..17beef4 100644 --- a/README.md +++ b/README.md @@ -112,10 +112,10 @@ deno run --unstable -A scripts/dev.ts examples/local.ts ## Environment variables -- `PLUGIN_URL` - The URL of the plugin - Due to MSHTML (internet explorer) no longer being enabled by default, the only - way to enable it is to set the `PLUGIN_URL` variable to the path of a binary - build built with the `--no-default-features` flag or using +- `PLUGIN_URL` - The URL of the plugin Due to MSHTML (internet explorer) no + longer being enabled by default, the only way to enable it is to set the + `PLUGIN_URL` variable to the path of a binary build built with the + `--no-default-features` flag or using `deno --unstable -A scripts/build.ts mshtml`. This is usually `./target/release/` when developing locally. - `DEBUG` - Disable cache and enable logs for `plug`. Used for debugging. diff --git a/deps.ts b/deps.ts index 25535f9..ce61225 100644 --- a/deps.ts +++ b/deps.ts @@ -1,2 +1,2 @@ -export { delay } from "https://deno.land/std@0.85.0/async/mod.ts"; -export { Plug } from "https://deno.land/x/plug@0.2.9/mod.ts"; +export { delay } from "https://deno.land/std@0.96.0/async/mod.ts"; +export { Plug } from "https://deno.land/x/plug@0.3.0/mod.ts"; diff --git a/mod.ts b/mod.ts index e2c13da..755f952 100644 --- a/mod.ts +++ b/mod.ts @@ -1,9 +1,2 @@ +import "./plugin.ts"; export * from "./webview.ts"; - -import { load, unload } from "./plugin.ts"; - -await load(); - -// deno-lint-ignore ban-ts-comment -// @ts-ignore -if (typeof window !== "undefined") window.addEventListener("unload", unload); diff --git a/plugin.ts b/plugin.ts index a628ff1..5a020de 100644 --- a/plugin.ts +++ b/plugin.ts @@ -1,88 +1,14 @@ import { Plug } from "./deps.ts"; -const VERSION = "0.5.6"; +const VERSION = "0.6.0-pre.0"; +const POLICY = Deno.env.get("PLUGIN_URL") === undefined + ? Plug.CachePolicy.STORE + : Plug.CachePolicy.NONE; const PLUGIN_URL = Deno.env.get("PLUGIN_URL") ?? `https://github.com/webview/webview_deno/releases/download/${VERSION}/`; -const DEBUG = Boolean(Deno.env.get("DEBUG")); -const encoder = new TextEncoder(); -const decoder = new TextDecoder(); - -let rid: number | undefined; - -function deserialize(text: string): unknown { - return JSON.parse( - text.replace(/([^\"]+\"\:\s*)(\d{16,})/g, '$1"$2n"'), - (_, v) => { - if (typeof v === "string" && /^\d{16,}n$/.test(v)) { - v = BigInt(v.slice(0, -1)); - } - - return v; - }, - ); -} - -function serialize(value: unknown, space?: number): string { - return JSON.stringify(value, (_, v) => { - if (typeof v === "bigint") { - v = v.toString() + "n"; - } - return v; - }, space).replace(/(?:\")(\d{16,})(?:n\")/g, "$1"); -} - -function decode(data: Uint8Array): unknown { - const text = decoder.decode(data); - return deserialize(text); -} - -function encode(data: unknown): Uint8Array { - const text = serialize(data); - return encoder.encode(text); -} - -export type Result = { err: string } | { ok: T }; - -export function sync(op: string, data: unknown = {}): T { - if (rid === undefined) { - throw "The plugin must be initialized before use"; - } - - const opId = Plug.getOpId(op); - const response = Plug.core.dispatch(opId, encode(data))!; - - return decode(response) as T; -} - -export function unwrap(result: Result): T { - if ("err" in result) { - throw (result as { err: string }).err; - } - - if ("ok" in result) { - return (result as { ok: T }).ok; - } - - throw `Invalid result (${JSON.stringify(result)})`; -} - -/** - * Loads the plugin - */ -export async function load(cache = !DEBUG) { - unload(); - rid = await Plug.prepare({ - name: "webview_deno", - url: PLUGIN_URL, - policy: cache ? Plug.CachePolicy.STORE : Plug.CachePolicy.NONE, - }); -} - -/** - * Frees the plugin - */ -export function unload() { - if (rid !== undefined) Deno.close(rid); - rid = undefined; -} +await Plug.prepare({ + name: "webview_deno", + url: PLUGIN_URL, + policy: POLICY, +}); diff --git a/src/lib.rs b/src/lib.rs index 04bcb95..4c2e62c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,357 +1,272 @@ +use std::borrow::Cow; use std::cell::RefCell; -use std::collections::HashMap; -use std::ffi::CStr; -use std::ffi::CString; -use std::os::raw::c_char; -use std::os::raw::c_int; -use std::os::raw::c_void; +use std::rc::Rc; use deno_core::error::anyhow; +use deno_core::error::bad_resource_id; use deno_core::error::AnyError; - -use deno_core::plugin_api::Interface; -use deno_core::plugin_api::Op; -use deno_core::plugin_api::ZeroCopyBuf; - -use deno_core::serde_json::json; -use deno_core::serde_json::Value; - -use deno_json_op::json_op; - -use webview_sys::CWebView; - -thread_local! { - static INDEX: RefCell = RefCell::new(0); - static WEBVIEW_MAP: RefCell> = RefCell::new(HashMap::new()); - static STACK_MAP: RefCell>> = RefCell::new(HashMap::new()); +use deno_core::futures::channel::mpsc::channel; +use deno_core::futures::channel::mpsc::Receiver; +use deno_core::futures::channel::mpsc::Sender; +use deno_core::futures::StreamExt; +use deno_core::op_async; +use deno_core::op_sync; +use deno_core::serde::Deserialize; +use deno_core::Extension; +use deno_core::OpState; +use deno_core::Resource; +use deno_core::ResourceId; +use deno_core::ZeroCopyBuf; + +use webview_official::SizeHint; +use webview_official::Webview; +use webview_official::Window; + +type WebviewEvent = (String, String); + +struct WebviewResource { + inner: RefCell, + events_rx: RefCell>, + events_tx: RefCell>, } -#[no_mangle] -pub fn deno_plugin_init(interface: &mut dyn Interface) { - interface.register_op("webview_free", webview_free); - interface.register_op("webview_new", webview_new); - interface.register_op("webview_exit", webview_exit); - interface.register_op("webview_eval", webview_eval); - interface.register_op("webview_loop", webview_loop); - interface.register_op("webview_step", webview_step); - interface.register_op("webview_set_color", webview_set_color); - interface.register_op("webview_set_fullscreen", webview_set_fullscreen); - interface.register_op("webview_set_maximized", webview_set_maximized); - interface.register_op("webview_set_minimized", webview_set_minimized); - interface.register_op("webview_set_title", webview_set_title); - interface.register_op("webview_set_visible", webview_set_visible); +impl WebviewResource { + fn new(debug: bool, window: Option<&mut Window>) -> Self { + let (tx, rx) = channel::<(String, String)>(256); + WebviewResource { + inner: RefCell::new(Webview::create(debug, window)), + events_rx: RefCell::new(rx), + events_tx: RefCell::new(tx), + } + } + + fn bind(&self, name: &str) { + let mut webview = self.inner.borrow_mut(); + + webview.bind(name, |seq, req| { + println!("{} {}", seq, req); + let _ = self + .events_tx + .borrow_mut() + .try_send((seq.to_string(), req.to_string())); + }) + } + + async fn next(&self) -> Option { + self.events_rx.borrow_mut().next().await + } } -#[json_op] -fn webview_free( - json: Value, - _zero_copy: &mut [ZeroCopyBuf], -) -> Result { - let id = json["id"].as_u64().unwrap(); +impl Resource for WebviewResource { + fn name(&self) -> Cow { + "webview".into() + } +} - WEBVIEW_MAP.with(|cell| { - let webview_map = cell.borrow(); +#[derive(Deserialize)] +struct StringArgs(ResourceId, String); - if let Some(webview) = webview_map.get(&id) { - unsafe { - webview_sys::webview_free(*webview); - } +#[derive(Deserialize)] +struct SizeArgs { + rid: ResourceId, + width: i32, + height: i32, + size: i32, +} - Ok(json!(())) - } else { - Err(anyhow!("Could not find webview with id: {}", id)) - } - }) +#[derive(Deserialize)] +struct ReturnArgs { + rid: ResourceId, + seq: String, + status: i32, + result: String, } -#[json_op] -fn webview_new( - json: Value, - _zero_copy: &mut [ZeroCopyBuf], -) -> Result { - let title = CString::new(json["title"].as_str().unwrap()).unwrap(); - let url = CString::new(json["url"].as_str().unwrap()).unwrap(); - let width = json["width"].as_i64().unwrap() as c_int; - let height = json["height"].as_i64().unwrap() as c_int; - let min_width = json["minWidth"].as_i64().unwrap() as c_int; - let min_height = json["minHeight"].as_i64().unwrap() as c_int; - let resizable = json["resizable"].as_bool().unwrap() as c_int; - let debug = json["debug"].as_bool().unwrap() as c_int; - let frameless = json["frameless"].as_bool().unwrap() as c_int; - let visible = json["visible"].as_bool().unwrap() as c_int; - - let mut id = 0; - INDEX.with(|cell| { - id = cell.replace_with(|&mut i| i + 1); - }); - - WEBVIEW_MAP.with(|cell| { - cell.borrow_mut().insert(id, unsafe { - webview_sys::webview_new( - title.as_ptr(), - url.as_ptr(), - width, - height, - resizable, - debug, - frameless, - visible, - min_width, - min_height, - Some(ffi_invoke_handler), - id as *mut c_void, - ) - }); - }); - - STACK_MAP.with(|cell| { - cell.borrow_mut().insert(id, Vec::new()); - }); - - Ok(json!(id)) +#[no_mangle] +pub fn init() -> Extension { + Extension::builder() + .ops(vec![ + ("webview_create", op_sync(webview_create)), + ("webview_run", op_sync(webview_run)), + ("webview_terminate", op_sync(webview_terminate)), + ("webview_set_title", op_sync(webview_set_title)), + ("webview_set_size", op_sync(webview_set_size)), + ("webview_navigate", op_sync(webview_navigate)), + ("webview_init", op_sync(webview_init)), + ("webview_eval", op_sync(webview_eval)), + ("webview_bind", op_sync(webview_bind)), + ("webview_return", op_sync(webview_return)), + ("webview_poll_next", op_async(webview_poll_next)), + ]) + .build() } -extern "C" fn ffi_invoke_handler(webview: *mut CWebView, arg: *const c_char) { - let arg = unsafe { CStr::from_ptr(arg).to_string_lossy().to_string() }; - let id = unsafe { webview_sys::webview_get_user_data(webview) as u64 }; - // println!("{}", id); +fn webview_create( + state: &mut OpState, + debug: bool, + _zero_copy: Option, +) -> Result { + Ok(state.resource_table.add(WebviewResource::new(debug, None))) +} - STACK_MAP.with(|cell| { - let mut stack_map = cell.borrow_mut(); +fn webview_run( + state: &mut OpState, + rid: ResourceId, + _zero_copy: Option, +) -> Result<(), AnyError> { + let webview = state + .resource_table + .get::(rid) + .ok_or_else(bad_resource_id)?; - // println!("{:?}", stack_map); + webview.inner.borrow_mut().run(); - if let Some(stack) = stack_map.get_mut(&id) { - stack.push(arg); - } else { - panic!( - "Could not find stack with id {} to push '{}' onto stack", - id, arg - ); - } - }); + Ok(()) } -#[json_op] -fn webview_loop( - json: Value, - _zero_copy: &mut [ZeroCopyBuf], -) -> Result { - let id = json["id"].as_u64().unwrap(); - let block = json["block"].as_bool().unwrap() as c_int; - - WEBVIEW_MAP.with(|cell| { - let webview_map = cell.borrow(); +fn webview_terminate( + state: &mut OpState, + rid: ResourceId, + _zero_copy: Option, +) -> Result<(), AnyError> { + let webview = state + .resource_table + .get::(rid) + .ok_or_else(bad_resource_id)?; - if let Some(webview) = webview_map.get(&id) { - let res = unsafe { webview_sys::webview_loop(*webview, block) }; + webview.inner.borrow_mut().terminate(); - Ok(json!(res)) - } else { - Err(anyhow!("Could not find webview with id: {}", id)) - } - }) + Ok(()) } -#[json_op] -fn webview_step( - json: Value, - _zero_copy: &mut [ZeroCopyBuf], -) -> Result { - let id = json["id"].as_u64().unwrap(); - - STACK_MAP.with(|cell| { - let mut stack_map = cell.borrow_mut(); - if let Some(stack) = stack_map.get_mut(&id) { - let ret = stack.clone(); - stack.clear(); - Ok(json!(ret)) - } else { - Err(anyhow!("Could not find stack with id: {}", id)) - } - }) +fn webview_set_title( + state: &mut OpState, + args: StringArgs, + _zero_copy: Option, +) -> Result<(), AnyError> { + let webview = state + .resource_table + .get::(args.0) + .ok_or_else(bad_resource_id)?; + + webview.inner.borrow_mut().set_title(&args.1); + + Ok(()) } -#[json_op] -fn webview_exit( - json: Value, - _zero_copy: &mut [ZeroCopyBuf], -) -> Result { - let id = json["id"].as_u64().unwrap(); +fn webview_set_size( + state: &mut OpState, + args: SizeArgs, + _zero_copy: Option, +) -> Result<(), AnyError> { + let webview = state + .resource_table + .get::(args.rid) + .ok_or_else(bad_resource_id)?; + + webview.inner.borrow_mut().set_size( + args.width, + args.height, + match args.size { + 0 => SizeHint::NONE, + 1 => SizeHint::MIN, + 2 => SizeHint::MAX, + 3 => SizeHint::FIXED, + _ => return Err(anyhow!("Size hint needs to be in range 0..3")), + }, + ); + + Ok(()) +} - WEBVIEW_MAP.with(|cell| { - let webview_map = cell.borrow(); +fn webview_navigate( + state: &mut OpState, + args: StringArgs, + _zero_copy: Option, +) -> Result<(), AnyError> { + let webview = state + .resource_table + .get::(args.0) + .ok_or_else(bad_resource_id)?; - if let Some(webview) = webview_map.get(&id) { - unsafe { - webview_sys::webview_exit(*webview); - } + webview.inner.borrow_mut().navigate(&args.1); - Ok(json!(())) - } else { - Err(anyhow!("Could not find webview with id: {}", id)) - } - }) + Ok(()) } -#[json_op] -fn webview_eval( - json: Value, - _zero_copy: &mut [ZeroCopyBuf], -) -> Result { - let id = json["id"].as_u64().unwrap(); - let js = CString::new(json["js"].as_str().unwrap()).unwrap(); - - WEBVIEW_MAP.with(|cell| { - let webview_map = cell.borrow(); +fn webview_init( + state: &mut OpState, + args: StringArgs, + _zero_copy: Option, +) -> Result<(), AnyError> { + let webview = state + .resource_table + .get::(args.0) + .ok_or_else(bad_resource_id)?; - if let Some(webview) = webview_map.get(&id) { - let res = unsafe { webview_sys::webview_eval(*webview, js.as_ptr()) }; + webview.inner.borrow_mut().init(&args.1); - Ok(json!(res)) - } else { - Err(anyhow!("Could not find webview with id: {}", id)) - } - }) + Ok(()) } -#[json_op] -fn webview_set_title( - json: Value, - _zero_copy: &mut [ZeroCopyBuf], -) -> Result { - let id = json["id"].as_u64().unwrap(); - let title = CString::new(json["title"].as_str().unwrap()).unwrap(); - - WEBVIEW_MAP.with(|cell| { - let webview_map = cell.borrow(); - - if let Some(webview) = webview_map.get(&id) { - unsafe { - webview_sys::webview_set_title(*webview, title.as_ptr()); - } - - Ok(json!(())) - } else { - Err(anyhow!("Could not find webview with id: {}", id)) - } - }) +fn webview_eval( + state: &mut OpState, + args: StringArgs, + _zero_copy: Option, +) -> Result<(), AnyError> { + let webview = state + .resource_table + .get::(args.0) + .ok_or_else(bad_resource_id)?; + + webview.inner.borrow_mut().eval(&args.1); + + Ok(()) } -#[json_op] -fn webview_set_fullscreen( - json: Value, - _zero_copy: &mut [ZeroCopyBuf], -) -> Result { - let id = json["id"].as_u64().unwrap(); - let fullscreen = json["fullscreen"].as_bool().unwrap() as c_int; - - WEBVIEW_MAP.with(|cell| { - let webview_map = cell.borrow(); - - if let Some(webview) = webview_map.get(&id) { - unsafe { - webview_sys::webview_set_fullscreen(*webview, fullscreen); - } - - Ok(json!(())) - } else { - Err(anyhow!("Could not find webview with id: {}", id)) - } - }) -} +fn webview_bind( + state: &mut OpState, + args: StringArgs, + _zero_copy: Option, +) -> Result<(), AnyError> { + let webview = state + .resource_table + .get::(args.0) + .ok_or_else(bad_resource_id)?; -#[json_op] -fn webview_set_maximized( - json: Value, - _zero_copy: &mut [ZeroCopyBuf], -) -> Result { - let id = json["id"].as_u64().unwrap(); - let maximized = json["maximized"].as_bool().unwrap() as c_int; - - WEBVIEW_MAP.with(|cell| { - let webview_map = cell.borrow(); - - if let Some(webview) = webview_map.get(&id) { - unsafe { - webview_sys::webview_set_maximized(*webview, maximized); - } - - Ok(json!(())) - } else { - Err(anyhow!("Could not find webview with id: {}", id)) - } - }) -} + webview.bind(&args.1); -#[json_op] -fn webview_set_minimized( - json: Value, - _zero_copy: &mut [ZeroCopyBuf], -) -> Result { - let id = json["id"].as_u64().unwrap(); - let minimized = json["minimized"].as_bool().unwrap() as c_int; - - WEBVIEW_MAP.with(|cell| { - let webview_map = cell.borrow(); - - if let Some(webview) = webview_map.get(&id) { - unsafe { - webview_sys::webview_set_minimized(*webview, minimized); - } - - Ok(json!(())) - } else { - Err(anyhow!("Could not find webview with id: {}", id)) - } - }) + Ok(()) } -#[json_op] -fn webview_set_visible( - json: Value, - _zero_copy: &mut [ZeroCopyBuf], -) -> Result { - let id = json["id"].as_u64().unwrap(); - let visible = json["visible"].as_bool().unwrap() as c_int; - - WEBVIEW_MAP.with(|cell| { - let webview_map = cell.borrow(); - - if let Some(webview) = webview_map.get(&id) { - unsafe { - webview_sys::webview_set_visible(*webview, visible); - } - - Ok(json!(())) - } else { - Err(anyhow!("Could not find webview with id: {}", id)) - } - }) +fn webview_return( + state: &mut OpState, + args: ReturnArgs, + _zero_copy: Option, +) -> Result<(), AnyError> { + let webview = state + .resource_table + .get::(args.rid) + .ok_or_else(bad_resource_id)?; + + webview + .inner + .borrow_mut() + .r#return(&args.seq, args.status, &args.result); + + Ok(()) } -#[json_op] -fn webview_set_color( - json: Value, - _zero_copy: &mut [ZeroCopyBuf], -) -> Result { - let id = json["id"].as_u64().unwrap(); - let r = json["r"].as_u64().unwrap() as u8; - let g = json["g"].as_u64().unwrap() as u8; - let b = json["b"].as_u64().unwrap() as u8; - let a = json["a"].as_u64().unwrap() as u8; - - WEBVIEW_MAP.with(|cell| { - let webview_map = cell.borrow(); - - if let Some(webview) = webview_map.get(&id) { - unsafe { - webview_sys::webview_set_color(*webview, r, g, b, a); - } - - Ok(json!(())) - } else { - Err(anyhow!("Could not find webview with id: {}", id)) - } - }) +async fn webview_poll_next( + state: Rc>, + rid: ResourceId, + _zero_copy: Option, +) -> Result, AnyError> { + let webview = state + .borrow_mut() + .resource_table + .get::(rid) + .ok_or_else(bad_resource_id)?; + + Ok(webview.next().await) } diff --git a/webview.ts b/webview.ts index f8e36f7..3c66bb8 100644 --- a/webview.ts +++ b/webview.ts @@ -1,213 +1,72 @@ -import { sync, unwrap } from "./plugin.ts"; -import { delay } from "./deps.ts"; +import { Plug } from "./deps.ts"; -function debounce( - func: (...args: T) => Promise, - time: number, -): (...args: T) => Promise { - return async (...args) => { - const promise = func(...args); - const timer = delay(time); - const response = await promise; - await timer; - return response; - }; -} - -export interface WebviewParams { - title: string; - url: string; - width: number; - height: number; - minWidth: number; - minHeight: number; - resizable: boolean; - debug: boolean; - frameless: boolean; - visible: boolean; -} +export type SizeHint = 0 | 1 | 2 | 3; -export interface RGBA { - r: number; - g: number; - b: number; - a: number; -} +export const SizeHint = { + NONE: 0, + MIN: 1, + MAX: 2, + FIXED: 3, +} as const; /** * A Webview instance */ export class Webview { - readonly id: bigint; + readonly rid: number; - /** - * Creates a new Webview instance - */ - constructor({ - title = "webview_deno", - url = "about:blank", - width = 800, - height = 600, - minWidth = 300, - minHeight = 300, - resizable = true, - debug = false, - frameless = false, - visible = true, - }: Partial) { - this.id = unwrap(sync("webview_new", { - title, - url, - width, - height, - minWidth, - minHeight, - resizable, - debug, - frameless, - visible, - })); + constructor(debug = false) { + this.rid = Plug.core.opSync("webview_create", debug); } - /** - * Frees the Webview instance - */ - free() { - unwrap(sync("webview_free", { id: this.id })); + run() { + Plug.core.opSync("webview_run", this.rid); } - /** - * Exits the Webview instance - */ - exit() { - unwrap(sync("webview_exit", { id: this.id })); + terminate() { + Plug.core.opSync("webview_terminate", this.rid); } - /** - * Exits and frees the Webview instance - */ - drop() { - this.exit(); - this.free(); + setTitle(title: string) { + Plug.core.opSync("webview_set_title", [this.rid, title]); } - /** - * Evaluates the provided js in the Webview instance, returns false if unsuccessful - */ - eval(js: string): boolean { - return unwrap(sync("webview_eval", { id: this.id, js })) === 0; + setSize(width: number, height: number, hints: SizeHint) { + Plug.core.opSync("webview_set_title", [this.rid, width, height, hints]); } - /** - * Iterates one step in the event loop, returns false if closed or terminated - */ - loop(block = false): boolean { - return unwrap(sync("webview_loop", { id: this.id, block })) === 0; + navigate(url: string) { + Plug.core.opSync("webview_navigate", [this.rid, url]); } - /** - * Steps one step in the event loop popping all accumulated events from the stack - */ - step(): string[] { - return unwrap(sync("webview_step", { id: this.id })); + init(js: string) { + Plug.core.opSync("webview_init", [this.rid, js]); } - /** - * Iterates over the event loop until closed or terminated without - * handling events - */ - run( - callback?: (events: string) => unknown, - delta = 1000 / 60, - ): Promise { - return new Promise((resolve) => { - const interval = setInterval(() => { - const success = this.loop(); - - if (callback !== undefined) { - const events = this.step(); - - for (const event of events) { - callback(event); - } - } - - if (!success) { - resolve(); - clearInterval(interval); - } - }, delta); - }); + eval(js: string) { + Plug.core.opSync("webview_eval", [this.rid, js]); } - /** - * Iterates over the event loop, yielding external invoke events as strings and - * returning once closed or terminated - */ - async *iter(delta = 1000 / 60): AsyncIterableIterator { - let finished = false; - - const runner = debounce(async () => { - const success = this.loop(); - const events = this.step(); - - if (!success) { - finished = true; - } - - return events; - }, delta); + bind(name: string, callback: (seq: string, req: string) => void) { + Plug.core.opSync("webview_bind", [this.rid, name]); - while (!finished) { - const events = await runner(); + Plug.core.opAsync("webview_poll_next", this.rid).then((value) => { + if (value !== undefined) { + const [seq, req] = value as [string, string]; - for (const event of events) { - yield event; + callback(seq, req); + } else { + throw new Error("Poll value is undefined"); } - } - } - - /** - * Sets the color of the title bar - */ - setColor( - { r, g, b, a = 255 }: RGBA, - ) { - unwrap(sync("webview_set_color", { id: this.id, r, g, b, a })); - } - - /** - * Enables or disables fullscreen - */ - setFullscreen(fullscreen: boolean) { - unwrap(sync("webview_set_fullscreen", { id: this.id, fullscreen })); - } - - /** - * Toggles window maximized - */ - setMaximized(maximized: boolean) { - unwrap(sync("webview_set_maximized", { id: this.id, maximized })); - } - - /** - * Toggles window minimized - */ - setMinimized(minimized: boolean) { - unwrap(sync("webview_set_minimized", { id: this.id, minimized })); - } - - /** - * Sets window title - */ - setTitle(title: string) { - unwrap(sync("webview_set_title", { id: this.id, title })); + }); } - /** - * Sets window visibility - */ - setVisible(visible: boolean) { - unwrap(sync("webview_set_visible", { id: this.id, visible })); + return(seq: string, status: number, result: string) { + Plug.core.opSync("webview_return", { + rid: this.rid, + seq, + status, + result, + }); } }