wry_ruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +12 -0
- data/.ruby-version +1 -0
- data/.rust-version +1 -0
- data/.tool-versions +1 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Cargo.lock +2423 -0
- data/Cargo.toml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +24 -0
- data/ext/wry_ruby/Cargo.toml +16 -0
- data/ext/wry_ruby/extconf.rb +6 -0
- data/ext/wry_ruby/src/application/clipboard.rs +77 -0
- data/ext/wry_ruby/src/application/event_loop.rs +39 -0
- data/ext/wry_ruby/src/application/mod.rs +17 -0
- data/ext/wry_ruby/src/application/tray_id.rs +51 -0
- data/ext/wry_ruby/src/application/window.rs +86 -0
- data/ext/wry_ruby/src/lib.rs +8 -0
- data/lib/example.rb +3 -0
- data/lib/wry_ruby/version.rb +5 -0
- data/lib/wry_ruby.rb +4 -0
- data/sig/wry_ruby.rbs +4 -0
- metadata +97 -0
data/Cargo.toml
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 gintama91
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# WryRuby
|
2
|
+
|
3
|
+
WryRuby is a project that provides experimental Ruby bindings for the [Tauri's Wry library](https://github.com/tauri-apps/wry). It aims to facilitate using Wry functionality in Ruby applications.
|
4
|
+
|
5
|
+
**Note: This PROJECT and README is a work in progress and will be updated as we go.**
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
Currently, WryRuby supports the following features:
|
10
|
+
|
11
|
+
- **Trayid**: Provides functionality for creating system tray icons.
|
12
|
+
- **New Window**: Allows creating new windows for your application.
|
13
|
+
- **Clipboard**: Provides access to the system clipboard.
|
14
|
+
- **Event Loop**: Allows creating and managing event loops for your application. as of now only new
|
15
|
+
|
16
|
+
To see examples of how to use these features in Ruby, please refer to the tests directory in this project.
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
To use WryRuby, you can install it directly using gem:(not available yet)
|
21
|
+
|
22
|
+
```bash
|
23
|
+
gem install wry_ruby
|
24
|
+
```
|
25
|
+
|
26
|
+
### For development
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/gintama91/wry_ruby
|
31
|
+
|
32
|
+
## License
|
33
|
+
|
34
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
35
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
require "rb_sys/extensiontask"
|
17
|
+
|
18
|
+
task build: :compile
|
19
|
+
|
20
|
+
RbSys::ExtensionTask.new("wry_ruby") do |ext|
|
21
|
+
ext.lib_dir = "lib/wry_ruby"
|
22
|
+
end
|
23
|
+
|
24
|
+
task default: %i[compile test] # no rubocop add later
|
@@ -0,0 +1,16 @@
|
|
1
|
+
[package]
|
2
|
+
name = "wry_ruby"
|
3
|
+
version = "0.1.0"
|
4
|
+
edition = "2021"
|
5
|
+
authors = ["gintama91 <b9-20@srkrec.edu.in>"]
|
6
|
+
license = "MIT"
|
7
|
+
publish = false
|
8
|
+
|
9
|
+
[lib]
|
10
|
+
crate-type = ["cdylib"]
|
11
|
+
|
12
|
+
[dependencies]
|
13
|
+
magnus = { version = "0.5.4" }
|
14
|
+
wry = "0.29.0"
|
15
|
+
gdk = "0.16.2"
|
16
|
+
gtk="0.16.2"
|
@@ -0,0 +1,77 @@
|
|
1
|
+
// https://docs.rs/wry/latest/wry/application/clipboard/struct.Clipboard.html
|
2
|
+
|
3
|
+
use std::cell::RefCell;
|
4
|
+
|
5
|
+
use gdk;
|
6
|
+
use gtk;
|
7
|
+
|
8
|
+
use magnus::{function, method, Error, Module, Object};
|
9
|
+
|
10
|
+
use wry::application::clipboard::Clipboard as ClipboardImpl;
|
11
|
+
|
12
|
+
#[derive(Clone, Debug)]
|
13
|
+
#[magnus::wrap(class = "Clip")]
|
14
|
+
pub struct Clipboard {
|
15
|
+
inner: RefCell<ClipboardImpl>,
|
16
|
+
}
|
17
|
+
|
18
|
+
impl Clipboard {
|
19
|
+
pub fn new() -> Result<Self, Error> {
|
20
|
+
let inner = ClipboardImpl::new();
|
21
|
+
|
22
|
+
Ok(Self {
|
23
|
+
inner: RefCell::new(inner),
|
24
|
+
})
|
25
|
+
}
|
26
|
+
|
27
|
+
pub fn get(&self) -> std::cell::Ref<ClipboardImpl> {
|
28
|
+
self.inner.borrow()
|
29
|
+
}
|
30
|
+
|
31
|
+
pub fn get_mut(&self) -> std::cell::RefMut<ClipboardImpl> {
|
32
|
+
self.inner.borrow_mut()
|
33
|
+
}
|
34
|
+
|
35
|
+
/// Writes text to the clipboard.
|
36
|
+
///
|
37
|
+
/// # Arguments
|
38
|
+
///
|
39
|
+
/// * `s` - A string containing the text to be written.
|
40
|
+
///
|
41
|
+
/// # Equivalent Ruby Method
|
42
|
+
///
|
43
|
+
/// `clip.write_text("Hello World")`
|
44
|
+
pub fn write_text(&self, s: String) {
|
45
|
+
let text: &str = s.as_ref();
|
46
|
+
self.get_mut().write_text(text);
|
47
|
+
}
|
48
|
+
|
49
|
+
/// Reads text from the clipboard.
|
50
|
+
///
|
51
|
+
/// # Equivalent Ruby Method
|
52
|
+
///
|
53
|
+
/// `clip.read_text`
|
54
|
+
pub fn read_text(&self) -> Option<String> {
|
55
|
+
self.get().read_text()
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
/// Initializes the clipboard module.
|
60
|
+
///
|
61
|
+
/// # Equivalent Ruby Methods
|
62
|
+
///
|
63
|
+
/// - `clip = Clip.new`
|
64
|
+
/// - `clip.write_text("Hello World")`
|
65
|
+
/// - `clip.read_text`
|
66
|
+
pub fn init() -> Result<(), Error> {
|
67
|
+
gdk::init();
|
68
|
+
let _ = gtk::init();
|
69
|
+
|
70
|
+
let class = magnus::define_class("Clip", Default::default())?;
|
71
|
+
|
72
|
+
class.define_singleton_method("new", function!(Clipboard::new, 0))?;
|
73
|
+
class.define_method("write_text", method!(Clipboard::write_text, 1))?;
|
74
|
+
class.define_method("read_text", method!(Clipboard::read_text, 0))?;
|
75
|
+
|
76
|
+
Ok(())
|
77
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
use magnus::{
|
2
|
+
function, Error, Object,
|
3
|
+
};
|
4
|
+
|
5
|
+
use std::marker::PhantomData;
|
6
|
+
use std::sync::atomic::{AtomicPtr};
|
7
|
+
|
8
|
+
use wry::application::event_loop::{
|
9
|
+
EventLoop as EventLoopImpl,
|
10
|
+
};
|
11
|
+
|
12
|
+
#[magnus::wrap(class = "EventLoop")]
|
13
|
+
pub struct EventLoop {
|
14
|
+
inner: SafeWrapper<EventLoopImpl<()>>,
|
15
|
+
}
|
16
|
+
|
17
|
+
pub struct SafeWrapper<T> {
|
18
|
+
event_loop: AtomicPtr<T>,
|
19
|
+
_marker: PhantomData<*mut T>,
|
20
|
+
}
|
21
|
+
|
22
|
+
unsafe impl<T> Send for SafeWrapper<T> {}
|
23
|
+
|
24
|
+
impl EventLoop {
|
25
|
+
pub fn new() -> Self {
|
26
|
+
let event_loop_impl = EventLoopImpl::new();
|
27
|
+
let inner = SafeWrapper {
|
28
|
+
event_loop: AtomicPtr::new(Box::into_raw(Box::new(event_loop_impl))),
|
29
|
+
_marker: PhantomData,
|
30
|
+
};
|
31
|
+
EventLoop { inner }
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
pub fn init() -> Result<(), Error> {
|
36
|
+
let class = magnus::define_class("WindowBuilder", Default::default())?;
|
37
|
+
class.define_singleton_method("new", function!(EventLoop::new, 0))?;
|
38
|
+
Ok(())
|
39
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
use magnus::{function, Error, ExceptionClass, Module, Object, RString};
|
2
|
+
use wry::application::TrayId as TrayIdImpl;
|
3
|
+
|
4
|
+
#[derive(Clone, Debug)]
|
5
|
+
#[magnus::wrap(class = "TrayId")]
|
6
|
+
pub struct TrayId {
|
7
|
+
inner: TrayIdImpl,
|
8
|
+
}
|
9
|
+
|
10
|
+
impl TrayId {
|
11
|
+
pub const EMPTY: TrayId = TrayId {
|
12
|
+
inner: TrayIdImpl::EMPTY,
|
13
|
+
};
|
14
|
+
|
15
|
+
pub fn new(unique_string: RString) -> Result<Self, Error> {
|
16
|
+
if unique_string.is_empty() {
|
17
|
+
return Err(Error::new(
|
18
|
+
ExceptionClass::default(),
|
19
|
+
"Unique string cannot be empty",
|
20
|
+
));
|
21
|
+
}
|
22
|
+
|
23
|
+
let s = match unique_string.as_interned_str() {
|
24
|
+
Some(str_ref) => str_ref.as_str().unwrap(),
|
25
|
+
None => {
|
26
|
+
println!("ok why is it none, hm check freeze or no");
|
27
|
+
return Err(Error::new(
|
28
|
+
ExceptionClass::default(),
|
29
|
+
"Interned string not available",
|
30
|
+
));
|
31
|
+
}
|
32
|
+
};
|
33
|
+
|
34
|
+
Ok(Self {
|
35
|
+
inner: TrayIdImpl::new(s),
|
36
|
+
})
|
37
|
+
}
|
38
|
+
|
39
|
+
pub fn is_empty(&self) -> bool {
|
40
|
+
self.inner.is_empty()
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
pub fn init() -> Result<(), Error> {
|
45
|
+
let class = magnus::define_class("TrayId", Default::default())?;
|
46
|
+
|
47
|
+
class.define_singleton_method("new", function!(TrayId::new, 1))?;
|
48
|
+
class.define_method("is_empty", magnus::method!(TrayId::is_empty, 0))?;
|
49
|
+
|
50
|
+
Ok(())
|
51
|
+
}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
use magnus::{Error, define_global_function, function, method};
|
2
|
+
use wry::application::dpi::LogicalSize;
|
3
|
+
use wry::application::window::WindowBuilder;
|
4
|
+
use wry::application::{
|
5
|
+
event::{Event, StartCause, WindowEvent},
|
6
|
+
event_loop::{ControlFlow, EventLoop},
|
7
|
+
};
|
8
|
+
use wry::webview::WebViewBuilder;
|
9
|
+
use std::time::{Duration, Instant};
|
10
|
+
|
11
|
+
pub fn WindoWnew(title: String, width: u32, height: u32, resizable: bool,timeout: u64) {
|
12
|
+
let event_loop = EventLoop::new();
|
13
|
+
let mut window_builder = WindowBuilder::new();
|
14
|
+
window_builder = window_builder.with_title(title.clone());
|
15
|
+
window_builder = window_builder.with_inner_size(LogicalSize::new(width, height));
|
16
|
+
window_builder = window_builder.with_resizable(resizable);
|
17
|
+
|
18
|
+
let window = window_builder.build(&event_loop).expect("Failed to create window");
|
19
|
+
|
20
|
+
// Get initial properties
|
21
|
+
let current_title = window.title();
|
22
|
+
let current_size = window.inner_size();
|
23
|
+
let resizable = window.is_resizable();
|
24
|
+
|
25
|
+
println!("Initial Title: {}", current_title);
|
26
|
+
println!("Initial Size: {:?}", current_size);
|
27
|
+
println!("Resizable: {}", resizable);
|
28
|
+
|
29
|
+
// ************************************************* as of now we are using this timeout to close for test******************************************************
|
30
|
+
let timeout_duration = Duration::from_secs(timeout);
|
31
|
+
let start_time = Instant::now();
|
32
|
+
|
33
|
+
event_loop.run(move |event, _, control_flow| {
|
34
|
+
*control_flow = ControlFlow::Wait;
|
35
|
+
|
36
|
+
match event {
|
37
|
+
Event::NewEvents(StartCause::Init) => println!("Wry has started!"),
|
38
|
+
Event::WindowEvent {
|
39
|
+
event: WindowEvent::CloseRequested,
|
40
|
+
..
|
41
|
+
} => *control_flow = ControlFlow::Exit,
|
42
|
+
_ => (),
|
43
|
+
}
|
44
|
+
|
45
|
+
let elapsed = Instant::now() - start_time;
|
46
|
+
if elapsed >= timeout_duration {
|
47
|
+
println!("Window creation timed out after {:?}.", timeout_duration);
|
48
|
+
*control_flow = ControlFlow::Exit;
|
49
|
+
}
|
50
|
+
});
|
51
|
+
}
|
52
|
+
|
53
|
+
pub fn window_with_html(html:String){
|
54
|
+
let event_loop = EventLoop::new();
|
55
|
+
let window = WindowBuilder::new()
|
56
|
+
.with_title("Shoes with html")
|
57
|
+
.build(&event_loop)
|
58
|
+
.unwrap();
|
59
|
+
let _webview = WebViewBuilder::new(window).unwrap()
|
60
|
+
.with_html(&html)
|
61
|
+
.unwrap()
|
62
|
+
.build()
|
63
|
+
.unwrap();
|
64
|
+
|
65
|
+
event_loop.run(move |event, _, control_flow| {
|
66
|
+
*control_flow = ControlFlow::Wait;
|
67
|
+
|
68
|
+
match event {
|
69
|
+
Event::NewEvents(StartCause::Init) => println!("Wry has started!"),
|
70
|
+
Event::WindowEvent {
|
71
|
+
event: WindowEvent::CloseRequested,
|
72
|
+
..
|
73
|
+
} => *control_flow = ControlFlow::Exit,
|
74
|
+
_ => (),
|
75
|
+
}
|
76
|
+
});
|
77
|
+
|
78
|
+
}
|
79
|
+
pub fn init() -> Result<(), Error> {
|
80
|
+
println!("inside init");
|
81
|
+
define_global_function("new_window", function!(WindoWnew, 5));
|
82
|
+
// as we use html in webiew i am trying to use it here not rly sure if it works though
|
83
|
+
define_global_function("window_with_html",function!(window_with_html,1));
|
84
|
+
|
85
|
+
Ok(())
|
86
|
+
}
|
data/lib/example.rb
ADDED
data/lib/wry_ruby.rb
ADDED
data/sig/wry_ruby.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wry_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pavan Nambi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-07-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rb_sys
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.39
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.39
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake-compiler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.2.0
|
41
|
+
description: Ruby bindings for Wry........
|
42
|
+
email:
|
43
|
+
- pavannambi0408@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions:
|
46
|
+
- ext/wry_ruby/extconf.rb
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".rubocop.yml"
|
50
|
+
- ".ruby-version"
|
51
|
+
- ".rust-version"
|
52
|
+
- ".tool-versions"
|
53
|
+
- CHANGELOG.md
|
54
|
+
- CODE_OF_CONDUCT.md
|
55
|
+
- Cargo.lock
|
56
|
+
- Cargo.toml
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- ext/wry_ruby/Cargo.toml
|
61
|
+
- ext/wry_ruby/extconf.rb
|
62
|
+
- ext/wry_ruby/src/application/clipboard.rs
|
63
|
+
- ext/wry_ruby/src/application/event_loop.rs
|
64
|
+
- ext/wry_ruby/src/application/mod.rs
|
65
|
+
- ext/wry_ruby/src/application/tray_id.rs
|
66
|
+
- ext/wry_ruby/src/application/window.rs
|
67
|
+
- ext/wry_ruby/src/lib.rs
|
68
|
+
- lib/example.rb
|
69
|
+
- lib/wry_ruby.rb
|
70
|
+
- lib/wry_ruby/version.rb
|
71
|
+
- sig/wry_ruby.rbs
|
72
|
+
homepage: https://github.com/gintama91/wry_ruby
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata:
|
76
|
+
homepage_uri: https://github.com/gintama91/wry_ruby
|
77
|
+
source_code_uri: https://github.com/gintama91/wry_ruby
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 2.6.0
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 3.3.11
|
92
|
+
requirements: []
|
93
|
+
rubygems_version: 3.4.17
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Ruby bindings for Wry.
|
97
|
+
test_files: []
|