Partially revert ask_file/folder on linux to explicitly use zenity/kdialog commands directly instead of using libui hack which leaves the file browser window open after returning

This commit is contained in:
2024-03-12 09:21:52 -05:00
parent 6d209c8942
commit 3f7ec2fb5c
4 changed files with 62 additions and 18 deletions

View File

@@ -4,15 +4,15 @@ gem "base64"
gem "excon" gem "excon"
gem "cyberarm_engine" gem "cyberarm_engine"
gem "sdl2-bindings" gem "sdl2-bindings"
gem "libui" gem "libui", platforms: [:windows]
gem "digest-crc" gem "digest-crc"
gem "i18n" gem "i18n"
gem "ircparser" gem "ircparser"
gem "rexml" gem "rexml"
gem "rubyzip" gem "rubyzip"
gem "websocket-client-simple" gem "websocket-client-simple"
gem "win32-process", platforms: [:x64_mingw, :mingw] gem "win32-process", platforms: [:windows]
gem "win32-security", platforms: [:x64_mingw, :mingw] gem "win32-security", platforms: [:windows]
# PACKAGING NOTES # PACKAGING NOTES
# bundler 2.5.x doesn't seem to play nice with ocra[n] # bundler 2.5.x doesn't seem to play nice with ocra[n]

View File

@@ -10,10 +10,11 @@ GEM
event_emitter (0.2.6) event_emitter (0.2.6)
excon (0.109.0) excon (0.109.0)
ffi (1.16.3) ffi (1.16.3)
ffi (1.16.3-x64-mingw-ucrt)
ffi-win32-extensions (1.0.4) ffi-win32-extensions (1.0.4)
ffi ffi
gosu (1.4.6) gosu (1.4.6)
i18n (1.14.1) i18n (1.14.4)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
ircparser (1.0.0) ircparser (1.0.0)
libui (0.0.15) libui (0.0.15)
@@ -34,6 +35,7 @@ GEM
PLATFORMS PLATFORMS
x64-mingw-ucrt x64-mingw-ucrt
x86_64-linux
DEPENDENCIES DEPENDENCIES
base64 base64

View File

@@ -147,16 +147,56 @@ class W3DHub
end end
def self.ask_file(title: "Open File", filter: "*game*.exe") def self.ask_file(title: "Open File", filter: "*game*.exe")
if W3DHub.unix?
# search for command
cmds = %w{ zenity matedialog qarma kdialog }
command = cmds.find do |cmd|
cmd if system("which #{cmd}")
end
path = case File.basename(command)
when "zenity", "matedialog", "qarma"
`#{command} --file-selection --title "#{title}" --file-filter "#{filter}"`
when "kdialog"
`#{command} --title "#{title}" --getopenfilename . "#{filter}"`
else
raise "No known command found for system file selection dialog!"
end
path.strip
else
result_ptr = LibUI.open_file(LIBUI_WINDOW) result_ptr = LibUI.open_file(LIBUI_WINDOW)
result = result_ptr.null? ? "" : result_ptr.to_s.gsub("\\", "/") result = result_ptr.null? ? "" : result_ptr.to_s.gsub("\\", "/")
result result.strip
end
end end
def self.ask_folder(title: "Open Folder") def self.ask_folder(title: "Open Folder")
result_ptr = LibUI.open_folder(window) if W3DHub.unix?
result = result_ptr.null? ? "" : result_ptr.to_s.gsub("\\", "/") # search for command
cmds = %w{ zenity matedialog qarma kdialog }
result command = cmds.find do |cmd|
cmd if system("which #{cmd}")
end
path = case File.basename(command)
when "zenity", "matedialog", "qarma"
`#{command} --file-selection --directory --title "#{title} #{Dir.home}"`
when "kdialog"
`#{command} --title "#{title}" --getexistingdirectory #{Dir.home}"`
else
raise "No known command found for system file selection dialog!"
end
path.strip
else
result_ptr = LibUI.open_folder(window)
result = result_ptr.null? ? "" : result_ptr.to_s.gsub("\\", "/")
result.strip
end
end end
end end

View File

@@ -80,15 +80,6 @@ require "i18n"
require "websocket-client-simple" require "websocket-client-simple"
require "English" require "English"
require "sdl2" require "sdl2"
require "libui"
# Using a WHOLE ui library for: native file/folder open dialogs...
LibUI.init
LIBUI_WINDOW = LibUI.new_window("", 100, 100, 0)
at_exit do
LibUI.control_destroy(LIBUI_WINDOW)
LibUI.uninit
end
I18n.load_path << Dir["#{W3DHub::GAME_ROOT_PATH}/locales/*.yml"] I18n.load_path << Dir["#{W3DHub::GAME_ROOT_PATH}/locales/*.yml"]
I18n.default_locale = :en I18n.default_locale = :en
@@ -158,7 +149,18 @@ require_relative "lib/asterisk/states/game_form"
require_relative "lib/asterisk/states/irc_profile_form" require_relative "lib/asterisk/states/irc_profile_form"
require_relative "lib/asterisk/states/server_profile_form" require_relative "lib/asterisk/states/server_profile_form"
require "win32/process" if W3DHub.windows? if W3DHub.windows?
require "libui"
require "win32/process"
# Using a WHOLE ui library for: native file/folder open dialogs...
LibUI.init
LIBUI_WINDOW = LibUI.new_window("", 100, 100, 0)
at_exit do
LibUI.control_destroy(LIBUI_WINDOW)
LibUI.uninit
end
end
logger.info(W3DHub::LOG_TAG) { "W3D Hub Linux Launcher v#{W3DHub::VERSION}" } logger.info(W3DHub::LOG_TAG) { "W3D Hub Linux Launcher v#{W3DHub::VERSION}" }