Skip to content

Commit

Permalink
Merge pull request #5 from gintama91/dev
Browse files Browse the repository at this point in the history
load with url,cleanup and wip tht eval
  • Loading branch information
gintama91 authored Sep 27, 2023
2 parents aa5623c + c6a0df4 commit 7da6c0a
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rust-analyzer.linkedProjects": [
"./ext/wry_ruby/Cargo.toml"
]
}
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.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ WryRuby is an **EXPERIMENTAL** Ruby project that provides ruby bindings for [Tau
- **`Clipboard`**: Access to the system clipboard with convenience.
- **`Event Loop`**: Create and manage application event loops. *(Currently, only `new` is supported)*.
- **`window_with_html`**: Create new windows with HTML content.
- **`load_with_url`**:loads a URL into the window.


## 📝 Usage

Expand Down
5 changes: 4 additions & 1 deletion examples/new_window.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require_relative "../lib/wry_ruby/wry_ruby"

new_window("Hello Wry", 100, 400, true, 3)
# new_window("Hello Wry", 100, 400, true, 3)

# load_with_url("https://github.com/scarpe-team/scarpe")

4 changes: 3 additions & 1 deletion ext/wry_ruby/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ crate-type = ["cdylib"]
magnus = { version = "0.5.4" }
wry = "0.29.0"
gdk = "0.16.2"
gtk="0.16.2"
gtk="0.16.2"
webkit2gtk = "1.1.0"

11 changes: 6 additions & 5 deletions ext/wry_ruby/src/application/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use magnus::{
};

use std::marker::PhantomData;
use std::sync::atomic::{AtomicPtr};

use wry::application::event_loop::{
EventLoop as EventLoopImpl,
};
use std::sync::atomic::AtomicPtr;

use wry::application::event_loop::EventLoop as EventLoopImpl;


#[magnus::wrap(class = "EventLoop")]
pub struct EventLoop {
Expand All @@ -19,7 +19,8 @@ pub struct SafeWrapper<T> {
_marker: PhantomData<*mut T>,
}

unsafe impl<T> Send for SafeWrapper<T> {}

unsafe impl<T> Send for SafeWrapper<T> {}

impl EventLoop {
pub fn new() -> Self {
Expand Down
1 change: 1 addition & 0 deletions ext/wry_ruby/src/application/tray_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub struct TrayId {
}

impl TrayId {
#[allow(dead_code)]
pub const EMPTY: TrayId = TrayId {
inner: TrayIdImpl::EMPTY,
};
Expand Down
36 changes: 34 additions & 2 deletions ext/wry_ruby/src/application/window.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use magnus::{Error, define_global_function, function, method};
use magnus::{Error, define_global_function, function};

use wry::application::dpi::LogicalSize;
use wry::application::window::WindowBuilder;
use wry::application::{
Expand Down Expand Up @@ -34,7 +35,8 @@ pub fn WindoWnew(title: String, width: u32, height: u32, resizable: bool,timeout
*control_flow = ControlFlow::Wait;

match event {
Event::NewEvents(StartCause::Init) => println!("Wry has started!"),
Event::NewEvents(StartCause::Init) => println!("ok started"),

Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
Expand All @@ -50,6 +52,33 @@ pub fn WindoWnew(title: String, width: u32, height: u32, resizable: bool,timeout
});
}

pub fn load_url(url:String){
let event_loop = EventLoop::new();
let window = WindowBuilder::new()
.with_title("loading with url")
.build(&event_loop)
.unwrap();
let _webview = WebViewBuilder::new(window).unwrap()
.with_url(url.as_str())
.unwrap()
.build()
.unwrap();

event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;

match event {
Event::NewEvents(StartCause::Init) => println!("ok"),
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => *control_flow = ControlFlow::Exit,
_ => (),
}
});

}

pub fn window_with_html(html:String){
let event_loop = EventLoop::new();
let window = WindowBuilder::new()
Expand All @@ -67,6 +96,7 @@ pub fn window_with_html(html:String){

match event {
Event::NewEvents(StartCause::Init) => println!("Wry has started!"),

Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
Expand All @@ -79,6 +109,8 @@ pub fn window_with_html(html:String){
pub fn init() -> Result<(), Error> {
println!("inside init");
define_global_function("new_window", function!(WindoWnew, 5));
define_global_function("load_with_url", function!(load_url, 1));

// as we use html in webiew i am trying to use it here not rly sure if it works though
define_global_function("window_with_html",function!(window_with_html,1));

Expand Down
4 changes: 4 additions & 0 deletions ext/wry_ruby/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ use magnus::Error;

mod application;

mod webview;

#[magnus::init]
fn init() -> Result<(), Error> {
application::init()
// webview::init()

}
7 changes: 7 additions & 0 deletions ext/wry_ruby/src/webview/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// use magnus::Error;
// mod utils;

// pub fn init() -> Result<(), Error> {
// // utils::init()?;
// Ok(())
// }
41 changes: 41 additions & 0 deletions ext/wry_ruby/src/webview/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// hmm i am tired of this errors where traits are not implemented for tht , this hmmmm i will look into this later.
// we need this mostly to eval js code


// **************************************************************************************************************************************************************************************

// use std::sync::{Arc, Mutex};
// use webkit2gtk::WebView;

// use magnus::{function, Error, ExceptionClass, Module, Object, RString, define_global_function, class};
// use wry::application::window::Window as WindowImpl;
// use wry::webview::WebView as WebViewImpl;

// pub struct WebViewWrapper {
// inner: Arc<Mutex<WebViewImpl>>,
// }

// impl WebViewWrapper {
// pub fn window(&self) -> Result<(), Error> {
// let inner = self.inner.lock().unwrap();
// WebViewImpl::window(&inner);
// Ok(())
// }

// pub fn eval(&self, js: RString) -> Result<(), Error> {
// let inner = self.inner.lock().unwrap();
// WebViewImpl::evaluate_script(&inner, unsafe { js.as_str() })?;
// Ok(())
// }
// }

// pub fn init() -> Result<(), Error> {
// // define_global_function("webview_eval", WebViewWrapper::eval);

// class::string()
// .define_private_method("eval",function!(WebViewWrapper::eval,2));
// Ok(())
// }
// // inner: Arc<Mutex<WebViewImpl>>,


0 comments on commit 7da6c0a

Please sign in to comment.