Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The event bf2042-portal-extensions-init is no longer fired #29

Closed
p0lygun opened this issue Apr 26, 2023 · 1 comment
Closed

The event bf2042-portal-extensions-init is no longer fired #29

p0lygun opened this issue Apr 26, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@p0lygun
Copy link

p0lygun commented Apr 26, 2023

function hookWorkspaceSvg() {
const originalWorkspaceSvg = _Blockly.Workspace.prototype.constructor;
_Blockly.Workspace.prototype.constructor = function () {
originalWorkspaceSvg.apply(this, arguments);
setTimeout(function () {
initializeWorkspaceEvents();
BF2042Portal.Plugins.initializeWorkspace();
}, 0);
}
}

This is happening because the workspace now has its own instance and does not use the global Workspace class

one hacky solution is to use mutationObserver As I do in cool-plugins

    function hookWorkspaceSvg() {
        if(!_Blockly.getMainWorkspace()){
            setTimeout(hookWorkspaceSvg, 100);
            return;
        }
        setTimeout(
            function(){
                initializeWorkspaceEvents();
                BF2042Portal.Plugins.initializeWorkspace();
            }, 2000
        )
        if(!blocklyMutationObserver ){
            const rulesApp = document.getElementsByTagName('app-rules')[0]    
            blocklyMutationObserver = new MutationObserver(function(mutations) {
                mutations.forEach(function(mutation) {
                    if (mutation.type === "childList") {
                        if (!document.getElementsByTagName("app-blockly").length) {
                            blocklyLoaded = false
                        } else {
                            if(!blocklyLoaded){
                                setTimeout(
                                    function(){
                                        initializeWorkspaceEvents();
                                        BF2042Portal.Plugins.initializeWorkspace();
                                        blocklyLoaded = true;
                                    }, 100
                                )
                            }
                        }
                    }
                });
            });
            blocklyMutationObserver.observe(rulesApp, { attributes: false, childList: true, characterData: false });
        }
    }

This adds two new variables to track the state of blockly rules

p0lygun pushed a commit to p0lygun/BF2042-Portal-Extensions that referenced this issue Apr 26, 2023
@LennardF1989 LennardF1989 added the bug Something isn't working label May 1, 2023
@LennardF1989
Copy link
Owner

Closing this as it's tracked by #27 and should be fixed with 2.0.0-pr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants