Giter VIP home page Giter VIP logo

sketchup-bridge's People

Contributors

aerilius avatar dependabot[bot] avatar jiminy-billy-bob avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sketchup-bridge's Issues

Undefined method `call' for Bridge:Class

Hi. Sorry for my english. I just espeak portuguese. So, lets go. I trying to use Bridge.call on Sketchup 2022 and I have this issue:

"undefined method call' for PRBO::Devix::Bridge:Class (Line 1)" Error: #<TypeError: no implicit conversion of NoMethodError into String> C:/Users/paulo/AppData/Roaming/SketchUp/SketchUp 2022/SketchUp/Plugins/as_rubyeditor/as_rubyeditor.rb:346:in +'
C:/Users/paulo/AppData/Roaming/SketchUp/SketchUp 2022/SketchUp/Plugins/as_rubyeditor/as_rubyeditor.rb:346:in rescue in block in initialize' C:/Users/paulo/AppData/Roaming/SketchUp/SketchUp 2022/SketchUp/Plugins/as_rubyeditor/as_rubyeditor.rb:344:in block in initialize'

my code:

module PRBO
    module Devix    
    
    class DialogBox
    attr_accessor :dlg
    def initialize
        dialog = UI::HtmlDialog.new({
          :dialog_title => "Plugin Devix",
          :preferences_key => "com.sample.plugin",
          :scrollable => true,
          :resizable => true,
          :width => 1000,
          :height => 1000,
          :left => 100,
          :top => 100,
          :min_width => 800,
          :min_height => 50,
          :style => UI::HtmlDialog::STYLE_DIALOG
        })
        dialog.set_file('c:/DevixPlugin/html/index.html')
        @dlg = dialog
    end
  end   




    load "c:/DevixPlugin/lib/bridge/bridge.rb"
  
    def self.showMenu 
        dlg_menu = DialogBox.new
        dlg = dlg_menu.dlg
        Bridge.decorate(dlg)
        #Bridge.new(dlg)

        dlg.on('ponte') {|deferred, mensagemponte|
            p mensagemponte
            deferred.resolve(1000)
        }

        dlg.show
        Bridge.call('borogodo','testando')
    end
    showMenu

    end
end

############ my index.html

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Devix - Tools</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
    </style>
    <script type="text/javascript" src="./js/bridge.js"></script>
</head>
<body>
    <div class="container">
        <div class="Button">
            <button type="button" id="teste">Teste click</button>
        </div>
    </div>
    <script type="text/javascript">
        var botao = document.getElementById('teste');
        botao.addEventListener('click', function(event) {
            Bridge.get('ponte', 'mariola').then(function (testando) {
                window.alert(testando); 
            });
        });
        function borogodo() {
            window.alert("Mensagem vinda do Sketchup"); 
        };
    </script>
    
</body>
</html>

################
when a click on button on the html file, the Bridge works. I wanna make work from sketchup. On event, call a function on index.html and return some data.

Originally posted by @PRBO84 in #13 (comment)

Missing fields when using Bridge.call() from the Ruby side with mixed hashes

Hi :)

I might have found a serialization bug.

I have this issue where some fields sent over from the Ruby side are missing on the JS side. After a lot of testing, it seems to be happening with mixed Ruby hashes (with both symbols and string keys) sent via call().

How to reproduce from the Ruby side:

hash1 = { # all symbols, will work fine
  a: 1,
  b: 'hello'
}

hash2 = { # all strings, will work fine
  'a' => 1,
  'b' => 'hello'
}
 
hash3 = {  # mixed, b will be missing
  'a' => 1,
  b: 'hello'
}

call('test', hash1)
call('test', hash2)
call('test', hash3)

The output on the JS side:

test: Object {a: 1, b: "hello"}
test: Object {a: 1, b: "hello"}
test: Object {a: 1}

Interestingly, this does not happen when sending data via promise resolution:

on('test1') do |deferred|
  deferred.resolve({ a: 1, b: 'hello' })
end

on('test2') do |deferred|
  deferred.resolve({ 'a' => 1, 'b' => 'hello' })
end

# This time it works
on('test3') do |deferred|
  deferred.resolve({ 'a' => 1, b: 'hello' })
end

So maybe there's a serialization inconsistency between call() and resolve()?

I tried poking a bit in the code but at first glance I cannot see what goes wrong.

Offer as an ES6 import?

It might be good to package this as a separate ES6 module to import. I'm not totally sure how to go from the IIFE that bridge.js currently is to a module export.

To be clear, this would help my use case, though I expect that the current form is most useful to a general audience who will drop this in a script tag instead.

Modifying frozen string

constant RESERVED_NAMES is a frozen array, and thus can't be mutated with the << method.

def add_default_handlers
# Puts (for debugging)
@handlers["#{NAMESPACE}.puts"] = Proc.new { |dialog, *arguments|
puts(*arguments.map { |argument| argument.inspect })
}
RESERVED_NAMES << "#{NAMESPACE}.puts"
# Error channel (for debugging)
@handlers["#{NAMESPACE}.error"] = Proc.new { |dialog, type, message, backtrace|
log_error(type + ': ' + message, {:language => 'javascript', :backtrace => backtrace})
}
RESERVED_NAMES << "#{NAMESPACE}.error"
end

Could either remove the call to freeze or refactor this to be a pure function that takes the old RESERVED_NAMES as an argument and returns a new array. What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.