Skip to content

Commit

Permalink
YES!!! BOOOOOOOOOOOOIIIIIIIIIIIIIII
Browse files Browse the repository at this point in the history
  • Loading branch information
Ngo Iok Ui committed Jan 29, 2021
1 parent 7f33214 commit 722e121
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ winapi = { version = "0.3", features = ["combaseapi", "libloaderapi", "minwindef
windows = "0.2.1"

[target.'cfg(target_os = "windows")'.build-dependencies]
cc = "1"
windows = "0.2.1"

[target.'cfg(target_os = "macos")'.dependencies]
Expand Down
16 changes: 13 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ fn main() {
let target = std::env::var("TARGET").unwrap();
if target.contains("-windows") {
windows::build!(
windows::foundation::*
windows::web::ui::*
windows::web::ui::interop::*
windows::foundation::collections::*
windows::foundation::{AsyncStatus, Rect, Uri}
windows::web::ui::interop::{WebViewControl, WebViewControlProcess, }
);

let mut build = cc::Build::new();
build
.include("src/collections.h")
.file("src/collections.cpp")
.flag_if_supported("/std:c++17");

println!("cargo:rerun-if-changed=src/collections.h");
println!("cargo:rerun-if-changed=src/collections.cpp");
build.compile("collections");
} else if target.contains("-apple") {
println!("cargo:rustc-link-lib=framework=WebKit");
}
Expand Down
10 changes: 10 additions & 0 deletions src/collections.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "collections.h"

#define WIN32_LEAN_AND_MEAN
#include <winrt/Windows.Foundation.Collections.h>
using namespace winrt;
void* ivector(const char* js) {
auto x = winrt::single_threaded_vector<hstring>({ winrt::to_hstring(js) });

return reinterpret_cast<void*>(winrt::detach_abi(x));
}
12 changes: 12 additions & 0 deletions src/collections.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef COLLECTIONS_H
#define COLLECTIONS_H
#ifdef __cplusplus
extern "C" {
#endif

void* ivector(const char* js);

#ifdef __cplusplus
}
#endif
#endif //COLLECTIONS_H
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ mod sys;
pub use crate::sys::*;

use std::fmt;
use std::ffi::c_void;
use std::os::raw::c_char;

#[cfg(target_os = "windows")]
extern {
fn ivector(js: *const c_char) -> *mut c_void;
}

#[derive(Debug)]
pub enum Error {
Expand Down
10 changes: 7 additions & 3 deletions src/sys/win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ mod bindings {
::windows::include_bindings!();
}

use bindings::windows::foundation::*;
use bindings::windows::foundation::collections::*;
use bindings::windows::foundation::*;
use bindings::windows::web::ui::interop::*;
use bindings::windows::web::ui::*;
use windows::HString;
use windows::{HString, Abi};

static CALLBACKS: Lazy<Mutex<HashMap<String, Box<dyn FnMut(i8, Vec<String>) -> i32 + Sync + Send>>>> = Lazy::new(|| {
let m = HashMap::new();
Expand Down Expand Up @@ -123,6 +122,11 @@ impl InnerWindow {
))?;
*/
// TODO NavigateToString/url as parameter
let h = CString::new("window.x = 42").unwrap();
let x = unsafe { crate::ivector(h.as_ptr()) };
let x: IVector<HString> = unsafe { IVector::from_abi(x).unwrap() };
dbg!(&x.get_at(0));
webview.invoke_script_async("eval", x)?;
webview.navigate(Uri::create_uri("https://google.com")?)?;

let w = InnerWindow {
Expand Down

0 comments on commit 722e121

Please sign in to comment.