class NotepadqqApi
Constants
- NQQ_STUB_ID
Attributes
extension_id[R]
Public Class Methods
new(socket_path = ARGV[0], extension_id = ARGV[1])
click to toggle source
# File lib/notepadqq_api.rb, line 12 def initialize(socket_path = ARGV[0], extension_id = ARGV[1]) @socket_path = socket_path @extension_id = extension_id @message_channel = MessageChannel.new(@socket_path) @message_interpreter = MessageInterpreter.new(@message_channel) end
Public Instance Methods
notepadqq()
click to toggle source
Returns an instance of Notepadqq
# File lib/notepadqq_api.rb, line 68 def notepadqq @nqq ||= Stubs::Notepadqq.new(@message_interpreter, NQQ_STUB_ID); return @nqq end
on_window_created(&callback)
click to toggle source
Execute a block for every new window. This is preferable to the “newWindow” event of Notepadqq, because it could happen that the extension isn’t ready soon enough to receive the “newWindow” event for the first Window. This method, instead, ensures that the passed block will be called once and only once for each current or future window.
# File lib/notepadqq_api.rb, line 41 def on_window_created(&callback) captured_windows = [] # Invoke the callback for every currently open window notepadqq.windows.each do |window| unless captured_windows.include? window captured_windows.push window callback.call(window) end end # Each time a new window gets opened, invoke the callback. # When Notepadqq is starting and initializing all the extensions, # we might not be fast enough to receive this event: this is why # we manually invoked the callback for every currently open window. notepadqq.on(:newWindow) do |window| unless captured_windows.include? window captured_windows.push window callback.call(window) end end end
Also aliased as: onWindowCreated
run_event_loop() { || ... }
click to toggle source
Start reading messages and calling event handlers
# File lib/notepadqq_api.rb, line 21 def run_event_loop yield while true do messages = @message_channel.get_messages messages.each do |msg| @message_interpreter.process_message(msg) end end end
Also aliased as: runEventLoop