sketchucation logo sketchucation
    • 登入
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    WebDialog on Mac (call to Google SU engineers)

    已排程 已置頂 已鎖定 已移動 Developers' Forum
    25 貼文 10 Posters 8.9k 瀏覽 10 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • thomthomT 離線
      thomthom
      最後由 編輯

      That sounds like you are sending back before the HTML DOM is ready. If you use jQuery use the 'ready' event to wait for the HTML DOM to be ready.

      How have you currently structured the loading event?

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 條回覆 最後回覆 回覆 引用 0
      • R 離線
        RonB
        最後由 編輯

        I guess you're right... i do have the skp callback somewhere in between of the page.
        I'll try to change it to jquery with the "wait for doc ready"-function and report back here.

        to answer your question: I'm creating a webdialog and connect by set_url to an url.
        Then i'm showing the dialog and wait for the callbacks.
        I hope that's what you was asking.

        1 條回覆 最後回覆 回覆 引用 0
        • A 離線
          Aerilius
          最後由 編輯

          I again stumbled across this issue, knowing JavaScript continues before the Ruby callback ends, but I didn't think that this async nature prevents subsequent urls to reach Ruby.

          Example of the Problem:

          w = UI;;WebDialog.new("Test")
          w.add_action_callback("1"){|dlg, param| puts("first callback")}
          w.add_action_callback("2"){|dlg, param| puts("second callback")}
          w.set_html("<html><body><script>window.location='skp;1'; window.location='skp;2';</script></body></html>")
          w.show
          

          On Windows:
          ` %(#000000)[> first callback

          second callback]On OSX: > second callback`

          Example solution:
          Doesn't make anything synchronous, but makes sure all urls reach Ruby.

          
          /* class Scheduler;
           * This class makes sure given functions are not called more frequently than a
           * certain time limit.
           * .queue(function)
           *     Adds a new function. All collected functions will be executed one by one with a time interval inbetween.
           */
          Scheduler = function(dt) {
            var scheduled = []; // Array of scheduled functions.
            var t = 0; // Tracks the time of the last function call.
            dt = (dt) ? Number(dt) ; 250; // Minimum time interval in milliseconds between subsequent function calls.
            this.queue = function(fn) {
              scheduled.push(fn);
              check();
            };
            var run = function() {
              var toRun = scheduled.shift();
              toRun();
            };
            var check = function() {
              var c = Number(new Date().getTime());
              // Last function call is long enough ago (or first time), execute given function immediately.
              if (c > t && scheduled.length > 0) {
                run();
                // Set timer for next possible function call.
                t = c + dt;
                window.setTimeout(check, dt);
              }
            };
          };
          
          
          /* An instance of the Scheduler */
          var callRubyScheduler = new Scheduler(1);
          
          
          /* Function to call a SketchUp Ruby action_callback. */
          var callRuby = function(name, data) {
            if (!data) { data = ''; }
            var url = 'skp;' + name + '@' + encodeURIComponent(data);
            callRubyScheduler.queue(function(){ window.location.href = url; });
          };
          
          

          On Windows:
          ` %(#000000)[> first callback

          second callback]On OSX: %(#000000)[> first callback
          second callback]`

          1 條回覆 最後回覆 回覆 引用 0
          • thomthomT 離線
            thomthom
            最後由 編輯

            Another way, that doesn't involve timing is to stack up messages in JS that call a receiving ruby method which takes care of forwarding to the correct ruby method and then send a ping back to JS which can then send the next message in the queue.

            I made a version like that which also gives JS a return value from ruby.

            Sent from my LT25i using Tapatalk 2

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 條回覆 最後回覆 回覆 引用 0
            • jolranJ 離線
              jolran
              最後由 編輯

              Ahh, missed this addition to this rather old topic. Interesting reading.

              Might be relative to Didier's recent topic.
              http://sketchucation.com/forums/viewtopic.php?f=180&t=51350

              I wonder if I could get some clarification about this:
              For ex, let say you have a dozen buttons that each is hooked up to it's own callback to Ruby with "window.location.href" for the callback.

              Even if the Ruby script is permitted to "finish" it's doing before pushing the next buttons, will there be a sync problem ?

              I'm having a hard time understanding how this issue behave since I don't have a Mac for testing it out myself.

              It seams like Arielius has a clever solution, but what if for ex one has a slider performing realtime transformation or such ?

              1 條回覆 最後回覆 回覆 引用 0
              • 1
              • 2
              • 2 / 2
              • 第一個貼文
                最後的貼文
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement