ozdenui 0.1.0

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.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +14 -0
  3. data/NOTICE +5 -0
  4. data/README.md +242 -0
  5. data/exe/ozdenui +17 -0
  6. data/lib/ozdenui/AGENTS.md +210 -0
  7. data/lib/ozdenui/COMPONENTS.md +3017 -0
  8. data/lib/ozdenui/app.rb +749 -0
  9. data/lib/ozdenui/command.rb +107 -0
  10. data/lib/ozdenui/components.rb +368 -0
  11. data/lib/ozdenui/dialogs.rb +212 -0
  12. data/lib/ozdenui/files.rb +124 -0
  13. data/lib/ozdenui/icon.png +0 -0
  14. data/lib/ozdenui/kit.json +1 -0
  15. data/lib/ozdenui/kit.rb +115 -0
  16. data/lib/ozdenui/look.rb +229 -0
  17. data/lib/ozdenui/objects.rb +652 -0
  18. data/lib/ozdenui/server.rb +270 -0
  19. data/lib/ozdenui/values.rb +273 -0
  20. data/lib/ozdenui/version.rb +15 -0
  21. data/lib/ozdenui/web/basic/LICENSE +14 -0
  22. data/lib/ozdenui/web/basic/basic.min.css +1 -0
  23. data/lib/ozdenui/web/basic/basic.min.js +78 -0
  24. data/lib/ozdenui/web/basic/font/open-sans/LICENSE.txt +206 -0
  25. data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
  26. data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
  27. data/lib/ozdenui/web/basic/scroll-bar.min.js +3 -0
  28. data/lib/ozdenui/web/bridge.js +584 -0
  29. data/lib/ozdenui/web/comp/accordion.js +659 -0
  30. data/lib/ozdenui/web/comp/action-button/add.png +0 -0
  31. data/lib/ozdenui/web/comp/action-button.js +521 -0
  32. data/lib/ozdenui/web/comp/action-tab-bar.js +383 -0
  33. data/lib/ozdenui/web/comp/app-bar.js +237 -0
  34. data/lib/ozdenui/web/comp/badge.js +292 -0
  35. data/lib/ozdenui/web/comp/bottom-bar.js +555 -0
  36. data/lib/ozdenui/web/comp/breadcrumbs.js +524 -0
  37. data/lib/ozdenui/web/comp/canvas.js +652 -0
  38. data/lib/ozdenui/web/comp/chat-view.js +827 -0
  39. data/lib/ozdenui/web/comp/check-box.js +490 -0
  40. data/lib/ozdenui/web/comp/code-editor.js +965 -0
  41. data/lib/ozdenui/web/comp/color-picker.js +636 -0
  42. data/lib/ozdenui/web/comp/context-menu.js +951 -0
  43. data/lib/ozdenui/web/comp/currency-field.js +209 -0
  44. data/lib/ozdenui/web/comp/data-table/arrow.svg +2 -0
  45. data/lib/ozdenui/web/comp/data-table.js +937 -0
  46. data/lib/ozdenui/web/comp/date-picker.js +1055 -0
  47. data/lib/ozdenui/web/comp/dialog.js +992 -0
  48. data/lib/ozdenui/web/comp/email-field.js +65 -0
  49. data/lib/ozdenui/web/comp/file-picker.js +920 -0
  50. data/lib/ozdenui/web/comp/filters.js +807 -0
  51. data/lib/ozdenui/web/comp/form.js +602 -0
  52. data/lib/ozdenui/web/comp/full-screen-select/arrow.svg +2 -0
  53. data/lib/ozdenui/web/comp/full-screen-select/cancel.svg +2 -0
  54. data/lib/ozdenui/web/comp/full-screen-select.js +614 -0
  55. data/lib/ozdenui/web/comp/gauge.js +439 -0
  56. data/lib/ozdenui/web/comp/graph-box.js +3911 -0
  57. data/lib/ozdenui/web/comp/grid-group.js +185 -0
  58. data/lib/ozdenui/web/comp/hold-to-confirm-button/trash-red.png +0 -0
  59. data/lib/ozdenui/web/comp/hold-to-confirm-button/trash.png +0 -0
  60. data/lib/ozdenui/web/comp/hold-to-confirm-button.js +289 -0
  61. data/lib/ozdenui/web/comp/image-view.js +598 -0
  62. data/lib/ozdenui/web/comp/item-list.js +1740 -0
  63. data/lib/ozdenui/web/comp/json-editor.js +3221 -0
  64. data/lib/ozdenui/web/comp/json-view.js +597 -0
  65. data/lib/ozdenui/web/comp/label-editor.js +1140 -0
  66. data/lib/ozdenui/web/comp/left-menu/data-table.png +0 -0
  67. data/lib/ozdenui/web/comp/left-menu/home.png +0 -0
  68. data/lib/ozdenui/web/comp/left-menu/reports.png +0 -0
  69. data/lib/ozdenui/web/comp/left-menu/setting.png +0 -0
  70. data/lib/ozdenui/web/comp/left-menu.js +548 -0
  71. data/lib/ozdenui/web/comp/line-progress-bar.js +343 -0
  72. data/lib/ozdenui/web/comp/loading-screen.js +413 -0
  73. data/lib/ozdenui/web/comp/log-view.js +530 -0
  74. data/lib/ozdenui/web/comp/login-page.js +685 -0
  75. data/lib/ozdenui/web/comp/markdown-view.js +1045 -0
  76. data/lib/ozdenui/web/comp/menu-bar.js +624 -0
  77. data/lib/ozdenui/web/comp/mini-graph-box.js +492 -0
  78. data/lib/ozdenui/web/comp/minimal-accent.js +208 -0
  79. data/lib/ozdenui/web/comp/notice.js +229 -0
  80. data/lib/ozdenui/web/comp/number-field.js +128 -0
  81. data/lib/ozdenui/web/comp/numeric-keyboard.js +298 -0
  82. data/lib/ozdenui/web/comp/page-control.js +762 -0
  83. data/lib/ozdenui/web/comp/page-header.js +191 -0
  84. data/lib/ozdenui/web/comp/password-field/hide-btn.png +0 -0
  85. data/lib/ozdenui/web/comp/password-field/hide-btn2.png +0 -0
  86. data/lib/ozdenui/web/comp/password-field/show-btn.png +0 -0
  87. data/lib/ozdenui/web/comp/password-field/show-btn2.png +0 -0
  88. data/lib/ozdenui/web/comp/password-field.js +192 -0
  89. data/lib/ozdenui/web/comp/period-bar.js +436 -0
  90. data/lib/ozdenui/web/comp/phone-field.js +322 -0
  91. data/lib/ozdenui/web/comp/progress-bar.js +992 -0
  92. data/lib/ozdenui/web/comp/property-panel.js +3639 -0
  93. data/lib/ozdenui/web/comp/radio-button.js +527 -0
  94. data/lib/ozdenui/web/comp/range-slider.js +569 -0
  95. data/lib/ozdenui/web/comp/rich-text-editor.js +1064 -0
  96. data/lib/ozdenui/web/comp/scroll-area.js +308 -0
  97. data/lib/ozdenui/web/comp/scrolling-text.js +297 -0
  98. data/lib/ozdenui/web/comp/search-input/clear-round.svg +1 -0
  99. data/lib/ozdenui/web/comp/search-input/clear.svg +1 -0
  100. data/lib/ozdenui/web/comp/search-input/filter.png +0 -0
  101. data/lib/ozdenui/web/comp/search-input/filter.svg +1 -0
  102. data/lib/ozdenui/web/comp/search-input/search.svg +1 -0
  103. data/lib/ozdenui/web/comp/search-input.js +725 -0
  104. data/lib/ozdenui/web/comp/search-results.js +596 -0
  105. data/lib/ozdenui/web/comp/select-box.js +1862 -0
  106. data/lib/ozdenui/web/comp/settings-row.js +299 -0
  107. data/lib/ozdenui/web/comp/side-panel.js +616 -0
  108. data/lib/ozdenui/web/comp/slider-field.js +952 -0
  109. data/lib/ozdenui/web/comp/slider.js +838 -0
  110. data/lib/ozdenui/web/comp/smart-button/alert-black.png +0 -0
  111. data/lib/ozdenui/web/comp/smart-button/clock.png +0 -0
  112. data/lib/ozdenui/web/comp/smart-button.js +981 -0
  113. data/lib/ozdenui/web/comp/smart-table/clock.png +0 -0
  114. data/lib/ozdenui/web/comp/smart-table/down.png +0 -0
  115. data/lib/ozdenui/web/comp/smart-table/scroll.png +0 -0
  116. data/lib/ozdenui/web/comp/smart-table/sort.png +0 -0
  117. data/lib/ozdenui/web/comp/smart-table/up.png +0 -0
  118. data/lib/ozdenui/web/comp/smart-table.js +1883 -0
  119. data/lib/ozdenui/web/comp/sortable-list.js +1181 -0
  120. data/lib/ozdenui/web/comp/spark-line-box.js +738 -0
  121. data/lib/ozdenui/web/comp/splitter.js +411 -0
  122. data/lib/ozdenui/web/comp/status-bar.js +408 -0
  123. data/lib/ozdenui/web/comp/step-bar.js +345 -0
  124. data/lib/ozdenui/web/comp/stepper.js +753 -0
  125. data/lib/ozdenui/web/comp/tabs.js +1366 -0
  126. data/lib/ozdenui/web/comp/tag-input.js +1107 -0
  127. data/lib/ozdenui/web/comp/tap-effect.js +170 -0
  128. data/lib/ozdenui/web/comp/text-area-field.js +233 -0
  129. data/lib/ozdenui/web/comp/text-field.js +1006 -0
  130. data/lib/ozdenui/web/comp/time-line.js +398 -0
  131. data/lib/ozdenui/web/comp/time-picker.js +1032 -0
  132. data/lib/ozdenui/web/comp/tiny-select/arrow.svg +1 -0
  133. data/lib/ozdenui/web/comp/tiny-select.js +322 -0
  134. data/lib/ozdenui/web/comp/tiny-table.js +283 -0
  135. data/lib/ozdenui/web/comp/toast.js +891 -0
  136. data/lib/ozdenui/web/comp/toggle.js +757 -0
  137. data/lib/ozdenui/web/comp/tool-bar.js +760 -0
  138. data/lib/ozdenui/web/comp/tooltip.js +534 -0
  139. data/lib/ozdenui/web/comp/tree-view.js +1179 -0
  140. data/lib/ozdenui/web/comp/ui-effects.js +1097 -0
  141. data/lib/ozdenui/web/comp/ui-standards.js +403 -0
  142. data/lib/ozdenui/web/comp/url-field.js +190 -0
  143. data/lib/ozdenui/web/comp/web-view.js +588 -0
  144. data/lib/ozdenui/web/components.js +123 -0
  145. data/lib/ozdenui/web/index.html +39 -0
  146. data/lib/ozdenui/window.rb +188 -0
  147. data/lib/ozdenui/window_cocoa.rb +221 -0
  148. data/lib/ozdenui.rb +32 -0
  149. metadata +200 -0
@@ -0,0 +1,123 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ components.js - ozdenui v0.1 (OzdenUI: basic.js for Ruby)
6
+ Every component of comp/ for the loader of bridge.js.
7
+
8
+ name: [file, [the components it needs, loaded before it]]. "needs" also has the optional ones that turn a feature
9
+ on (Ex: SearchInput for the filter of a SmartTable). bridge.js loads a component with what it needs when the program
10
+ first names it.
11
+
12
+ Started Date: November 2026
13
+ Webpage: https://bug7a.github.io/ozdenui-ruby/
14
+
15
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
16
+ Licensed under the Apache License, Version 2.0
17
+ SPDX-License-Identifier: Apache-2.0
18
+
19
+ */
20
+
21
+ "use strict";
22
+
23
+ window.__bpComponents = (function () {
24
+
25
+ const LIST = {
26
+ ScrollBar: ["basic/scroll-bar.min.js", []],
27
+ Accordion: ["comp/accordion.js", ["ScrollBar"]],
28
+ ActionButton: ["comp/action-button.js", []],
29
+ ActionTabBar: ["comp/action-tab-bar.js", []],
30
+ AppBar: ["comp/app-bar.js", ["SmartButton"]],
31
+ Badge: ["comp/badge.js", []],
32
+ BottomBar: ["comp/bottom-bar.js", ["Badge"]],
33
+ Breadcrumbs: ["comp/breadcrumbs.js", []],
34
+ Canvas: ["comp/canvas.js", []],
35
+ ChatView: ["comp/chat-view.js", ["MarkdownView", "ScrollArea", "CodeEditor", "ScrollBar"]],
36
+ CheckBox: ["comp/check-box.js", []],
37
+ CodeEditor: ["comp/code-editor.js", []],
38
+ ColorPicker: ["comp/color-picker.js", []],
39
+ ContextMenu: ["comp/context-menu.js", []],
40
+ CurrencyField: ["comp/currency-field.js", ["TextField"]],
41
+ DataTable: ["comp/data-table.js", ["SearchInput", "ScrollBar"]],
42
+ DatePicker: ["comp/date-picker.js", []],
43
+ Dialog: ["comp/dialog.js", ["SmartButton", "TextField"]],
44
+ EmailField: ["comp/email-field.js", ["TextField"]],
45
+ FilePicker: ["comp/file-picker.js", []],
46
+ Filters: ["comp/filters.js", ["SearchInput", "CheckBox", "ScrollBar"]],
47
+ Form: ["comp/form.js", ["Tooltip", "ScrollBar"]],
48
+ FullScreenSelect: ["comp/full-screen-select.js", ["SearchInput", "ScrollBar"]],
49
+ Gauge: ["comp/gauge.js", []],
50
+ GraphBox: ["comp/graph-box.js", []],
51
+ GridGroup: ["comp/grid-group.js", []],
52
+ HoldToConfirmButton: ["comp/hold-to-confirm-button.js", []],
53
+ ImageView: ["comp/image-view.js", []],
54
+ ItemList: ["comp/item-list.js", ["SearchInput", "ScrollBar"]],
55
+ JsonEditor: ["comp/json-editor.js", ["ContextMenu", "SearchInput"]],
56
+ JsonView: ["comp/json-view.js", ["TreeView", "ContextMenu"]],
57
+ LabelEditor: ["comp/label-editor.js", ["SidePanel", "Stepper", "ColorPicker", "Tabs", "CheckBox", "ScrollBar"]],
58
+ LeftMenu: ["comp/left-menu.js", ["ScrollBar"]],
59
+ LineProgressBar: ["comp/line-progress-bar.js", ["Tooltip"]],
60
+ LoadingScreen: ["comp/loading-screen.js", ["SmartButton"]],
61
+ LogView: ["comp/log-view.js", ["ScrollBar"]],
62
+ LoginPage: ["comp/login-page.js", ["UIEffects", "Tooltip", "TextField", "EmailField", "PasswordField", "Tabs", "SmartButton", "LoadingScreen"]],
63
+ MarkdownView: ["comp/markdown-view.js", ["CodeEditor", "ScrollBar"]],
64
+ MenuBar: ["comp/menu-bar.js", ["ContextMenu"]],
65
+ MinimalAccent: ["comp/minimal-accent.js", []],
66
+ MiniGraphBox: ["comp/mini-graph-box.js", []],
67
+ Notice: ["comp/notice.js", []],
68
+ NumberField: ["comp/number-field.js", ["TextField"]],
69
+ NumericKeyboard: ["comp/numeric-keyboard.js", []],
70
+ PageControl: ["comp/page-control.js", []],
71
+ PageHeader: ["comp/page-header.js", []],
72
+ PasswordField: ["comp/password-field.js", ["TextField", "Tooltip"]],
73
+ PeriodBar: ["comp/period-bar.js", []],
74
+ PhoneField: ["comp/phone-field.js", ["TextField"]],
75
+ ProgressBar: ["comp/progress-bar.js", []],
76
+ PropertyPanel: ["comp/property-panel.js", ["ContextMenu", "ScrollBar"]],
77
+ RadioButton: ["comp/radio-button.js", []],
78
+ RangeSlider: ["comp/range-slider.js", []],
79
+ RichTextEditor: ["comp/rich-text-editor.js", ["ScrollBar"]],
80
+ ScrollArea: ["comp/scroll-area.js", ["ScrollBar"]],
81
+ ScrollingText: ["comp/scrolling-text.js", []],
82
+ SearchInput: ["comp/search-input.js", []],
83
+ SearchResults: ["comp/search-results.js", ["ScrollBar"]],
84
+ SelectBox: ["comp/select-box.js", ["SearchInput", "ItemList", "ScrollBar"]],
85
+ SettingsRow: ["comp/settings-row.js", ["Toggle"]],
86
+ SidePanel: ["comp/side-panel.js", []],
87
+ Slider: ["comp/slider.js", []],
88
+ SliderField: ["comp/slider-field.js", []],
89
+ SmartButton: ["comp/smart-button.js", ["Tooltip"]],
90
+ SmartTable: ["comp/smart-table.js", ["Tooltip", "SearchInput", "ScrollBar", "ContextMenu"]],
91
+ SortableList: ["comp/sortable-list.js", ["ScrollBar"]],
92
+ SparkLineBox: ["comp/spark-line-box.js", []],
93
+ Splitter: ["comp/splitter.js", []],
94
+ StatusBar: ["comp/status-bar.js", []],
95
+ StepBar: ["comp/step-bar.js", []],
96
+ Stepper: ["comp/stepper.js", []],
97
+ Tabs: ["comp/tabs.js", []],
98
+ TagInput: ["comp/tag-input.js", []],
99
+ TapEffect: ["comp/tap-effect.js", []],
100
+ TextAreaField: ["comp/text-area-field.js", ["TextField", "ScrollBar"]],
101
+ TextField: ["comp/text-field.js", ["Tooltip"]],
102
+ TimeLine: ["comp/time-line.js", []],
103
+ TimePicker: ["comp/time-picker.js", ["ScrollBar"]],
104
+ TinySelect: ["comp/tiny-select.js", []],
105
+ TinyTable: ["comp/tiny-table.js", ["ScrollingText", "ScrollBar"]],
106
+ Toast: ["comp/toast.js", []],
107
+ Toggle: ["comp/toggle.js", []],
108
+ ToolBar: ["comp/tool-bar.js", ["Tooltip", "ContextMenu", "MenuBar"]],
109
+ Tooltip: ["comp/tooltip.js", []],
110
+ TreeView: ["comp/tree-view.js", ["ScrollBar"]],
111
+ UIEffects: ["comp/ui-effects.js", []],
112
+ UI: ["comp/ui-standards.js", []],
113
+ UrlField: ["comp/url-field.js", ["TextField", "TinySelect"]],
114
+ WebView: ["comp/web-view.js", []],
115
+ };
116
+
117
+ const components = {};
118
+ Object.keys(LIST).forEach(function (name) {
119
+ components[name] = { file: LIST[name][0], needs: LIST[name][1] };
120
+ });
121
+ return components;
122
+
123
+ })();
@@ -0,0 +1,39 @@
1
+ <!DOCTYPE html>
2
+ <!-- Bismillah -->
3
+ <!--
4
+
5
+ index.html - ozdenui v0.1 (OzdenUI: basic.js for Ruby)
6
+ The page of the window: basic.js, the bridge that runs the commands of the Ruby program, and the components of comp/ it loads when they are named.
7
+
8
+ Started Date: November 2026
9
+ Webpage: https://bug7a.github.io/ozdenui-ruby/
10
+
11
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
12
+ Licensed under the Apache License, Version 2.0
13
+ SPDX-License-Identifier: Apache-2.0
14
+
15
+ -->
16
+ <html lang="en">
17
+ <head>
18
+
19
+ <title>ozdenui</title>
20
+
21
+ <meta charset="UTF-8">
22
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
23
+
24
+ <!-- LIBRARY FILES (copied by update-web.sh) -->
25
+ <link rel="preload" href="basic/font/open-sans/OpenSans-Regular.ttf" as="font" crossorigin="anonymous">
26
+ <link rel="preload" href="basic/font/open-sans/OpenSans-Bold.ttf" as="font" crossorigin="anonymous">
27
+ <link rel="stylesheet" type="text/css" href="basic/basic.min.css">
28
+ <script src="basic/basic.min.js" type="text/javascript" charset="utf-8"></script>
29
+ <script src="basic/scroll-bar.min.js" type="text/javascript" charset="utf-8"></script>
30
+
31
+
32
+ <!-- THE BRIDGE: the commands of the program -> basic.js objects. It loads a component of comp/ when the program
33
+ first names it (components.js: its file and what it needs). -->
34
+ <script src="components.js" type="text/javascript" charset="utf-8"></script>
35
+ <script src="bridge.js" type="text/javascript" charset="utf-8"></script>
36
+
37
+ </head>
38
+ <body></body>
39
+ </html>
@@ -0,0 +1,188 @@
1
+ # Bismillah
2
+ #
3
+ # window.rb - ozdenui v0.1 (OzdenUI: basic.js for Ruby)
4
+ # Opens the window of the program and returns when it is closed: the web view of macOS (window_cocoa.rb), an app
5
+ # window of Chrome or Edge (no address bar, no tabs) or, for a picture or a check, a hidden browser (look.rb).
6
+ #
7
+ # OZDENUI_WINDOW: "browser" (an app window of Chrome or Edge also on macOS), "tab" (a tab of the default browser),
8
+ # "headless" (no window: a check). OZDENUI_BROWSER: the path of the browser. OZDENUI_LOOK: see look.rb.
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 "tmpdir"
18
+ require "fileutils"
19
+ require "rbconfig"
20
+
21
+ module OzdenUI
22
+ # What the gem is made of. A program uses the methods of OzdenUI; these classes are behind them.
23
+ module Runtime
24
+ # @api private
25
+ module Window
26
+ STREAM_GONE_AFTER = 1.5 # a page that does not listen this long is a closed window
27
+
28
+ module_function
29
+
30
+ def open(app, address)
31
+ mode = ENV["OZDENUI_WINDOW"].to_s
32
+ return Look.open(app, address) if !ENV["OZDENUI_LOOK"].to_s.empty? || mode == "headless"
33
+ return if mode.empty? && open_native(app, address)
34
+ BrowserWindow.new(app).open(address, mode == "tab")
35
+ end
36
+
37
+ # true when the window of the system was opened (and is closed now).
38
+ def open_native(app, address)
39
+ return false unless Dialogs.system_name == :mac
40
+ require_relative "window_cocoa"
41
+ CocoaWindow.new(app).open(address)
42
+ true
43
+ rescue LoadError, Fiddle::DLError => error
44
+ # WHY it goes on: without fiddle (a Ruby built without it, a Gemfile that does not list it) the program still
45
+ # works, in a window of the browser
46
+ $stderr.puts "ozdenui: the web view of macOS could not be used (#{error.message}): the window of a browser opens"
47
+ false
48
+ end
49
+
50
+ def cache_folder
51
+ base = case Dialogs.system_name
52
+ when :mac then File.join(Dir.home, "Library", "Caches")
53
+ when :windows then ENV["LOCALAPPDATA"] || Dir.tmpdir
54
+ else ENV["XDG_CACHE_HOME"] || File.join(Dir.home, ".cache")
55
+ end
56
+ File.join(base, "ozdenui")
57
+ rescue ArgumentError
58
+ File.join(Dir.tmpdir, "ozdenui")
59
+ end
60
+
61
+ def program_name
62
+ File.basename($PROGRAM_NAME, ".*").gsub(/[^A-Za-z0-9-]/, "_")
63
+ end
64
+
65
+ # A browser of this computer that opens an app window (Chromium kind): Edge is on every Windows.
66
+ def find_browser
67
+ given = ENV["OZDENUI_BROWSER"].to_s
68
+ return given unless given.empty?
69
+ candidates = []
70
+ case Dialogs.system_name
71
+ when :mac
72
+ ["Google Chrome", "Microsoft Edge", "Chromium", "Brave Browser"].each do |name|
73
+ candidates << "/Applications/#{name}.app/Contents/MacOS/#{name}"
74
+ candidates << File.join(Dir.home, "Applications", "#{name}.app", "Contents", "MacOS", name)
75
+ end
76
+ when :windows
77
+ [ENV["ProgramFiles(x86)"], ENV["ProgramFiles"], ENV["LocalAppData"]].compact.each do |root|
78
+ candidates << File.join(root, "Microsoft", "Edge", "Application", "msedge.exe")
79
+ candidates << File.join(root, "Google", "Chrome", "Application", "chrome.exe")
80
+ end
81
+ else
82
+ folders = ENV["PATH"].to_s.split(File::PATH_SEPARATOR)
83
+ %w[google-chrome google-chrome-stable chromium chromium-browser microsoft-edge brave-browser].each do |name|
84
+ folders.each { |folder| candidates << File.join(folder, name) }
85
+ end
86
+ end
87
+ candidates.find { |path| File.executable?(path) && !File.directory?(path) }
88
+ end
89
+
90
+ def open_in_default_browser(address)
91
+ command = case Dialogs.system_name
92
+ when :mac then ["open", address]
93
+ when :windows then ["rundll32", "url.dll,FileProtocolHandler", address]
94
+ else ["xdg-open", address]
95
+ end
96
+ Process.detach(Process.spawn(*command, out: File::NULL, err: File::NULL))
97
+ end
98
+ end
99
+
100
+ # A window of a browser.
101
+ # @api private
102
+ class BrowserWindow
103
+ def initialize(app)
104
+ @app = app
105
+ @done = Latch.new
106
+ @mutex = Mutex.new
107
+ @open_streams = 0
108
+ @gone_at = nil
109
+ end
110
+
111
+ def title=(_title); end # the page changes its own title (set_title)
112
+
113
+ def close
114
+ return if @closing
115
+ @closing = true
116
+ # WHY the page closes itself: the process of the browser may be one that was already open
117
+ Thread.new do
118
+ begin
119
+ @app.server.request("kind" => "eval", "script" => "window.close(); 0")
120
+ rescue PageGone, Error
121
+ nil
122
+ end
123
+ end
124
+ Thread.new do
125
+ sleep(0.3)
126
+ @done.set
127
+ end
128
+ end
129
+
130
+ def open(address, is_tab)
131
+ @app.control = self
132
+ watch_stream
133
+ browser = is_tab ? nil : Window.find_browser
134
+ pid = nil
135
+ if browser
136
+ # WHY a profile of the program: the browser is a process of its own then, which ends with the window (a
137
+ # browser that was already open would take the window into its process, with its tabs and its size)
138
+ profile = File.join(Window.cache_folder, "browser-profile-#{Window.program_name}")
139
+ begin
140
+ FileUtils.mkdir_p(profile)
141
+ pid = Process.spawn(browser, "--app=#{address}", "--window-size=#{@app.options[:width]},#{@app.options[:height]}",
142
+ "--user-data-dir=#{profile}", "--no-first-run", "--no-default-browser-check",
143
+ out: File::NULL, err: File::NULL)
144
+ rescue SystemCallError
145
+ pid = nil
146
+ end
147
+ end
148
+ unless pid
149
+ begin
150
+ Window.open_in_default_browser(address)
151
+ rescue SystemCallError => error
152
+ $stderr.puts "ozdenui: no browser could be opened (#{error.message}). The page of the program: #{address}"
153
+ end
154
+ end
155
+ @done.wait
156
+ ensure
157
+ end_process(pid) if pid # WHY: on macOS a browser without a window keeps running
158
+ end
159
+
160
+ private
161
+
162
+ def end_process(pid)
163
+ Process.kill(Dialogs.system_name == :windows ? "KILL" : "TERM", pid)
164
+ Process.detach(pid)
165
+ rescue SystemCallError
166
+ nil
167
+ end
168
+
169
+ # The window is closed when the page stopped listening and did not come back (a closed tab or window; a page that
170
+ # is loaded again comes back at once).
171
+ def watch_stream
172
+ @app.server.on_stream = lambda do |is_open|
173
+ @mutex.synchronize do
174
+ @open_streams += is_open ? 1 : -1
175
+ @gone_at = @open_streams.zero? ? Process.clock_gettime(Process::CLOCK_MONOTONIC) : nil
176
+ end
177
+ end
178
+ Thread.new do
179
+ until @done.set?
180
+ sleep(0.1)
181
+ gone_at = @mutex.synchronize { @gone_at }
182
+ @done.set if gone_at && Process.clock_gettime(Process::CLOCK_MONOTONIC) - gone_at > Window::STREAM_GONE_AFTER
183
+ end
184
+ end
185
+ end
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,221 @@
1
+ # Bismillah
2
+ #
3
+ # window_cocoa.rb - ozdenui v0.1 (OzdenUI: basic.js for Ruby)
4
+ # The window of macOS: a window of the system with its web view (WKWebView), made with fiddle, the library of Ruby
5
+ # that calls the functions of the system. No gem and no compiler are needed.
6
+ #
7
+ # The main thread runs the events of the window. WHY its own loop and not [NSApp run]: between two events it does the
8
+ # small jobs the other threads ask for (a title, a close) and sees that the window was closed; the calls of fiddle
9
+ # leave Ruby free, so the thread of the program and the server work meanwhile. A thread that has a job for the window
10
+ # posts an event of its own, so the loop sleeps until something happens (a loop that looked every 10 ms took a
11
+ # tenth of a CPU core in a window nobody touched).
12
+ #
13
+ # Started Date: November 2026
14
+ # Webpage: https://bug7a.github.io/ozdenui-ruby/
15
+ #
16
+ # Copyright 2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
17
+ # Licensed under the Apache License, Version 2.0
18
+ # SPDX-License-Identifier: Apache-2.0
19
+
20
+ require "fiddle"
21
+
22
+ module OzdenUI
23
+ # What the gem is made of. A program uses the methods of OzdenUI; these classes are behind them.
24
+ module Runtime
25
+ # @api private
26
+ class CocoaWindow
27
+ POINTER = Fiddle::TYPE_VOIDP
28
+ DOUBLE = Fiddle::TYPE_DOUBLE
29
+ LONG = Fiddle::TYPE_LONG
30
+ BOOL = Fiddle::TYPE_CHAR
31
+ VOID = Fiddle::TYPE_VOID
32
+ EVENT_WAIT = 0.5 # seconds the loop sleeps at most (Ctrl+C in the terminal is seen when it wakes)
33
+ APPLICATION_EVENT = 15 # NSEventTypeApplicationDefined: the event that wakes the loop for a job
34
+ EVENT_TYPES = [LONG, DOUBLE, DOUBLE, LONG, DOUBLE, LONG, POINTER, Fiddle::TYPE_SHORT, LONG, LONG].freeze
35
+ STYLE_MASK = 1 | 2 | 4 | 8 # a title, and the buttons to close, to make small and to resize
36
+ ALL_EVENTS = -1
37
+ DEFAULT_ICON = File.join(__dir__, "icon.png")
38
+ # The menus: without them Cmd+C / V / Q do nothing in a program that is not an app bundle.
39
+ EDIT_ITEMS = [["Undo", "undo:", "z"], ["Redo", "redo:", "Z"], nil, ["Cut", "cut:", "x"], ["Copy", "copy:", "c"],
40
+ ["Paste", "paste:", "v"], ["Select All", "selectAll:", "a"]].freeze
41
+
42
+ def initialize(app)
43
+ @app = app
44
+ @jobs = Queue.new
45
+ @objc = Fiddle.dlopen("/usr/lib/libobjc.A.dylib")
46
+ Fiddle.dlopen("/System/Library/Frameworks/AppKit.framework/AppKit")
47
+ Fiddle.dlopen("/System/Library/Frameworks/WebKit.framework/WebKit")
48
+ @get_class = Fiddle::Function.new(@objc["objc_getClass"], [POINTER], POINTER)
49
+ @selector = Fiddle::Function.new(@objc["sel_registerName"], [POINTER], POINTER)
50
+ @functions = {}
51
+ @selectors = {}
52
+ end
53
+
54
+ def title=(title)
55
+ ask_window { send_message(VOID, @window, "setTitle:", [POINTER], string(title)) }
56
+ end
57
+
58
+ def close
59
+ ask_window { send_message(VOID, @window, "close") }
60
+ end
61
+
62
+ # Opens the window and returns when it is closed.
63
+ def open(address)
64
+ pool = new_pool
65
+ make_window(address)
66
+ @app.control = self
67
+ mode = string("kCFRunLoopDefaultMode")
68
+ send_message(POINTER, mode, "retain")
69
+ drain(pool)
70
+ loop do
71
+ pool = new_pool
72
+ run_events(mode)
73
+ @jobs.pop.call until @jobs.empty?
74
+ is_open = send_message(BOOL, @window, "isVisible") != 0 || send_message(BOOL, @window, "isMiniaturized") != 0
75
+ drain(pool)
76
+ break unless is_open
77
+ end
78
+ ensure
79
+ # WHY: an error of the program in the loop (Ctrl+C) must not leave the window on the screen
80
+ send_message(VOID, @window, "close") if @window
81
+ end
82
+
83
+ private
84
+
85
+ # A job for the thread of the window, from any thread: the loop is woken to do it.
86
+ def ask_window(&job)
87
+ @jobs.push(job)
88
+ pool = new_pool
89
+ event = send_message(POINTER, class_named("NSEvent"),
90
+ "otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:",
91
+ EVENT_TYPES, APPLICATION_EVENT, 0.0, 0.0, 0, 0.0, 0, nil, 0, 0, 0)
92
+ send_message(VOID, @ns_app, "postEvent:atStart:", [POINTER, BOOL], event, 1)
93
+ drain(pool)
94
+ end
95
+
96
+ # objc_msgSend with the types of this call. WHY a function for every set of types: the system reads the values of a
97
+ # call by their types (a double is not where a pointer is).
98
+ def send_message(returns, receiver, name, types = [], *values)
99
+ function = (@functions[[returns, types]] ||= Fiddle::Function.new(@objc["objc_msgSend"], [POINTER, POINTER] + types, returns))
100
+ function.call(receiver, selector(name), *values)
101
+ end
102
+
103
+ def selector(name)
104
+ @selectors[name] ||= @selector.call(name)
105
+ end
106
+
107
+ def class_named(name)
108
+ @get_class.call(name)
109
+ end
110
+
111
+ def create(class_name)
112
+ send_message(POINTER, send_message(POINTER, class_named(class_name), "alloc"), "init")
113
+ end
114
+
115
+ def string(text)
116
+ send_message(POINTER, class_named("NSString"), "stringWithUTF8String:", [POINTER], text.to_s.encode("UTF-8"))
117
+ end
118
+
119
+ def new_pool
120
+ create("NSAutoreleasePool")
121
+ end
122
+
123
+ def drain(pool)
124
+ send_message(VOID, pool, "drain")
125
+ end
126
+
127
+ def responds?(object, name)
128
+ send_message(BOOL, object, "respondsToSelector:", [POINTER], selector(name)) != 0
129
+ end
130
+
131
+ def make_window(address)
132
+ options = @app.options
133
+ name_the_program(options[:title])
134
+ @ns_app = send_message(POINTER, class_named("NSApplication"), "sharedApplication")
135
+ send_message(VOID, @ns_app, "setActivationPolicy:", [LONG], 0) # a program with a Dock icon and a menu
136
+ make_menus(options[:title])
137
+ show_icon(options[:icon] || DEFAULT_ICON)
138
+
139
+ @window = create("NSWindow")
140
+ send_message(VOID, @window, "setReleasedWhenClosed:", [BOOL], 0)
141
+ send_message(VOID, @window, "setStyleMask:", [LONG], STYLE_MASK)
142
+ # WHY the content: the page is as large as the program asked, the title bar comes on top of it
143
+ send_message(VOID, @window, "setContentSize:", [DOUBLE, DOUBLE], options[:width].to_f, options[:height].to_f)
144
+ send_message(VOID, @window, "setTitle:", [POINTER], string(options[:title]))
145
+ @web_view = create("WKWebView")
146
+ allow_developer_tools if options[:debug]
147
+ send_message(VOID, @window, "setContentView:", [POINTER], @web_view)
148
+ url = send_message(POINTER, class_named("NSURL"), "URLWithString:", [POINTER], string(address))
149
+ request = send_message(POINTER, class_named("NSURLRequest"), "requestWithURL:", [POINTER], url)
150
+ send_message(POINTER, @web_view, "loadRequest:", [POINTER], request)
151
+ send_message(VOID, @window, "center")
152
+ send_message(VOID, @window, "makeKeyAndOrderFront:", [POINTER], nil)
153
+ send_message(VOID, @window, "makeFirstResponder:", [POINTER], @web_view)
154
+ send_message(VOID, @ns_app, "finishLaunching")
155
+ send_message(VOID, @ns_app, "activateIgnoringOtherApps:", [BOOL], 1)
156
+ end
157
+
158
+ # WHY: the menu bar and the Dock would name the program "ruby".
159
+ def name_the_program(title)
160
+ bundle = send_message(POINTER, class_named("NSBundle"), "mainBundle")
161
+ info = send_message(POINTER, bundle, "infoDictionary")
162
+ return if info.null? || !responds?(info, "setObject:forKey:")
163
+ send_message(VOID, info, "setObject:forKey:", [POINTER, POINTER], string(title), string("CFBundleName"))
164
+ end
165
+
166
+ def menu_item(title, action, key)
167
+ item = send_message(POINTER, class_named("NSMenuItem"), "alloc")
168
+ send_message(POINTER, item, "initWithTitle:action:keyEquivalent:", [POINTER, POINTER, POINTER],
169
+ string(title), action ? selector(action) : nil, string(key))
170
+ end
171
+
172
+ def add_menu(bar, title, items)
173
+ menu = send_message(POINTER, send_message(POINTER, class_named("NSMenu"), "alloc"), "initWithTitle:", [POINTER], string(title))
174
+ items.each do |item|
175
+ entry = item ? menu_item(*item) : send_message(POINTER, class_named("NSMenuItem"), "separatorItem")
176
+ send_message(VOID, menu, "addItem:", [POINTER], entry)
177
+ end
178
+ holder = menu_item(title, nil, "")
179
+ send_message(VOID, holder, "setSubmenu:", [POINTER], menu)
180
+ send_message(VOID, bar, "addItem:", [POINTER], holder)
181
+ end
182
+
183
+ def make_menus(title)
184
+ bar = create("NSMenu")
185
+ # WHY performClose: and not terminate: Quit closes the window, so run returns and the program ends its own way
186
+ add_menu(bar, title, [["Hide #{title}", "hide:", "h"], nil, ["Quit #{title}", "performClose:", "q"]])
187
+ add_menu(bar, "Edit", EDIT_ITEMS)
188
+ add_menu(bar, "Window", [["Minimize", "performMiniaturize:", "m"], ["Close", "performClose:", "w"]])
189
+ send_message(VOID, @ns_app, "setMainMenu:", [POINTER], bar)
190
+ end
191
+
192
+ def show_icon(path)
193
+ return unless File.file?(path.to_s)
194
+ image = send_message(POINTER, send_message(POINTER, class_named("NSImage"), "alloc"), "initWithContentsOfFile:", [POINTER], string(File.expand_path(path)))
195
+ send_message(VOID, @ns_app, "setApplicationIconImage:", [POINTER], image) unless image.null?
196
+ end
197
+
198
+ # run(debug: true): right click > Inspect Element.
199
+ def allow_developer_tools
200
+ configuration = send_message(POINTER, @web_view, "configuration")
201
+ preferences = send_message(POINTER, configuration, "preferences")
202
+ yes = send_message(POINTER, class_named("NSNumber"), "numberWithBool:", [BOOL], 1)
203
+ send_message(VOID, preferences, "setValue:forKey:", [POINTER, POINTER], yes, string("developerExtrasEnabled"))
204
+ send_message(VOID, @web_view, "setInspectable:", [BOOL], 1) if responds?(@web_view, "setInspectable:")
205
+ end
206
+
207
+ # The events of the window that wait, after a short wait for the first one.
208
+ def run_events(mode)
209
+ wait_until = send_message(POINTER, class_named("NSDate"), "dateWithTimeIntervalSinceNow:", [DOUBLE], EVENT_WAIT)
210
+ loop do
211
+ event = send_message(POINTER, @ns_app, "nextEventMatchingMask:untilDate:inMode:dequeue:",
212
+ [Fiddle::TYPE_LONG_LONG, POINTER, POINTER, BOOL], ALL_EVENTS, wait_until, mode, 1)
213
+ break if event.null?
214
+ send_message(VOID, @ns_app, "sendEvent:", [POINTER], event)
215
+ wait_until = nil # the others that wait already, without a wait
216
+ end
217
+ send_message(VOID, @ns_app, "updateWindows")
218
+ end
219
+ end
220
+ end
221
+ end
data/lib/ozdenui.rb ADDED
@@ -0,0 +1,32 @@
1
+ # Bismillah
2
+ #
3
+ # ozdenui.rb - ozdenui v0.1 (OzdenUI: basic.js for Ruby)
4
+ # A desktop window in plain Ruby, made of the objects of basic.js and the components of the OzdenUI kit.
5
+ #
6
+ # require "ozdenui"
7
+ # include OzdenUI
8
+ #
9
+ # run(title: "Hello", width: 360, height: 200) do
10
+ # Label(text: "Hello", font_size: 28)
11
+ # end
12
+ #
13
+ # Without the include, every name is a method of the module: OzdenUI.run { OzdenUI.Label(text: "Hello") }
14
+ #
15
+ # Started Date: November 2026
16
+ # Webpage: https://bug7a.github.io/ozdenui-ruby/
17
+ #
18
+ # Copyright 2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
19
+ # Licensed under the Apache License, Version 2.0
20
+ # SPDX-License-Identifier: Apache-2.0
21
+
22
+ require_relative "ozdenui/version"
23
+ require_relative "ozdenui/values"
24
+ require_relative "ozdenui/kit"
25
+ require_relative "ozdenui/server"
26
+ require_relative "ozdenui/app"
27
+ require_relative "ozdenui/objects"
28
+ require_relative "ozdenui/components"
29
+ require_relative "ozdenui/dialogs"
30
+ require_relative "ozdenui/files"
31
+ require_relative "ozdenui/window"
32
+ require_relative "ozdenui/look"