From c56c83305421a89a0941dcd2ff23e60b83965c92 Mon Sep 17 00:00:00 2001 From: gintama91 Date: Thu, 29 Jun 2023 21:30:50 +0530 Subject: [PATCH 1/9] new window --- Cargo.lock | 2 + ext/wry_ruby/Cargo.toml | 4 +- ext/wry_ruby/src/application/mod.rs | 10 +++++ ext/wry_ruby/src/application/window.rs | 53 ++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 ext/wry_ruby/src/application/window.rs diff --git a/Cargo.lock b/Cargo.lock index 011edad..6d23d84 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2395,6 +2395,8 @@ dependencies = [ name = "wry_ruby" version = "0.1.0" dependencies = [ + "gdk", + "gtk", "magnus", "wry", ] diff --git a/ext/wry_ruby/Cargo.toml b/ext/wry_ruby/Cargo.toml index d601e05..46d56e8 100644 --- a/ext/wry_ruby/Cargo.toml +++ b/ext/wry_ruby/Cargo.toml @@ -10,5 +10,7 @@ publish = false crate-type = ["cdylib"] [dependencies] -magnus = { version = "0.5" } +magnus = { version = "0.5.4" } wry = "0.29.0" +gdk = "0.16.2" +gtk="0.16.2" \ No newline at end of file diff --git a/ext/wry_ruby/src/application/mod.rs b/ext/wry_ruby/src/application/mod.rs index 00d6a98..3fb06de 100644 --- a/ext/wry_ruby/src/application/mod.rs +++ b/ext/wry_ruby/src/application/mod.rs @@ -1,8 +1,18 @@ use magnus:: Error; +use wry::application::event_loop; mod tray_id; +mod window; + +mod clipboard; + +// mod event_loop; + pub fn init() -> Result<(), Error> { tray_id::init()?; + // window::init()?; + clipboard::init()?; + // event_loop::init()?; Ok(()) } diff --git a/ext/wry_ruby/src/application/window.rs b/ext/wry_ruby/src/application/window.rs new file mode 100644 index 0000000..c969e61 --- /dev/null +++ b/ext/wry_ruby/src/application/window.rs @@ -0,0 +1,53 @@ +use magnus::{Error, define_global_function, function, define_class}; +use wry::application::dpi::LogicalSize; +use wry::application::window::WindowBuilder; + +use wry::{ + application::{ + event::{Event, StartCause, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, + }, + webview::WebViewBuilder, + }; + +pub fn WindoWnew(title: String, width: u32, height: u32) { + let event_loop = wry::application::event_loop::EventLoop::new(); + let mut window_builder = WindowBuilder::new(); + window_builder = window_builder.with_title(title.clone()); + window_builder = window_builder.with_inner_size(LogicalSize::new(width, height)); + window_builder = window_builder.with_resizable(false); + + let window = window_builder.build(&event_loop).expect("Failed to create window"); + + // Get initial properties + let current_title = window.title(); + let current_size = window.inner_size(); + let resizable = window.is_resizable(); + + println!("Initial Title: {}", current_title); + println!("Initial Size: {:?}", current_size); + println!("Resizable: {}", resizable); + + + event_loop.run(move |event, _, control_flow| { + *control_flow = ControlFlow::Wait; + + match event { + Event::NewEvents(StartCause::Init) => println!("Wry has started!"), + Event::WindowEvent { + event: WindowEvent::CloseRequested, + .. + } => *control_flow = ControlFlow::Exit, + _ => (), + } + }); +} + + +pub fn init() -> Result<(), Error> { + + define_global_function("new_window", function!(WindoWnew, 3)); + // define_global_function("hello_wry", function!(new, 3)); + // application::init(); + Ok(()) +} \ No newline at end of file From 2f5088023157be69e3b7187b3e9c245a36e17e44 Mon Sep 17 00:00:00 2001 From: gintama91 Date: Thu, 29 Jun 2023 21:31:26 +0530 Subject: [PATCH 2/9] clipboard add rs doc link --- ext/wry_ruby/src/application/clipboard.rs | 77 +++++++++++++++++++++++ test/test_clipboard.rb | 15 +++++ 2 files changed, 92 insertions(+) create mode 100644 ext/wry_ruby/src/application/clipboard.rs create mode 100644 test/test_clipboard.rb diff --git a/ext/wry_ruby/src/application/clipboard.rs b/ext/wry_ruby/src/application/clipboard.rs new file mode 100644 index 0000000..3daa2fc --- /dev/null +++ b/ext/wry_ruby/src/application/clipboard.rs @@ -0,0 +1,77 @@ +// https://docs.rs/wry/latest/wry/application/clipboard/struct.Clipboard.html + +use std::cell::RefCell; + +use gdk; +use gtk; + +use magnus::{Error, function, Object, Module, method}; + +use wry::application::clipboard::Clipboard as ClipboardImpl; + +#[derive(Clone, Debug)] +#[magnus::wrap(class = "Clip")] +pub struct Clipboard { + inner: RefCell, +} + +impl Clipboard { + pub fn new() -> Result { + let inner = ClipboardImpl::new(); + + Ok(Self { + inner: RefCell::new(inner), + }) + } + + pub fn get(&self) -> std::cell::Ref { + self.inner.borrow() + } + + pub fn get_mut(&self) -> std::cell::RefMut { + self.inner.borrow_mut() + } + + /// Writes text to the clipboard. + /// + /// # Arguments + /// + /// * `s` - A string containing the text to be written. + /// + /// # Equivalent Ruby Method + /// + /// `clip.write_text("Hello World")` + pub fn write_text(&self, s: String) { + let text: &str = s.as_ref(); + self.get_mut().write_text(text); + } + + /// Reads text from the clipboard. + /// + /// # Equivalent Ruby Method + /// + /// `clip.read_text` + pub fn read_text(&self) -> Option { + self.get().read_text() + } +} + +/// Initializes the clipboard module. +/// +/// # Equivalent Ruby Methods +/// +/// - `clip = Clip.new` +/// - `clip.write_text("Hello World")` +/// - `clip.read_text` +pub fn init() -> Result<(), Error> { + gdk::init(); + let _ = gtk::init(); + + let class = magnus::define_class("Clip", Default::default())?; + + class.define_singleton_method("new", function!(Clipboard::new, 0))?; + class.define_method("write_text", method!(Clipboard::write_text, 1))?; + class.define_method("read_text", method!(Clipboard::read_text, 0))?; + + Ok(()) +} diff --git a/test/test_clipboard.rb b/test/test_clipboard.rb new file mode 100644 index 0000000..3fdbeb8 --- /dev/null +++ b/test/test_clipboard.rb @@ -0,0 +1,15 @@ +require 'test_helper' + +class ClipboardTest < Minitest::Test + def test_clipboard_functionality + clip = Clip.new + + # Write text to the clipboard + clip.write_text("Hello, World!") + + # Read text from the clipboard + text = clip.read_text + + assert_equal("Hello, World!", text) + end +end From baba5d0bcb3aa22b1a8d29620c2a58e4fd29ff23 Mon Sep 17 00:00:00 2001 From: gintama91 Date: Fri, 30 Jun 2023 07:24:04 +0530 Subject: [PATCH 3/9] wip eventloop --- ext/wry_ruby/src/application/clipboard.rs | 2 +- ext/wry_ruby/src/application/event_loop.rs | 39 ++++++++++++++++++++++ ext/wry_ruby/src/application/mod.rs | 7 ++-- ext/wry_ruby/src/lib.rs | 2 +- 4 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 ext/wry_ruby/src/application/event_loop.rs diff --git a/ext/wry_ruby/src/application/clipboard.rs b/ext/wry_ruby/src/application/clipboard.rs index 3daa2fc..342e3df 100644 --- a/ext/wry_ruby/src/application/clipboard.rs +++ b/ext/wry_ruby/src/application/clipboard.rs @@ -5,7 +5,7 @@ use std::cell::RefCell; use gdk; use gtk; -use magnus::{Error, function, Object, Module, method}; +use magnus::{function, method, Error, Module, Object}; use wry::application::clipboard::Clipboard as ClipboardImpl; diff --git a/ext/wry_ruby/src/application/event_loop.rs b/ext/wry_ruby/src/application/event_loop.rs new file mode 100644 index 0000000..337da97 --- /dev/null +++ b/ext/wry_ruby/src/application/event_loop.rs @@ -0,0 +1,39 @@ +use magnus::{ + define_class, define_global_function, function, method, Error, Module, Object, Value, +}; +use std::cell::RefCell; +use std::marker::PhantomData; +use std::sync::atomic::{AtomicPtr, Ordering}; +use wry::application::dpi::LogicalSize; +use wry::application::event_loop::{ + EventLoop as EventLoopImpl, +}; + +#[magnus::wrap(class = "EventLoop")] +pub struct EventLoop { + inner: SafeWrapper>, +} + +pub struct SafeWrapper { + event_loop: AtomicPtr, + _marker: PhantomData<*mut T>, +} + +unsafe impl Send for SafeWrapper {} + +impl EventLoop { + pub fn new() -> Self { + let event_loop_impl = EventLoopImpl::new(); + let inner = SafeWrapper { + event_loop: AtomicPtr::new(Box::into_raw(Box::new(event_loop_impl))), + _marker: PhantomData, + }; + EventLoop { inner } + } +} + +pub fn init() -> Result<(), Error> { + let class = magnus::define_class("WindowBuilder", Default::default())?; + class.define_singleton_method("new", function!(EventLoop::new, 0))?; + Ok(()) +} diff --git a/ext/wry_ruby/src/application/mod.rs b/ext/wry_ruby/src/application/mod.rs index 3fb06de..dab16bb 100644 --- a/ext/wry_ruby/src/application/mod.rs +++ b/ext/wry_ruby/src/application/mod.rs @@ -1,5 +1,4 @@ -use magnus:: Error; -use wry::application::event_loop; +use magnus::Error; mod tray_id; @@ -7,12 +6,12 @@ mod window; mod clipboard; -// mod event_loop; +mod event_loop; pub fn init() -> Result<(), Error> { tray_id::init()?; // window::init()?; clipboard::init()?; - // event_loop::init()?; + event_loop::init()?; Ok(()) } diff --git a/ext/wry_ruby/src/lib.rs b/ext/wry_ruby/src/lib.rs index 650d5f3..e7a74d2 100644 --- a/ext/wry_ruby/src/lib.rs +++ b/ext/wry_ruby/src/lib.rs @@ -5,4 +5,4 @@ mod application; #[magnus::init] fn init() -> Result<(), Error> { application::init() -} \ No newline at end of file +} From 6b0f67daa2a44bd7832389cbb932f49203a1b993 Mon Sep 17 00:00:00 2001 From: gintama91 Date: Fri, 30 Jun 2023 12:21:06 +0530 Subject: [PATCH 4/9] cleanup timeout for newwindow --- .rubocop.yml | 3 +- Rakefile | 2 +- ext/wry_ruby/src/application/event_loop.rs | 10 ++-- ext/wry_ruby/src/application/mod.rs | 2 +- ext/wry_ruby/src/application/window.rs | 60 ++++++++++++---------- lib/example.rb | 3 +- test/test_application_tray.rb | 8 ++- test/test_wry_ruby.rb | 5 +- wry_ruby.gemspec | 8 +-- 9 files changed, 52 insertions(+), 49 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index e3462a7..6657af0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,8 +2,7 @@ AllCops: TargetRubyVersion: 2.6 Style/StringLiterals: - Enabled: true - EnforcedStyle: double_quotes + Enabled: false # Disable frozen literal string enforcement FOR NOW AS SOME NEED TO BE FREEZED and some don't Style/StringLiteralsInInterpolation: Enabled: true diff --git a/Rakefile b/Rakefile index 4ef2a6d..a9051b7 100644 --- a/Rakefile +++ b/Rakefile @@ -21,4 +21,4 @@ RbSys::ExtensionTask.new("wry_ruby") do |ext| ext.lib_dir = "lib/wry_ruby" end -task default: %i[compile test ]#no rubocop add later +task default: %i[compile test] # no rubocop add later diff --git a/ext/wry_ruby/src/application/event_loop.rs b/ext/wry_ruby/src/application/event_loop.rs index 337da97..415e9c3 100644 --- a/ext/wry_ruby/src/application/event_loop.rs +++ b/ext/wry_ruby/src/application/event_loop.rs @@ -1,10 +1,10 @@ use magnus::{ - define_class, define_global_function, function, method, Error, Module, Object, Value, + function, Error, Object, }; -use std::cell::RefCell; + use std::marker::PhantomData; -use std::sync::atomic::{AtomicPtr, Ordering}; -use wry::application::dpi::LogicalSize; +use std::sync::atomic::{AtomicPtr}; + use wry::application::event_loop::{ EventLoop as EventLoopImpl, }; @@ -19,7 +19,7 @@ pub struct SafeWrapper { _marker: PhantomData<*mut T>, } -unsafe impl Send for SafeWrapper {} +unsafe impl Send for SafeWrapper {} impl EventLoop { pub fn new() -> Self { diff --git a/ext/wry_ruby/src/application/mod.rs b/ext/wry_ruby/src/application/mod.rs index dab16bb..3444e3d 100644 --- a/ext/wry_ruby/src/application/mod.rs +++ b/ext/wry_ruby/src/application/mod.rs @@ -10,7 +10,7 @@ mod event_loop; pub fn init() -> Result<(), Error> { tray_id::init()?; - // window::init()?; + window::init()?; clipboard::init()?; event_loop::init()?; Ok(()) diff --git a/ext/wry_ruby/src/application/window.rs b/ext/wry_ruby/src/application/window.rs index c969e61..cbd4239 100644 --- a/ext/wry_ruby/src/application/window.rs +++ b/ext/wry_ruby/src/application/window.rs @@ -1,21 +1,18 @@ -use magnus::{Error, define_global_function, function, define_class}; +use magnus::{Error, define_global_function, function}; use wry::application::dpi::LogicalSize; use wry::application::window::WindowBuilder; - -use wry::{ - application::{ - event::{Event, StartCause, WindowEvent}, - event_loop::{ControlFlow, EventLoop}, - }, - webview::WebViewBuilder, - }; - -pub fn WindoWnew(title: String, width: u32, height: u32) { - let event_loop = wry::application::event_loop::EventLoop::new(); +use wry::application::{ + event::{Event, StartCause, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, +}; +use std::time::{Duration, Instant}; + +pub fn WindoWnew(title: String, width: u32, height: u32, resizable: bool,timeout: u64) { + let event_loop = EventLoop::new(); let mut window_builder = WindowBuilder::new(); window_builder = window_builder.with_title(title.clone()); - window_builder = window_builder.with_inner_size(LogicalSize::new(width, height)); - window_builder = window_builder.with_resizable(false); + window_builder = window_builder.with_inner_size(LogicalSize::new(width, height)); + window_builder = window_builder.with_resizable(resizable); let window = window_builder.build(&event_loop).expect("Failed to create window"); @@ -28,26 +25,33 @@ pub fn WindoWnew(title: String, width: u32, height: u32) { println!("Initial Size: {:?}", current_size); println!("Resizable: {}", resizable); - + // ************************************************* as of now we are using this timeout to close for test****************************************************** + let timeout_duration = Duration::from_secs(timeout); + let start_time = Instant::now(); + event_loop.run(move |event, _, control_flow| { *control_flow = ControlFlow::Wait; - + match event { - Event::NewEvents(StartCause::Init) => println!("Wry has started!"), - Event::WindowEvent { - event: WindowEvent::CloseRequested, - .. - } => *control_flow = ControlFlow::Exit, - _ => (), + Event::NewEvents(StartCause::Init) => println!("Wry has started!"), + Event::WindowEvent { + event: WindowEvent::CloseRequested, + .. + } => *control_flow = ControlFlow::Exit, + _ => (), } - }); -} + let elapsed = Instant::now() - start_time; + if elapsed >= timeout_duration { + println!("Window creation timed out after {:?}.", timeout_duration); + *control_flow = ControlFlow::Exit; + } + }); +} pub fn init() -> Result<(), Error> { + println!("inside init"); + define_global_function("new_window", function!(WindoWnew, 5)); - define_global_function("new_window", function!(WindoWnew, 3)); - // define_global_function("hello_wry", function!(new, 3)); - // application::init(); Ok(()) -} \ No newline at end of file +} diff --git a/lib/example.rb b/lib/example.rb index 29ea384..ca8f411 100644 --- a/lib/example.rb +++ b/lib/example.rb @@ -1,2 +1,3 @@ -require_relative "wry_ruby/wry_ruby" +# frozen_string_literal: true +require_relative "wry_ruby/wry_ruby" diff --git a/test/test_application_tray.rb b/test/test_application_tray.rb index 9d70782..6d414fb 100644 --- a/test/test_application_tray.rb +++ b/test/test_application_tray.rb @@ -1,16 +1,14 @@ - -require 'test_helper' +require "test_helper" class TestWryRuby < Minitest::Test - def test_tray_id_new_with_empty_string assert_raises(StandardError) do - TrayId.new("".freeze()) # Unique string is empty + TrayId.new("") # Unique string is empty end end def test_tray_id_new_with_non_empty_string - tray_id = TrayId.new("hmm".freeze()) # Unique string is non-empty + tray_id = TrayId.new("hmm") # Unique string is non-empty refute(tray_id.is_empty) end diff --git a/test/test_wry_ruby.rb b/test/test_wry_ruby.rb index f8fbf74..08cafea 100644 --- a/test/test_wry_ruby.rb +++ b/test/test_wry_ruby.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require "test_helper" class TestWryRuby < Minitest::Test # def test_that_it_has_a_version_number @@ -6,6 +6,7 @@ class TestWryRuby < Minitest::Test # end def test_hello_wry - + # title, width, height, resizable , timeout (seconds) to close window during test + new_window "Hello Wry", 100, 400, true, 3 end end diff --git a/wry_ruby.gemspec b/wry_ruby.gemspec index 41b822e..a47ffa0 100644 --- a/wry_ruby.gemspec +++ b/wry_ruby.gemspec @@ -36,12 +36,12 @@ Gem::Specification.new do |spec| # Uncomment to register a new dependency of your gem # spec.add_dependency "example-gem", "~> 1.0" - + # needed until rubygems supports Rust support is out of beta -spec.add_dependency "rb_sys", "~> 0.9.39" + spec.add_dependency "rb_sys", "~> 0.9.39" -# only needed when developing or packaging your gem -spec.add_development_dependency "rake-compiler", "~> 1.2.0" + # only needed when developing or packaging your gem + spec.add_development_dependency "rake-compiler", "~> 1.2.0" # For more information and examples about making a new gem, check out our # guide at: https://bundler.io/guides/creating_gem.html From fe1d4fbc0918e54ecd85b60a9f1d0cd62e187335 Mon Sep 17 00:00:00 2001 From: gintama91 Date: Wed, 19 Jul 2023 10:29:25 +0530 Subject: [PATCH 5/9] remove ci test for window as of now --- test/test_wry_ruby.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_wry_ruby.rb b/test/test_wry_ruby.rb index 08cafea..53b1335 100644 --- a/test/test_wry_ruby.rb +++ b/test/test_wry_ruby.rb @@ -5,8 +5,8 @@ class TestWryRuby < Minitest::Test # refute_nil ::WryRuby::VERSION # end - def test_hello_wry - # title, width, height, resizable , timeout (seconds) to close window during test - new_window "Hello Wry", 100, 400, true, 3 - end + # def test_hello_wry + # # title, width, height, resizable , timeout (seconds) to close window during test + # new_window "Hello Wry", 100, 400, true, 3 + # end end From e65cb724c899f6ff980ae434737d22e42c7d83db Mon Sep 17 00:00:00 2001 From: gintama91 Date: Fri, 28 Jul 2023 13:39:29 +0530 Subject: [PATCH 6/9] use html to load window --- .ruby-version | 1 + .rust-version | 1 + .tool-versions | 1 + ext/wry_ruby/src/application/window.rs | 31 +++++++++++++++++++++++++- test/shoes.html | 13 +++++++++++ test/test_wry_ruby.rb | 15 +++++++++---- 6 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 .ruby-version create mode 100644 .rust-version create mode 100644 .tool-versions create mode 100644 test/shoes.html diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..be94e6f --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.2.2 diff --git a/.rust-version b/.rust-version new file mode 100644 index 0000000..832e9af --- /dev/null +++ b/.rust-version @@ -0,0 +1 @@ +1.70.0 diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..f2a971a --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +ruby 3.2.2 diff --git a/ext/wry_ruby/src/application/window.rs b/ext/wry_ruby/src/application/window.rs index cbd4239..20005f1 100644 --- a/ext/wry_ruby/src/application/window.rs +++ b/ext/wry_ruby/src/application/window.rs @@ -1,10 +1,11 @@ -use magnus::{Error, define_global_function, function}; +use magnus::{Error, define_global_function, function, method}; use wry::application::dpi::LogicalSize; use wry::application::window::WindowBuilder; use wry::application::{ event::{Event, StartCause, WindowEvent}, event_loop::{ControlFlow, EventLoop}, }; +use wry::webview::WebViewBuilder; use std::time::{Duration, Instant}; pub fn WindoWnew(title: String, width: u32, height: u32, resizable: bool,timeout: u64) { @@ -49,9 +50,37 @@ pub fn WindoWnew(title: String, width: u32, height: u32, resizable: bool,timeout }); } +pub fn window_with_html(html:String){ + let event_loop = EventLoop::new(); + let window = WindowBuilder::new() + .with_title("Shoes with html") + .build(&event_loop) + .unwrap(); + let _webview = WebViewBuilder::new(window).unwrap() + .with_html(&html) + .unwrap() + .build() + .unwrap(); + + event_loop.run(move |event, _, control_flow| { + *control_flow = ControlFlow::Wait; + + match event { + Event::NewEvents(StartCause::Init) => println!("Wry has started!"), + Event::WindowEvent { + event: WindowEvent::CloseRequested, + .. + } => *control_flow = ControlFlow::Exit, + _ => (), + } + }); + +} pub fn init() -> Result<(), Error> { println!("inside init"); define_global_function("new_window", function!(WindoWnew, 5)); + // 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)); Ok(()) } diff --git a/test/shoes.html b/test/shoes.html new file mode 100644 index 0000000..8b3b39e --- /dev/null +++ b/test/shoes.html @@ -0,0 +1,13 @@ + + + + + + Document + + +

Scarpe from html!!!

+

ok looking good

+ + + diff --git a/test/test_wry_ruby.rb b/test/test_wry_ruby.rb index 53b1335..676aec8 100644 --- a/test/test_wry_ruby.rb +++ b/test/test_wry_ruby.rb @@ -5,8 +5,15 @@ class TestWryRuby < Minitest::Test # refute_nil ::WryRuby::VERSION # end - # def test_hello_wry - # # title, width, height, resizable , timeout (seconds) to close window during test - # new_window "Hello Wry", 100, 400, true, 3 - # end + def test_hello_wry + # title, width, height, resizable, timeout (seconds) to close window during test + new_window "Hello Wry", 100, 400, true, 3 + + end + + def use_html + html_content = File.read("test/a.html") # Read the HTML content from your file hm maybee we can do this in rust side..??? + window_with_html(html_content) + end + end From 3d72ed3be4f62da27ec9c4b0f1809b409c404232 Mon Sep 17 00:00:00 2001 From: gintama91 Date: Fri, 28 Jul 2023 13:58:16 +0530 Subject: [PATCH 7/9] messed up with filename ok --- test/test_wry_ruby.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_wry_ruby.rb b/test/test_wry_ruby.rb index 676aec8..7a8fcf8 100644 --- a/test/test_wry_ruby.rb +++ b/test/test_wry_ruby.rb @@ -12,7 +12,7 @@ def test_hello_wry end def use_html - html_content = File.read("test/a.html") # Read the HTML content from your file hm maybee we can do this in rust side..??? + html_content = File.read("test/shoes.html") # Read the HTML content from your file hm maybee we can do this in rust side..??? window_with_html(html_content) end From c50909af163346a14eebcdd4cd525810d5abbade Mon Sep 17 00:00:00 2001 From: gintama91 Date: Fri, 28 Jul 2023 14:00:32 +0530 Subject: [PATCH 8/9] don't do ci now --- .github/workflows/main.yml | 64 ++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cd15cfc..db9ae09 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,36 +1,38 @@ -name: Ruby +# ah ok screw this i am tired of cancelling everytime until i figure out what happens i am commenting this out -on: - push: - branches: - - main - - dev - pull_request: +# name: Ruby -jobs: - build: - runs-on: ubuntu-latest - name: Ruby ${{ matrix.ruby }} - strategy: - matrix: - ruby: - - '3.2.2' +# on: +# push: +# branches: +# - main +# - dev +# pull_request: - steps: - - uses: actions/checkout@v3 - - name: Set up Ruby & Rust - uses: oxidize-rb/actions/setup-ruby-and-rust@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true - cargo-cache: true - rubygems: '3.4.14' +# jobs: +# build: +# runs-on: ubuntu-latest +# name: Ruby ${{ matrix.ruby }} +# strategy: +# matrix: +# ruby: +# - '3.2.2' - - name: Install dependencies - run: | - sudo apt update - sudo apt install -y libwebkit2gtk-4.1-dev - sudo apt install -y libayatana-appindicator3-dev +# steps: +# - uses: actions/checkout@v3 +# - name: Set up Ruby & Rust +# uses: oxidize-rb/actions/setup-ruby-and-rust@v1 +# with: +# ruby-version: ${{ matrix.ruby }} +# bundler-cache: true +# cargo-cache: true +# rubygems: '3.4.14' - - name: Run the default task - run: bundle exec rake +# - name: Install dependencies +# run: | +# sudo apt update +# sudo apt install -y libwebkit2gtk-4.1-dev +# sudo apt install -y libayatana-appindicator3-dev + +# - name: Run the default task +# run: bundle exec rake From 817711c3ecc5e00306392bb2aeee1cebc8741e59 Mon Sep 17 00:00:00 2001 From: gintama91 Date: Wed, 27 Sep 2023 14:06:15 +0530 Subject: [PATCH 9/9] can use url now to load window, and cleanup and wip tht eval --- .vscode/settings.json | 5 +++ Cargo.lock | 1 + README.md | 50 +++++++++++++++++----- examples/new_window.rb | 5 +++ ext/wry_ruby/Cargo.toml | 3 +- ext/wry_ruby/src/application/event_loop.rs | 8 ++-- ext/wry_ruby/src/application/tray_id.rs | 1 + ext/wry_ruby/src/application/window.rs | 36 ++++++++++++++-- ext/wry_ruby/src/lib.rs | 3 ++ ext/wry_ruby/src/webview/mod.rs | 7 +++ ext/wry_ruby/src/webview/utils.rs | 41 ++++++++++++++++++ 11 files changed, 141 insertions(+), 19 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 examples/new_window.rb create mode 100644 ext/wry_ruby/src/webview/mod.rs create mode 100644 ext/wry_ruby/src/webview/utils.rs diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a4fdae4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "rust-analyzer.linkedProjects": [ + "./ext/wry_ruby/Cargo.toml" + ] +} diff --git a/Cargo.lock b/Cargo.lock index 6d23d84..77c52e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2398,6 +2398,7 @@ dependencies = [ "gdk", "gtk", "magnus", + "webkit2gtk", "wry", ] diff --git a/README.md b/README.md index fe1afd2..a7d49da 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,57 @@ # WryRuby -# NOTE: update README later +[![License](https://img.shields.io/github/license/gintama91/wry_ruby)](https://opensource.org/licenses/MIT) +[![Issues](https://img.shields.io/github/issues/gintama91/wry_ruby)](https://github.com/gintama91/wry_ruby/issues) +[![Stars](https://img.shields.io/github/stars/gintama91/wry_ruby)](https://github.com/gintama91/wry_ruby/stargazers) +## Overview -## Installation +WryRuby is an **EXPERIMENTAL** Ruby project that provides ruby bindings for [Tauri's Wry library](https://github.com/tauri-apps/wry). +**Please Note: This project is not ready to use yet** -## Usage +## 🚀 Features +- **`Trayid`**: Simplified creation of system tray icons. +- **`New Window`**: Easy window creation for your Ruby application. +- **`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 -## Development +For examples and usage instructions, please refer to the `tests` directory or `examples` directory. +## 💻 Installation +To get started with WryRuby, you can install it using: -## Contributing +```bash +gem install wry_ruby +``` -Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/wry_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/wry_ruby/blob/main/CODE_OF_CONDUCT.md). +### 🛠️ Development Setup -## License +To contribute to the development of WryRuby, ensure you have Ruby and Rust installed on your system. Refer to the `.rust-version` and `.ruby-version` files for specific version requirements. -The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). +Install the dependencies based on your platform from [here](https://github.com/tauri-apps/wry#platform-specific-notes) -## Code of Conduct +```bash +git clone https://github.com/gintama91/wry_ruby.git +bundle install +``` -Everyone interacting in the WryRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/wry_ruby/blob/main/CODE_OF_CONDUCT.md). +To run examples: + +```bash +ruby examples/new_window.rb # Replace with the specific example name +``` + +## Contributing ❤️ + +We welcome bug reports and pull requests on our [GitHub repository](https://github.com/gintama91/wry_ruby). Join us in improving and expanding the capabilities of WryRuby. + +## License 📜 + +WryRuby is an open-source project licensed under the [MIT License](https://opensource.org/licenses/MIT). Feel free to use it and contribute to the community. diff --git a/examples/new_window.rb b/examples/new_window.rb new file mode 100644 index 0000000..88d7117 --- /dev/null +++ b/examples/new_window.rb @@ -0,0 +1,5 @@ +require_relative "../lib/wry_ruby/wry_ruby" + +# new_window("Hello Wry", 100, 400, true, 3) + +# load_with_url("https://github.com/scarpe-team/scarpe") diff --git a/ext/wry_ruby/Cargo.toml b/ext/wry_ruby/Cargo.toml index 46d56e8..c12d5bf 100644 --- a/ext/wry_ruby/Cargo.toml +++ b/ext/wry_ruby/Cargo.toml @@ -13,4 +13,5 @@ crate-type = ["cdylib"] magnus = { version = "0.5.4" } wry = "0.29.0" gdk = "0.16.2" -gtk="0.16.2" \ No newline at end of file +gtk="0.16.2" +webkit2gtk = "1.1.0" diff --git a/ext/wry_ruby/src/application/event_loop.rs b/ext/wry_ruby/src/application/event_loop.rs index 415e9c3..c209742 100644 --- a/ext/wry_ruby/src/application/event_loop.rs +++ b/ext/wry_ruby/src/application/event_loop.rs @@ -3,11 +3,9 @@ use magnus::{ }; use std::marker::PhantomData; -use std::sync::atomic::{AtomicPtr}; +use std::sync::atomic::AtomicPtr; -use wry::application::event_loop::{ - EventLoop as EventLoopImpl, -}; +use wry::application::event_loop::EventLoop as EventLoopImpl; #[magnus::wrap(class = "EventLoop")] pub struct EventLoop { @@ -19,7 +17,7 @@ pub struct SafeWrapper { _marker: PhantomData<*mut T>, } -unsafe impl Send for SafeWrapper {} +unsafe impl Send for SafeWrapper {} impl EventLoop { pub fn new() -> Self { diff --git a/ext/wry_ruby/src/application/tray_id.rs b/ext/wry_ruby/src/application/tray_id.rs index f58dd0a..c4e4842 100644 --- a/ext/wry_ruby/src/application/tray_id.rs +++ b/ext/wry_ruby/src/application/tray_id.rs @@ -8,6 +8,7 @@ pub struct TrayId { } impl TrayId { + #[allow(dead_code)] pub const EMPTY: TrayId = TrayId { inner: TrayIdImpl::EMPTY, }; diff --git a/ext/wry_ruby/src/application/window.rs b/ext/wry_ruby/src/application/window.rs index 20005f1..2771ad6 100644 --- a/ext/wry_ruby/src/application/window.rs +++ b/ext/wry_ruby/src/application/window.rs @@ -1,4 +1,4 @@ -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::{ @@ -34,7 +34,7 @@ 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, .. @@ -50,6 +50,35 @@ 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() @@ -66,7 +95,7 @@ pub fn window_with_html(html:String){ *control_flow = ControlFlow::Wait; match event { - Event::NewEvents(StartCause::Init) => println!("Wry has started!"), + Event::NewEvents(StartCause::Init) => println!("ok"), Event::WindowEvent { event: WindowEvent::CloseRequested, .. @@ -79,6 +108,7 @@ 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)); diff --git a/ext/wry_ruby/src/lib.rs b/ext/wry_ruby/src/lib.rs index e7a74d2..6b4b390 100644 --- a/ext/wry_ruby/src/lib.rs +++ b/ext/wry_ruby/src/lib.rs @@ -2,7 +2,10 @@ use magnus::Error; mod application; +mod webview; + #[magnus::init] fn init() -> Result<(), Error> { application::init() + // webview::init() } diff --git a/ext/wry_ruby/src/webview/mod.rs b/ext/wry_ruby/src/webview/mod.rs new file mode 100644 index 0000000..11cdfc6 --- /dev/null +++ b/ext/wry_ruby/src/webview/mod.rs @@ -0,0 +1,7 @@ +// use magnus::Error; +// mod utils; + +// pub fn init() -> Result<(), Error> { +// // utils::init()?; +// Ok(()) +// } diff --git a/ext/wry_ruby/src/webview/utils.rs b/ext/wry_ruby/src/webview/utils.rs new file mode 100644 index 0000000..9ec0362 --- /dev/null +++ b/ext/wry_ruby/src/webview/utils.rs @@ -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>, +// } + +// 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>, + +