Skip to content

Commit

Permalink
ci-checking
Browse files Browse the repository at this point in the history
  • Loading branch information
gintama91 committed Jul 12, 2023
1 parent ae1bfb5 commit 3c82caa
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 36 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: Ruby
name: Trying with Xvfb

on:
push:
branches:
- main
- dev
- ci-dev
pull_request:

jobs:
Expand All @@ -31,6 +32,15 @@ jobs:
sudo apt update
sudo apt install -y libwebkit2gtk-4.1-dev
sudo apt install -y libayatana-appindicator3-dev
sudo apt install -y at-spi2-core
- name: Run the default task
run: bundle exec rake
uses: coactions/setup-xvfb@v1
with:
run: bundle exec rake

- name: Capture screenshot
run: |
DISPLAY=:99 import -window root screenshot.png
echo "Screenshot captured!"
ls -l
3 changes: 1 addition & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ AllCops:
TargetRubyVersion: 2.6

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
Enabled: false

Style/StringLiteralsInInterpolation:
Enabled: true
Expand Down
56 changes: 30 additions & 26 deletions ext/wry_ruby/src/application/window.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
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},
},
};

pub fn WindoWnew(title: String, width: u32, height: u32, resizable: bool) {
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_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");
Expand All @@ -27,26 +25,32 @@ pub fn WindoWnew(title: String, width: u32, height: u32, resizable: bool) {
println!("Initial Size: {:?}", current_size);
println!("Resizable: {}", resizable);


// ******************************************************* for tests timeout ************************************************************************
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 {
*control_flow = ControlFlow::Exit
}
});
}

});
}

pub fn init() -> Result<(), Error> {
println!("inside init");
define_global_function("new_window", function!(WindoWnew, 4));
// define_global_function("hello_wry", function!(new, 3));
// application::init();
println!("inside init");
define_global_function("new_window", function!(WindoWnew, 5));

Ok(())
}
}
20 changes: 14 additions & 6 deletions test/test_wry_ruby.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
require 'test_helper'
require "test_helper"
require "timeout"

class TestWryRuby < Minitest::Test
# def test_that_it_has_a_version_number
# refute_nil ::WryRuby::VERSION
# end

def test_hello_wry
new_window "Hello Wry",100,400,true # title, width, height, resizable
timeout_seconds = 1
assert_timeout(timeout_seconds) do
new_window "Hello Wry", 100, 400, true, 1 # title, width, height, resizable
end
end

private

def assert_timeout(timeout_seconds, &block)
Timeout.timeout(timeout_seconds, &block)
rescue Timeout::Error
raise "Window creation timed out after #{timeout_seconds}s."
end
end

0 comments on commit 3c82caa

Please sign in to comment.