Class: Ruflet::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/ruflet_ui/ruflet/page.rb

Constant Summary collapse

PAGE_PROP_KEYS =
%w[route title vertical_alignment horizontal_alignment scroll].freeze
DIALOG_PROP_KEYS =
%w[dialog snack_bar bottom_sheet].freeze
WIDGET_HELPER_METHODS =
(
  Ruflet::UI::MaterialControlMethods.instance_methods(false) +
  Ruflet::UI::CupertinoControlMethods.instance_methods(false) +
  %i[control widget]
).map(&:to_s).to_set.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session_id:, client_details:, sender:) ⇒ Page

Returns a new instance of Page.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ruflet_ui/ruflet/page.rb', line 27

def initialize(session_id:, client_details:, sender:)
  @session_id = session_id
  @client_details = client_details
  @sender = sender
  @control_index = {}
  @wire_index = {}
  @next_wire_id = 100
  @view_id = 20
  @root_controls = []
  @views = []
  @dialogs = []
  @page_event_handlers = {}
  @view_props = {}
  @page_props = { "route" => (client_details["route"] || "/") }
  @overlay_container = Ruflet::Control.new(
    type: "overlay",
    id: "_overlay",
    controls: []
  )
  @services_container = Ruflet::Control.new(
    type: "service_registry",
    id: "_services",
    "_services": [],
    "_internals": { "uid" => Ruflet::Control.generate_id }
  )
  @dialogs_container = Ruflet::Control.new(
    type: "dialogs",
    id: "_dialogs",
    controls: []
  )
  @invoke_waiters = {}
  @invoke_callbacks = {}
  @invoke_waiters_mutex = Mutex.new
  refresh_overlay_container!
  refresh_services_container!
  refresh_dialogs_container!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
# File 'lib/ruflet_ui/ruflet/page.rb', line 685

def method_missing(name, *args, &block)
  method_name = name.to_s
  prop_name = method_name.delete_suffix("=")

  if method_name.end_with?("=")
    if widget_helper_method?(prop_name)
      raise NoMethodError, "Use `#{prop_name}(...)` as a free widget helper, then attach with `page.add(...)`."
    end
    assign_split_prop(prop_name, normalize_value(prop_name, args.first))
    return args.first
  end

  if args.empty? && !block
    return @page_props[method_name] if @page_props.key?(method_name)
    return @view_props[method_name] if @view_props.key?(method_name)
    return instance_variable_get("@#{method_name}") if DIALOG_PROP_KEYS.include?(method_name)
  end

  if widget_helper_method?(name)
    raise NoMethodError, "Use `#{name}(...)` as a free widget helper, then attach with `page.add(...)`."
  end

  super
end

Instance Attribute Details

#client_detailsObject (readonly)

Returns the value of attribute client_details.



25
26
27
# File 'lib/ruflet_ui/ruflet/page.rb', line 25

def client_details
  @client_details
end

#session_idObject (readonly)

Returns the value of attribute session_id.



25
26
27
# File 'lib/ruflet_ui/ruflet/page.rb', line 25

def session_id
  @session_id
end

#viewsObject

Returns the value of attribute views.



25
26
27
# File 'lib/ruflet_ui/ruflet/page.rb', line 25

def views
  @views
end

Instance Method Details

#add(*controls, appbar: nil, floating_action_button: nil, navigation_bar: nil, dialog: nil, snack_bar: nil, bottom_sheet: nil) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/ruflet_ui/ruflet/page.rb', line 114

def add(*controls, appbar: nil, floating_action_button: nil, navigation_bar: nil, dialog: nil, snack_bar: nil, bottom_sheet: nil)
  controls = controls.flatten
  visited = Set.new
  controls.each { |c| register_control_tree(c, visited) }
  @root_controls = controls

  @view_props["appbar"] = appbar if appbar
  @view_props["floating_action_button"] = floating_action_button if floating_action_button
  @view_props["navigation_bar"] = navigation_bar if navigation_bar
  @dialog = dialog if dialog
  @snack_bar = snack_bar if snack_bar
  @bottom_sheet = bottom_sheet if bottom_sheet

  refresh_dialogs_container!
  @view_props.each_value { |value| register_embedded_value(value, visited) }

  send_view_patch

  self
end

#add_service(*value) ⇒ Object



151
152
153
154
155
156
# File 'lib/ruflet_ui/ruflet/page.rb', line 151

def add_service(*value)
  @services_container.props["_services"] = services + value.flatten.compact
  refresh_services_container!
  push_services_update!
  self
end

#appbar=(value) ⇒ Object



223
224
225
# File 'lib/ruflet_ui/ruflet/page.rb', line 223

def appbar=(value)
  @view_props["appbar"] = value
end

#apply_client_update(control_or_id, props) ⇒ Object



652
653
654
655
656
657
658
659
660
661
662
# File 'lib/ruflet_ui/ruflet/page.rb', line 652

def apply_client_update(control_or_id, props)
  control = resolve_control(control_or_id)
  return self unless control

  patch = normalize_props(props || {})
  patch.each { |k, v| control.props[k] = v }

  remove_dialog_tracking(control) if patch.key?("open") && patch["open"] == false

  self
end

#battery_save_mode?(timeout: nil, on_result: nil) ⇒ Boolean

Returns:

  • (Boolean)


445
446
447
# File 'lib/ruflet_ui/ruflet/page.rb', line 445

def battery_save_mode?(timeout: nil, on_result: nil)
  invoke_battery_method("is_in_battery_save_mode", timeout: timeout, on_result: on_result)
end

#bgcolorObject



106
107
108
# File 'lib/ruflet_ui/ruflet/page.rb', line 106

def bgcolor
  @view_props["bgcolor"]
end

#bgcolor=(value) ⇒ Object



110
111
112
# File 'lib/ruflet_ui/ruflet/page.rb', line 110

def bgcolor=(value)
  @view_props["bgcolor"] = normalize_value("bgcolor", value)
end

#bottom_sheet=(value) ⇒ Object



247
248
249
250
# File 'lib/ruflet_ui/ruflet/page.rb', line 247

def bottom_sheet=(value)
  @bottom_sheet = value
  refresh_dialogs_container!
end

#bottomsheet=(value) ⇒ Object



252
253
254
# File 'lib/ruflet_ui/ruflet/page.rb', line 252

def bottomsheet=(value)
  self.bottom_sheet = value
end

#can_launch_url(url, timeout: 10) ⇒ Object



326
327
328
329
# File 'lib/ruflet_ui/ruflet/page.rb', line 326

def can_launch_url(url, timeout: 10)
  url_launcher = ensure_url_launcher_service
  invoke(url_launcher, "can_launch_url", args: { "url" => url }, timeout: timeout)
end

#dialogObject



231
# File 'lib/ruflet_ui/ruflet/page.rb', line 231

def dialog = @dialog

#dialog=(value) ⇒ Object



233
234
235
236
# File 'lib/ruflet_ui/ruflet/page.rb', line 233

def dialog=(value)
  @dialog = value
  refresh_dialogs_container!
end

#dispatch_event(target:, name:, data:) ⇒ Object



664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
# File 'lib/ruflet_ui/ruflet/page.rb', line 664

def dispatch_event(target:, name:, data:)
  if page_control_target?(target)
    if name.to_s == "route_change"
      route_from_event = extract_route(data)
      @page_props["route"] = route_from_event if route_from_event
    end
    dispatch_page_event(name: name, data: data)
    return
  end

  control = @wire_index[target.to_i] || @control_index[target.to_s]
  return unless control

  event = Event.new(name: name, target: target, raw_data: data, page: self, control: control)
  control.emit(name, event)

  if name.to_s == "dismiss" && remove_dialog_tracking(control)
    push_dialogs_update!
  end
end

#floating_action_button=(value) ⇒ Object



227
228
229
# File 'lib/ruflet_ui/ruflet/page.rb', line 227

def floating_action_button=(value)
  @view_props["floating_action_button"] = value
end

#get_application_cache_directory(timeout: nil, on_result: nil) ⇒ Object



449
450
451
# File 'lib/ruflet_ui/ruflet/page.rb', line 449

def get_application_cache_directory(timeout: nil, on_result: nil)
  invoke_storage_paths("get_application_cache_directory", timeout: timeout, on_result: on_result)
end

#get_application_documents_directory(timeout: nil, on_result: nil) ⇒ Object



453
454
455
# File 'lib/ruflet_ui/ruflet/page.rb', line 453

def get_application_documents_directory(timeout: nil, on_result: nil)
  invoke_storage_paths("get_application_documents_directory", timeout: timeout, on_result: on_result)
end

#get_application_support_directory(timeout: nil, on_result: nil) ⇒ Object



457
458
459
# File 'lib/ruflet_ui/ruflet/page.rb', line 457

def get_application_support_directory(timeout: nil, on_result: nil)
  invoke_storage_paths("get_application_support_directory", timeout: timeout, on_result: on_result)
end

#get_battery_level(timeout: nil, on_result: nil) ⇒ Object



437
438
439
# File 'lib/ruflet_ui/ruflet/page.rb', line 437

def get_battery_level(timeout: nil, on_result: nil)
  invoke_battery_method("get_battery_level", timeout: timeout, on_result: on_result)
end

#get_battery_state(timeout: nil, on_result: nil) ⇒ Object



441
442
443
# File 'lib/ruflet_ui/ruflet/page.rb', line 441

def get_battery_state(timeout: nil, on_result: nil)
  invoke_battery_method("get_battery_state", timeout: timeout, on_result: on_result)
end

#get_clipboard(timeout: nil, on_result: nil) ⇒ Object



403
404
405
# File 'lib/ruflet_ui/ruflet/page.rb', line 403

def get_clipboard(timeout: nil, on_result: nil)
  invoke_clipboard_method("get_data", timeout: timeout, on_result: on_result)
end

#get_clipboard_files(timeout: nil, on_result: nil) ⇒ Object



416
417
418
# File 'lib/ruflet_ui/ruflet/page.rb', line 416

def get_clipboard_files(timeout: nil, on_result: nil)
  invoke_clipboard_method("get_files", timeout: timeout, on_result: on_result)
end

#get_clipboard_image(timeout: nil, on_result: nil) ⇒ Object



429
430
431
# File 'lib/ruflet_ui/ruflet/page.rb', line 429

def get_clipboard_image(timeout: nil, on_result: nil)
  invoke_clipboard_method("get_image", timeout: timeout, on_result: on_result)
end

#get_connectivity(timeout: nil, on_result: nil) ⇒ Object



433
434
435
# File 'lib/ruflet_ui/ruflet/page.rb', line 433

def get_connectivity(timeout: nil, on_result: nil)
  invoke_connectivity_method("get_connectivity", timeout: timeout, on_result: on_result)
end

#get_console_log_filename(timeout: nil, on_result: nil) ⇒ Object



485
486
487
# File 'lib/ruflet_ui/ruflet/page.rb', line 485

def get_console_log_filename(timeout: nil, on_result: nil)
  invoke_storage_paths("get_console_log_filename", timeout: timeout, on_result: on_result)
end

#get_directory_path(dialog_title: nil, initial_directory: nil, timeout: nil, on_result: nil) ⇒ Object



382
383
384
385
386
387
388
389
390
391
392
# File 'lib/ruflet_ui/ruflet/page.rb', line 382

def get_directory_path(dialog_title: nil, initial_directory: nil, timeout: nil, on_result: nil)
  invoke_file_picker(
    "get_directory_path",
    {
      "dialog_title" => dialog_title,
      "initial_directory" => initial_directory
    },
    timeout: timeout,
    on_result: on_result
  )
end

#get_downloads_directory(timeout: nil, on_result: nil) ⇒ Object



461
462
463
# File 'lib/ruflet_ui/ruflet/page.rb', line 461

def get_downloads_directory(timeout: nil, on_result: nil)
  invoke_storage_paths("get_downloads_directory", timeout: timeout, on_result: on_result)
end

#get_external_cache_directories(timeout: nil, on_result: nil) ⇒ Object



465
466
467
# File 'lib/ruflet_ui/ruflet/page.rb', line 465

def get_external_cache_directories(timeout: nil, on_result: nil)
  invoke_storage_paths("get_external_cache_directories", timeout: timeout, on_result: on_result)
end

#get_external_storage_directories(timeout: nil, on_result: nil) ⇒ Object



469
470
471
# File 'lib/ruflet_ui/ruflet/page.rb', line 469

def get_external_storage_directories(timeout: nil, on_result: nil)
  invoke_storage_paths("get_external_storage_directories", timeout: timeout, on_result: on_result)
end

#get_external_storage_directory(timeout: nil, on_result: nil) ⇒ Object



477
478
479
# File 'lib/ruflet_ui/ruflet/page.rb', line 477

def get_external_storage_directory(timeout: nil, on_result: nil)
  invoke_storage_paths("get_external_storage_directory", timeout: timeout, on_result: on_result)
end

#get_library_directory(timeout: nil, on_result: nil) ⇒ Object



473
474
475
# File 'lib/ruflet_ui/ruflet/page.rb', line 473

def get_library_directory(timeout: nil, on_result: nil)
  invoke_storage_paths("get_library_directory", timeout: timeout, on_result: on_result)
end

#get_temporary_directory(timeout: nil, on_result: nil) ⇒ Object



481
482
483
# File 'lib/ruflet_ui/ruflet/page.rb', line 481

def get_temporary_directory(timeout: nil, on_result: nil)
  invoke_storage_paths("get_temporary_directory", timeout: timeout, on_result: on_result)
end

#go(route, **query_params) ⇒ Object



197
198
199
200
201
202
# File 'lib/ruflet_ui/ruflet/page.rb', line 197

def go(route, **query_params)
  @page_props["route"] = build_route(route, query_params)
  dispatch_page_event(name: "route_change", data: @page_props["route"])
  send_view_patch
  self
end

#handle_invoke_method_result(payload) ⇒ Object



574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
# File 'lib/ruflet_ui/ruflet/page.rb', line 574

def handle_invoke_method_result(payload)
  call_id = payload["call_id"].to_s
  waiter = @invoke_waiters_mutex.synchronize { @invoke_waiters[call_id] }
  if waiter
    waiter << payload
    return true
  end

  callback = @invoke_waiters_mutex.synchronize { @invoke_callbacks.delete(call_id) }
  return false unless callback

  callback.call(payload["result"], payload["error"])
  true
rescue StandardError => e
  Kernel.warn("invoke callback error: #{e.class}: #{e.message}")
  false
end

#horizontal_alignmentObject



96
97
98
# File 'lib/ruflet_ui/ruflet/page.rb', line 96

def horizontal_alignment
  @page_props["horizontal_alignment"] || @view_props["horizontal_alignment"]
end

#horizontal_alignment=(value) ⇒ Object



100
101
102
103
104
# File 'lib/ruflet_ui/ruflet/page.rb', line 100

def horizontal_alignment=(value)
  v = normalize_value("horizontal_alignment", value)
  @page_props["horizontal_alignment"] = v
  @view_props["horizontal_alignment"] = v
end

#invoke(control_or_id, method_name, args: nil, timeout: 10, on_result: nil) ⇒ Object



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/ruflet_ui/ruflet/page.rb', line 269

def invoke(control_or_id, method_name, args: nil, timeout: 10, on_result: nil)
  control_id =
    if page_control_target?(control_or_id)
      1
    else
      control = resolve_control(control_or_id)
      return nil unless control
      control.wire_id
    end

  call_id = "call_#{Ruflet::Control.generate_id}"
  if on_result.respond_to?(:call)
    @invoke_waiters_mutex.synchronize { @invoke_callbacks[call_id] = on_result }
    unless timeout.nil?
      Thread.new(call_id, timeout.to_f) do |pending_call_id, invoke_timeout|
        sleep([invoke_timeout, 0.0].max + 0.1)
        callback = @invoke_waiters_mutex.synchronize { @invoke_callbacks.delete(pending_call_id) }
        callback&.call(nil, "execution expired")
      rescue StandardError => e
        Kernel.warn("invoke timeout callback error: #{e.class}: #{e.message}")
      end
    end
  end
  payload = {
    "control_id" => control_id,
    "call_id" => call_id,
    "name" => method_name.to_s,
    "args" => args
  }
  payload["timeout"] = timeout unless timeout.nil?
  send_message(Protocol::ACTIONS[:invoke_control_method], payload)

  call_id
end

#invoke_sync(control_or_id, method_name, args: nil, timeout: 10) ⇒ Object

Synchronous invoke for controls/services that must return a value before continuing (e.g. picker selection, camera discovery/init).



306
307
308
# File 'lib/ruflet_ui/ruflet/page.rb', line 306

def invoke_sync(control_or_id, method_name, args: nil, timeout: 10)
  invoke_and_wait(control_or_id, method_name, args: args, timeout: timeout)
end

#launch_url(url, mode: nil, web_view_configuration: nil, browser_configuration: nil, web_only_window_name: nil, timeout: 10, on_result: nil) ⇒ Object



310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/ruflet_ui/ruflet/page.rb', line 310

def launch_url(url, mode: nil, web_view_configuration: nil, browser_configuration: nil, web_only_window_name: nil, timeout: 10, on_result: nil)
  url_launcher = ensure_url_launcher_service
  args = { "url" => url }
  args["mode"] = mode unless mode.nil?
  args["web_view_configuration"] = web_view_configuration unless web_view_configuration.nil?
  args["browser_configuration"] = browser_configuration unless browser_configuration.nil?
  args["web_only_window_name"] = web_only_window_name unless web_only_window_name.nil?
  invoke(
    url_launcher,
    "launch_url",
    args: args,
    timeout: timeout,
    on_result: on_result
  )
end

#mount(&block) ⇒ Object



217
218
219
220
221
# File 'lib/ruflet_ui/ruflet/page.rb', line 217

def mount(&block)
  builder = WidgetBuilder.new
  builder.instance_eval(&block)
  add(*builder.children)
end

#on(event_name, &block) ⇒ Object



212
213
214
215
# File 'lib/ruflet_ui/ruflet/page.rb', line 212

def on(event_name, &block)
  @page_event_handlers[event_name.to_s.sub(/\Aon_/, "")] = block
  self
end

#on_route_change=(handler) ⇒ Object



204
205
206
# File 'lib/ruflet_ui/ruflet/page.rb', line 204

def on_route_change=(handler)
  @page_event_handlers["route_change"] = handler
end

#on_view_pop=(handler) ⇒ Object



208
209
210
# File 'lib/ruflet_ui/ruflet/page.rb', line 208

def on_view_pop=(handler)
  @page_event_handlers["view_pop"] = handler
end

#patch_page(control_id, **props) ⇒ Object



648
649
650
# File 'lib/ruflet_ui/ruflet/page.rb', line 648

def patch_page(control_id, **props)
  update(control_id, **props)
end

#pick_files(dialog_title: nil, initial_directory: nil, file_type: "any", allowed_extensions: nil, allow_multiple: false, with_data: false, timeout: nil, on_result: nil) ⇒ Object

File picker helpers: create an ephemeral service, invoke method, and dispose it.



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/ruflet_ui/ruflet/page.rb', line 332

def pick_files(
  dialog_title: nil,
  initial_directory: nil,
  file_type: "any",
  allowed_extensions: nil,
  allow_multiple: false,
  with_data: false,
  timeout: nil,
  on_result: nil
)
  invoke_file_picker(
    "pick_files",
    {
      "dialog_title" => dialog_title,
      "initial_directory" => initial_directory,
      "file_type" => file_type,
      "allowed_extensions" => allowed_extensions,
      "allow_multiple" => allow_multiple,
      "with_data" => with_data
    },
    timeout: timeout,
    on_result: on_result
  )
end

#pop_dialogObject



592
593
594
595
596
597
598
599
600
# File 'lib/ruflet_ui/ruflet/page.rb', line 592

def pop_dialog
  dialog_control = latest_open_dialog
  return nil unless dialog_control

  dialog_control.props["open"] = false
  refresh_dialogs_container!
  push_dialogs_update!
  dialog_control
end

#remove_service(*value) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/ruflet_ui/ruflet/page.rb', line 158

def remove_service(*value)
  targets = value.flatten.compact
  return self if targets.empty?

  @services_container.props["_services"] = services.reject do |service|
    targets.any? do |target|
      case target
      when Control
        service.equal?(target) || (!target.id.nil? && service.id.to_s == target.id.to_s)
      else
        needle = target.to_s
        service.id.to_s == needle || service.type.to_s.downcase == needle.downcase
      end
    end
  end

  refresh_services_container!
  push_services_update!
  self
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


710
711
712
713
714
715
716
717
718
719
720
# File 'lib/ruflet_ui/ruflet/page.rb', line 710

def respond_to_missing?(name, include_private = false)
  method_name = name.to_s
  prop_name = method_name.delete_suffix("=")
  widget_helper_method?(name) ||
    widget_helper_method?(prop_name) ||
    method_name.end_with?("=") ||
    @page_props.key?(method_name) ||
    @view_props.key?(method_name) ||
    DIALOG_PROP_KEYS.include?(method_name) ||
    super
end

#routeObject



78
79
80
# File 'lib/ruflet_ui/ruflet/page.rb', line 78

def route
  @page_props["route"]
end

#route=(value) ⇒ Object



82
83
84
# File 'lib/ruflet_ui/ruflet/page.rb', line 82

def route=(value)
  @page_props["route"] = value
end

#save_file(dialog_title: nil, file_name: nil, initial_directory: nil, file_type: "any", allowed_extensions: nil, src_bytes: nil, timeout: nil, on_result: nil) ⇒ Object



357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/ruflet_ui/ruflet/page.rb', line 357

def save_file(
  dialog_title: nil,
  file_name: nil,
  initial_directory: nil,
  file_type: "any",
  allowed_extensions: nil,
  src_bytes: nil,
  timeout: nil,
  on_result: nil
)
  invoke_file_picker(
    "save_file",
    {
      "dialog_title" => dialog_title,
      "file_name" => file_name,
      "initial_directory" => initial_directory,
      "file_type" => file_type,
      "allowed_extensions" => allowed_extensions,
      "src_bytes" => src_bytes
    },
    timeout: timeout,
    on_result: on_result
  )
end

#service(type, **props) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/ruflet_ui/ruflet/page.rb', line 179

def service(type, **props)
  mapped_props = normalize_props(props || {})
  id = mapped_props.delete("id")
  normalized_type = type.to_s.downcase

  existing =
    if id
      services.find { |s| s.is_a?(Control) && s.id.to_s == id.to_s }
    else
      services.find { |s| s.is_a?(Control) && s.type.to_s.downcase == normalized_type }
    end
  return existing if existing

  svc = Ruflet::UI::ControlFactory.build(type.to_s, id: id&.to_s, **mapped_props)
  add_service(svc) unless services.include?(svc)
  svc
end

#servicesObject



140
141
142
# File 'lib/ruflet_ui/ruflet/page.rb', line 140

def services
  @services_container.props["_services"] ||= []
end

#services=(value) ⇒ Object



144
145
146
147
148
149
# File 'lib/ruflet_ui/ruflet/page.rb', line 144

def services=(value)
  @services_container.props["_services"] = Array(value).compact
  refresh_services_container!
  push_services_update!
  self
end

#set_clipboard(value, timeout: nil, on_result: nil) ⇒ Object



394
395
396
397
398
399
400
401
# File 'lib/ruflet_ui/ruflet/page.rb', line 394

def set_clipboard(value, timeout: nil, on_result: nil)
  invoke_clipboard_method(
    "set_data",
    args: { "data" => value.to_s },
    timeout: timeout,
    on_result: on_result
  )
end

#set_clipboard_files(files, timeout: nil, on_result: nil) ⇒ Object



407
408
409
410
411
412
413
414
# File 'lib/ruflet_ui/ruflet/page.rb', line 407

def set_clipboard_files(files, timeout: nil, on_result: nil)
  invoke_clipboard_method(
    "set_files",
    args: { "files" => Array(files).map(&:to_s) },
    timeout: timeout,
    on_result: on_result
  )
end

#set_clipboard_image(value, timeout: nil, on_result: nil) ⇒ Object



420
421
422
423
424
425
426
427
# File 'lib/ruflet_ui/ruflet/page.rb', line 420

def set_clipboard_image(value, timeout: nil, on_result: nil)
  invoke_clipboard_method(
    "set_image",
    args: { "data" => value },
    timeout: timeout,
    on_result: on_result
  )
end

#set_view_props(props) ⇒ Object



65
66
67
68
# File 'lib/ruflet_ui/ruflet/page.rb', line 65

def set_view_props(props)
  split_props(normalize_props(props || {}))
  self
end

#share_files(files:, text: nil, title: nil, subject: nil, preview_thumbnail: nil, share_position_origin: nil, download_fallback_enabled: true, mail_to_fallback_enabled: true, excluded_cupertino_activities: nil, timeout: nil, on_result: nil) ⇒ Object



541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
# File 'lib/ruflet_ui/ruflet/page.rb', line 541

def share_files(
  files:,
  text: nil,
  title: nil,
  subject: nil,
  preview_thumbnail: nil,
  share_position_origin: nil,
  download_fallback_enabled: true,
  mail_to_fallback_enabled: true,
  excluded_cupertino_activities: nil,
  timeout: nil,
  on_result: nil
)
  share = ensure_share_service
  invoke(
    share,
    "share_files",
    args: {
      "files" => files,
      "text" => text,
      "title" => title,
      "subject" => subject,
      "preview_thumbnail" => preview_thumbnail,
      "share_position_origin" => share_position_origin,
      "download_fallback_enabled" => download_fallback_enabled,
      "mail_to_fallback_enabled" => mail_to_fallback_enabled,
      "excluded_cupertino_activities" => excluded_cupertino_activities
    },
    timeout: timeout,
    on_result: on_result
  )
end

#share_text(text:, title: nil, subject: nil, preview_thumbnail: nil, share_position_origin: nil, download_fallback_enabled: true, mail_to_fallback_enabled: true, excluded_cupertino_activities: nil, timeout: nil, on_result: nil) ⇒ Object



489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
# File 'lib/ruflet_ui/ruflet/page.rb', line 489

def share_text(
  text:,
  title: nil,
  subject: nil,
  preview_thumbnail: nil,
  share_position_origin: nil,
  download_fallback_enabled: true,
  mail_to_fallback_enabled: true,
  excluded_cupertino_activities: nil,
  timeout: nil,
  on_result: nil
)
  share = ensure_share_service
  invoke(
    share,
    "share_text",
    args: {
      "text" => text,
      "title" => title,
      "subject" => subject,
      "preview_thumbnail" => preview_thumbnail,
      "share_position_origin" => share_position_origin,
      "download_fallback_enabled" => download_fallback_enabled,
      "mail_to_fallback_enabled" => mail_to_fallback_enabled,
      "excluded_cupertino_activities" => excluded_cupertino_activities
    },
    timeout: timeout,
    on_result: on_result
  )
end

#share_uri(uri:, share_position_origin: nil, excluded_cupertino_activities: nil, timeout: nil, on_result: nil) ⇒ Object



520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
# File 'lib/ruflet_ui/ruflet/page.rb', line 520

def share_uri(
  uri:,
  share_position_origin: nil,
  excluded_cupertino_activities: nil,
  timeout: nil,
  on_result: nil
)
  share = ensure_share_service
  invoke(
    share,
    "share_uri",
    args: {
      "uri" => uri,
      "share_position_origin" => share_position_origin,
      "excluded_cupertino_activities" => excluded_cupertino_activities
    },
    timeout: timeout,
    on_result: on_result
  )
end

#show_dialog(dialog_control) ⇒ Object



256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/ruflet_ui/ruflet/page.rb', line 256

def show_dialog(dialog_control)
  return self unless dialog_control

  return self if dialog_open?(dialog_control)

  dialog_control.props["open"] = true
  @dialogs << dialog_control unless @dialogs.include?(dialog_control)
  refresh_dialogs_container!
  send_view_patch unless @dialogs_container.wire_id
  push_dialogs_update!
  self
end

#snack_bar=(value) ⇒ Object



238
239
240
241
# File 'lib/ruflet_ui/ruflet/page.rb', line 238

def snack_bar=(value)
  @snack_bar = value
  refresh_dialogs_container!
end

#snackbar=(value) ⇒ Object



243
244
245
# File 'lib/ruflet_ui/ruflet/page.rb', line 243

def snackbar=(value)
  self.snack_bar = value
end

#titleObject



70
71
72
# File 'lib/ruflet_ui/ruflet/page.rb', line 70

def title
  @page_props["title"]
end

#title=(value) ⇒ Object



74
75
76
# File 'lib/ruflet_ui/ruflet/page.rb', line 74

def title=(value)
  @page_props["title"] = value
end

#update(control_or_id = nil, **props) ⇒ Object



602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
# File 'lib/ruflet_ui/ruflet/page.rb', line 602

def update(control_or_id = nil, **props)
  if control_or_id.nil? && props.empty?
    send_view_patch
    return self
  end

  if page_control_target?(control_or_id)
    split_props(normalize_props(props))
    send_view_patch
    return self
  end

  control = resolve_control(control_or_id)
  return self unless control
  wire_id = control.wire_id
  if wire_id.nil?
    # Events can race with navigation/disposal; never emit patch_control with nil id.
    refresh_control_indexes!
    wire_id = control.wire_id
  end
  return self if wire_id.nil?

  patch = normalize_props(props)
  if text_maps_to_content?(control, patch)
    patch["content"] = patch.delete("text")
  end

  # Keep runtime control tree aligned with incremental patches.
  if patch.key?("controls")
    control.children.clear
    Array(patch["controls"]).each { |child| control.children << child if child.is_a?(Control) }
  end

  visited = Set.new
  patch.each_value { |value| register_embedded_value(value, visited) }

  patch_ops = patch.map { |k, v| [0, 0, k, serialize_patch_value(v)] }

  send_message(Protocol::ACTIONS[:patch_control], {
    "id" => wire_id,
    "patch" => [[0], *patch_ops]
  })

  self
end

#vertical_alignmentObject



86
87
88
# File 'lib/ruflet_ui/ruflet/page.rb', line 86

def vertical_alignment
  @page_props["vertical_alignment"] || @view_props["vertical_alignment"]
end

#vertical_alignment=(value) ⇒ Object



90
91
92
93
94
# File 'lib/ruflet_ui/ruflet/page.rb', line 90

def vertical_alignment=(value)
  v = normalize_value("vertical_alignment", value)
  @page_props["vertical_alignment"] = v
  @view_props["vertical_alignment"] = v
end