In the plugin , on start , if a request is called then response is not returned.
But when the button is clicked and same request is executed , correct response is returned.
PluginName: testsentio
test.zip (3.3 KB)
In the plugin , on start , if a request is called then response is not returned.
But when the button is clicked and same request is executed , correct response is returned.
PluginName: testsentio
test.zip (3.3 KB)
you should look at âlazy loadingâ all of your files, so they donât load on startupâŚ
you can add an over-ride for debugging, and comment out for deploymentâŚ
## Tidied up code below in latter post...
john
Sorry i do not understand how this will help because flow seems to be same.
Also I have toolbar in the plugin so that should load on startup.
the flow IS different, as itâs deliberately withholding the loadingâŚ
you should add cmdâs [so you can add a shortcut key] then use the cmd for menu and toolbarâŚ
I tidied up the first postâs rubyâŚ
you need to change ENV['LOGNAME'] == 'johns_iMac'
to your computerâŚ
module TestSolutionario
module TestSentio
module_function
DEBUG ||= true if ENV['LOGNAME'] == 'johns_iMac'
def lazy_load
require 'sketchup.rb'
require 'net/http'
require 'json'
require 'pathname'
Sketchup.require(File.join(File.dirname(__FILE__), "config"))
Sketchup.require(File.join(File.dirname(__FILE__), "sentio_logger"))
Sketchup.require(File.join(File.dirname(__FILE__), "csrf_request"))
Sketchup.require(File.join(File.dirname(__FILE__), "pluginreloader"))
end
def init
SKETCHUP_CONSOLE.show if DEBUG
csrfReq = CSRFRequest.new
csrfReq.get_token { |t| puts "#{t}"}
end
unless defined? MENU
# add a cmd for menu, toolbar or shortcut item...
title = 'TestSentioVR'
cmd = UI::Command.new(title) do
lazy_load
init
end
cmd.tooltip = cmd.status_bar_text = 'cmd_message...'
cmd.large_icon = cmd.small_icon = File.join(__dir__, 'Resources', 'images', 'name')
MENU ||= UI.menu('Plugins', title)
menu = MENU
# menu item
menu.add_item(cmd)
# create toolbar
TBAR ||= UI::Toolbar.new(title)
tb = TBAR
# toolbar item
tb.add_item(cmd)
# showing the toolbar
tb.get_last_state == TB_NEVER_SHOWN ? tb.show : tb.restore
end
if DEBUG
lazy_load
init
end
end
end
EDIT: made some minor changes to constantsâŚ
john
Thank you @john_drivenupthewall for explaining. I will try out these changes.
ENV["LOGNAME"]
is Mac only. Windows uses ENV["COMPUTERNAME"]
One more thing if on the startup I want to request some information from server.
Canât I do that like version check or login.
on SU startup there are could be lots of request coming from many extensionsâŚ
this can lead to missed conections, loading delays or even crashesâŚ
ALL extensions should do their checks only when the user wants to run them, not on SU startupâŚ
on Extension startup [ using âlazy loadingâ ], when the user clicks any of your buttons, you have a clear path for your checksâŚ
theyâll happen quicker and have less potential issuesâŚ
if they fail, you can let the user know without the risk of your message being swallowedâŚ
john
I tend to wrap everything in a proxy object, so that references can get passed to other objects, but initialization only occurs when a method is really called.
See Design Patterns in Ruby: Proxy. A clear example of the Proxy pattern | by D. L. Jerome | Medium for more info on the proxy design pattern.