ozdenui 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/ozdenui/dialogs.rb +14 -0
- data/lib/ozdenui/hidden_process.rb +86 -0
- data/lib/ozdenui/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2089fa60697ded84fc50e606d992978d42232cd7bfc62550e859fc80ffadb5b4
|
|
4
|
+
data.tar.gz: 7280802b11086200fc87fc762ecc83274bd10af41217c258f75057340b99f249
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e2d8520a0022ddb3ddc27bb0f06b7283cfccd5b8e7272977f551f7da199fddf431c0bcbc099445d16f6db6a87e9c869ff15a1c9973ad2d457814d127a6a521a8
|
|
7
|
+
data.tar.gz: 31421ed6bb2f6f6b937d97ca2b39a81f2779741cbd01628048e259072a3427b72f02a3eca1e3ae4da71cba5e0fc2e2704d300e3a8cd20e2064db1155c3764892
|
data/README.md
CHANGED
|
@@ -212,7 +212,7 @@ In a dark window every component takes its dark look by itself, and the plain ob
|
|
|
212
212
|
- A file dropped on a `FilePicker` gives its name, not its path on the computer; a click on it opens the file dialog
|
|
213
213
|
of the system, and those files have their paths (`picker.paths`).
|
|
214
214
|
- With Bundler on Ruby 3.5 or newer, add `gem "fiddle"` to the Gemfile (it left the default gems); without it the
|
|
215
|
-
window of macOS is the window of a browser.
|
|
215
|
+
window of macOS is the window of a browser, and a file dialog of Windows opens with a console window behind it.
|
|
216
216
|
- No hot reload: `ruby app.rb` again.
|
|
217
217
|
|
|
218
218
|
## Development
|
data/lib/ozdenui/dialogs.rb
CHANGED
|
@@ -58,6 +58,10 @@ module OzdenUI
|
|
|
58
58
|
app = OzdenUI.app
|
|
59
59
|
app.flush if app && app.app_thread? # what the program drew before the dialog is on the page
|
|
60
60
|
types = Array(types).map { |ending| ending.to_s.sub(/\A\./, "") }
|
|
61
|
+
if system_name == :windows
|
|
62
|
+
lines = windows_dialog(power_shell(kind, title, directory, file_name, types))
|
|
63
|
+
return lines if lines
|
|
64
|
+
end
|
|
61
65
|
command = case system_name
|
|
62
66
|
when :mac then ["osascript", "-e", apple_script(kind, title, directory, file_name, types)]
|
|
63
67
|
when :windows then ["powershell", "-NoProfile", "-STA", "-Command", power_shell(kind, title, directory, file_name, types)]
|
|
@@ -70,6 +74,16 @@ module OzdenUI
|
|
|
70
74
|
[]
|
|
71
75
|
end
|
|
72
76
|
|
|
77
|
+
# The lines of the dialog of Windows, started without a console window (hidden_process.rb); nil when fiddle
|
|
78
|
+
# could not be used (then Open3 starts it, as before).
|
|
79
|
+
def windows_dialog(script)
|
|
80
|
+
require_relative "hidden_process"
|
|
81
|
+
HiddenProcess.run_power_shell(script)
|
|
82
|
+
rescue LoadError, Fiddle::DLError => error
|
|
83
|
+
$stderr.puts "ozdenui: the file dialog opens with a console window (#{error.message})"
|
|
84
|
+
nil
|
|
85
|
+
end
|
|
86
|
+
|
|
73
87
|
def quoted(text)
|
|
74
88
|
%("#{text.to_s.gsub('\\') { '\\\\' }.gsub('"') { '\\"' }}")
|
|
75
89
|
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Bismillah
|
|
2
|
+
#
|
|
3
|
+
# hidden_process.rb - ozdenui v0.1 (OzdenUI: basic.js for Ruby)
|
|
4
|
+
# Windows: a PowerShell script run without a console window, its output read back. Used by the file dialogs.
|
|
5
|
+
# WHY: a program without a console (rubyw, a .rbw file opened with a double click) got a new console window behind
|
|
6
|
+
# every file dialog: Open3 starts powershell as a console program, and Windows gives it a console of its own. Here
|
|
7
|
+
# CreateProcessW starts it with CREATE_NO_WINDOW (fiddle, the library of Ruby that calls the functions of the system).
|
|
8
|
+
# The script comes as -EncodedCommand (no quoting of the command line) and writes its lines into a file in UTF-8.
|
|
9
|
+
#
|
|
10
|
+
# Started Date: November 2026
|
|
11
|
+
# Webpage: https://bug7a.github.io/ozdenui-ruby/
|
|
12
|
+
#
|
|
13
|
+
# Copyright 2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
14
|
+
# Licensed under the Apache License, Version 2.0
|
|
15
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
17
|
+
require "fiddle"
|
|
18
|
+
require "tmpdir"
|
|
19
|
+
require "securerandom"
|
|
20
|
+
|
|
21
|
+
module OzdenUI
|
|
22
|
+
module Runtime
|
|
23
|
+
# @api private
|
|
24
|
+
module HiddenProcess
|
|
25
|
+
module_function
|
|
26
|
+
|
|
27
|
+
CREATE_NO_WINDOW = 0x08000000
|
|
28
|
+
WAIT_FOREVER = -1 # INFINITE (0xFFFFFFFF) as the signed 32-bit int of the call
|
|
29
|
+
# The sizes of STARTUPINFOW and PROCESS_INFORMATION in a 64-bit and in a 32-bit Ruby
|
|
30
|
+
STARTUP_INFO_SIZE = (Fiddle::SIZEOF_VOIDP == 8) ? 104 : 68
|
|
31
|
+
PROCESS_INFO_SIZE = (Fiddle::SIZEOF_VOIDP * 2) + 8
|
|
32
|
+
|
|
33
|
+
# The lines the script wrote, [] when it wrote none (a cancelled dialog).
|
|
34
|
+
def run_power_shell(script)
|
|
35
|
+
output = File.join(Dir.tmpdir, "ozdenui-#{SecureRandom.hex(6)}.txt")
|
|
36
|
+
run(command_line(script, output))
|
|
37
|
+
return [] unless File.exist?(output)
|
|
38
|
+
File.read(output, encoding: "UTF-8").split(/\r?\n/).map(&:strip).reject(&:empty?)
|
|
39
|
+
ensure
|
|
40
|
+
File.delete(output) if output && File.exist?(output)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# The command line of powershell; the script writes what it gives into the file at the path output.
|
|
44
|
+
def command_line(script, output)
|
|
45
|
+
quoted = output.gsub("'", "''")
|
|
46
|
+
whole = "$lines = & { #{script} }; " \
|
|
47
|
+
"if ($lines) { [IO.File]::WriteAllLines('#{quoted}', [string[]]$lines, (New-Object Text.UTF8Encoding $false)) }"
|
|
48
|
+
encoded = [whole.encode("UTF-16LE")].pack("m0")
|
|
49
|
+
"powershell.exe -NoProfile -NonInteractive -STA -EncodedCommand #{encoded}"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Starts the command without a window and waits until it ends.
|
|
53
|
+
# WHY the wait does not stop the program: a call of fiddle leaves Ruby free, so the server and the other threads
|
|
54
|
+
# go on while the dialog is open.
|
|
55
|
+
def run(command)
|
|
56
|
+
bytes = command.encode("UTF-16LE").b + "\0\0".b
|
|
57
|
+
line = Fiddle::Pointer.malloc(bytes.bytesize, Fiddle::RUBY_FREE)
|
|
58
|
+
line[0, bytes.bytesize] = bytes
|
|
59
|
+
startup = Fiddle::Pointer.malloc(STARTUP_INFO_SIZE, Fiddle::RUBY_FREE)
|
|
60
|
+
startup[0, STARTUP_INFO_SIZE] = "\0".b * STARTUP_INFO_SIZE
|
|
61
|
+
startup[0, 4] = [STARTUP_INFO_SIZE].pack("L")
|
|
62
|
+
process = Fiddle::Pointer.malloc(PROCESS_INFO_SIZE, Fiddle::RUBY_FREE)
|
|
63
|
+
process[0, PROCESS_INFO_SIZE] = "\0".b * PROCESS_INFO_SIZE
|
|
64
|
+
started = functions[:create].call(nil, line, nil, nil, 0, CREATE_NO_WINDOW, nil, nil, startup, process)
|
|
65
|
+
raise SystemCallError.new("CreateProcessW", Fiddle.win32_last_error.to_i) if started.zero?
|
|
66
|
+
handles = process[0, Fiddle::SIZEOF_VOIDP * 2].unpack((Fiddle::SIZEOF_VOIDP == 8) ? "Q2" : "L2")
|
|
67
|
+
functions[:wait].call(handles[0], WAIT_FOREVER)
|
|
68
|
+
handles.each { |handle| functions[:close].call(handle) }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def functions
|
|
72
|
+
@functions ||= begin
|
|
73
|
+
kernel = Fiddle.dlopen("kernel32")
|
|
74
|
+
pointer = Fiddle::TYPE_VOIDP
|
|
75
|
+
{
|
|
76
|
+
create: Fiddle::Function.new(kernel["CreateProcessW"],
|
|
77
|
+
[pointer, pointer, pointer, pointer, Fiddle::TYPE_INT, Fiddle::TYPE_INT,
|
|
78
|
+
pointer, pointer, pointer, pointer], Fiddle::TYPE_INT),
|
|
79
|
+
wait: Fiddle::Function.new(kernel["WaitForSingleObject"], [pointer, Fiddle::TYPE_INT], Fiddle::TYPE_INT),
|
|
80
|
+
close: Fiddle::Function.new(kernel["CloseHandle"], [pointer], Fiddle::TYPE_INT),
|
|
81
|
+
}
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
data/lib/ozdenui/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ozdenui
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bugra Ozden
|
|
@@ -35,6 +35,7 @@ files:
|
|
|
35
35
|
- lib/ozdenui/components.rb
|
|
36
36
|
- lib/ozdenui/dialogs.rb
|
|
37
37
|
- lib/ozdenui/files.rb
|
|
38
|
+
- lib/ozdenui/hidden_process.rb
|
|
38
39
|
- lib/ozdenui/icon.png
|
|
39
40
|
- lib/ozdenui/kit.json
|
|
40
41
|
- lib/ozdenui/kit.rb
|