From 7eb2b6d8ba5d1e16498a7f76b7833e98643d84bd Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 9 Nov 2023 13:31:32 -0800 Subject: [PATCH] Make thread_tk.rb check whether tk already set to run on main thread This makes loading thread_tk error if tk has already been loaded, unless it was already loaded and has already been set not to run the event loop on the main thread. --- lib/thread_tk.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/thread_tk.rb b/lib/thread_tk.rb index 57be25c..69ed938 100644 --- a/lib/thread_tk.rb +++ b/lib/thread_tk.rb @@ -4,5 +4,10 @@ # main thread. That is, when "require 'thread_tk'" is executed instead # of or before "require 'tk'", "Thread.new{Tk.mainloop}" works properly. # + +if defined?(TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD) && TkCore::RUN_EVENTLOOP_ON_MAIN_THREAD + raise LoadError, "thread_tk.rb must be loaded before tk.rb" +end + module TkCore; RUN_EVENTLOOP_ON_MAIN_THREAD = false; end require 'tk'