Class: Scarpe::WebviewDisplayService

Inherits:
Shoes::DisplayService show all
Includes:
Shoes::Log
Defined in:
lib/scarpe/wv/webview_local_display.rb

Overview

This is the simplest type of Webview DisplayService. It creates Webview widgets corresponding to Shoes widgets, manages the Webview and its DOM tree, and generally keeps the Shoes/Webview connection working.

This is an in-process Webview-based display service, with all the limitations that entails. Slow handlers will crash, ending this display service will end the process, too many or too large evals can crash the process, etc. Frequently it's better to use a RelayDisplayService to a second process containing one of these.

Constant Summary

Constants included from Shoes::Log

Shoes::Log::DEFAULT_COMPONENT, Shoes::Log::DEFAULT_DEBUG_LOG_CONFIG, Shoes::Log::DEFAULT_LOG_CONFIG

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Shoes::Log

configure_logger, #log_init, logger

Methods inherited from Shoes::DisplayService

dispatch_event, display_service, full_reset!, #query_display_widget_for, set_display_service_class, #set_widget_pairing, subscribe_to_event, unsub_from_events

Constructor Details

#initializeWebviewDisplayService

This is called before any of the various WebviewWidgets are created, to be able to create them and look them up.



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/scarpe/wv/webview_local_display.rb', line 34

def initialize
  if WebviewDisplayService.instance
    raise "ERROR! This is meant to be a singleton!"
  end

  WebviewDisplayService.instance = self

  super()
  log_init("WV::WebviewDisplayService")

  @display_widget_for = {}
end

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



17
18
19
# File 'lib/scarpe/wv/webview_local_display.rb', line 17

def instance
  @instance
end

Instance Attribute Details

#appObject (readonly)

app is the Scarpe::WebviewApp



27
28
29
# File 'lib/scarpe/wv/webview_local_display.rb', line 27

def app
  @app
end

#control_interfaceObject (readonly)

The ControlInterface is used to handle internal events in Webview Scarpe



21
22
23
# File 'lib/scarpe/wv/webview_local_display.rb', line 21

def control_interface
  @control_interface
end

#doc_rootObject (readonly)

The DocumentRoot is the top widget of the Webview-side widget tree



24
25
26
# File 'lib/scarpe/wv/webview_local_display.rb', line 24

def doc_root
  @doc_root
end

#wranglerObject (readonly)

wrangler is the Scarpe::WebWrangler



30
31
32
# File 'lib/scarpe/wv/webview_local_display.rb', line 30

def wrangler
  @wrangler
end

Instance Method Details

#create_display_widget_for(widget_class_name, widget_id, properties) ⇒ WebviewWidget

Create a Webview display widget for a specific Shoes widget, and pair it with the linkable ID for this Shoes widget.

Parameters:

  • widget_class_name (String)

    The class name of the Shoes widget, e.g. Shoes::Button

  • widget_id (String)

    the linkable ID for widget events

  • properties (Hash)

    a JSON-serialisable Hash with the widget's display properties

Returns:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/scarpe/wv/webview_local_display.rb', line 54

def create_display_widget_for(widget_class_name, widget_id, properties)
  if widget_class_name == "App"
    unless @doc_root
      raise "WebviewDocumentRoot is supposed to be created before WebviewApp!"
    end

    display_app = Scarpe::WebviewApp.new(properties)
    display_app.document_root = @doc_root
    @control_interface = display_app.control_interface
    @control_interface.doc_root = @doc_root
    @app = @control_interface.app
    @wrangler = @control_interface.wrangler

    set_widget_pairing(widget_id, display_app)

    return display_app
  end

  # Create a corresponding display widget
  display_class = Scarpe::WebviewWidget.display_class_for(widget_class_name)
  display_widget = display_class.new(properties)
  set_widget_pairing(widget_id, display_widget)

  if widget_class_name == "DocumentRoot"
    # WebviewDocumentRoot is created before WebviewApp. Mostly doc_root is just like any other widget,
    # but we'll want a reference to it when we create WebviewApp.
    @doc_root = display_widget
  end

  display_widget
end

#destroyvoid

This method returns an undefined value.

Destroy the display service and the app. Quit the process (eventually.)



89
90
91
92
# File 'lib/scarpe/wv/webview_local_display.rb', line 89

def destroy
  @app.destroy
  WebviewDisplayService.instance = nil
end