From 3c82caa7a6488877571cbdecc0d1ed61122ea585 Mon Sep 17 00:00:00 2001 From: gintama91 Date: Wed, 12 Jul 2023 22:30:41 +0530 Subject: [PATCH] ci-checking --- .github/workflows/main.yml | 14 ++++++- .rubocop.yml | 3 +- ext/wry_ruby/src/application/window.rs | 56 ++++++++++++++------------ test/test_wry_ruby.rb | 20 ++++++--- 4 files changed, 57 insertions(+), 36 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cd15cfc..147fc71 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,10 +1,11 @@ -name: Ruby +name: Trying with Xvfb on: push: branches: - main - dev + - ci-dev pull_request: jobs: @@ -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 diff --git a/.rubocop.yml b/.rubocop.yml index e3462a7..c3bfaf6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,8 +2,7 @@ AllCops: TargetRubyVersion: 2.6 Style/StringLiterals: - Enabled: true - EnforcedStyle: double_quotes + Enabled: false Style/StringLiteralsInInterpolation: Enabled: true diff --git a/ext/wry_ruby/src/application/window.rs b/ext/wry_ruby/src/application/window.rs index 5f670ef..2ee2655 100644 --- a/ext/wry_ruby/src/application/window.rs +++ b/ext/wry_ruby/src/application/window.rs @@ -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"); @@ -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(()) -} \ No newline at end of file +} diff --git a/test/test_wry_ruby.rb b/test/test_wry_ruby.rb index daccf72..27b562a 100644 --- a/test/test_wry_ruby.rb +++ b/test/test_wry_ruby.rb @@ -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