0

basically I have an electron app and i've added minimize/close butttons to it on load the buttons work but after switching page with smoothstate they stop working i've found various solutions (github faq, stackoverlow, etc) but none worked so far

the buttons html

<div id="title-bar-btns">
    <button class="btn btn-outline" id="min-btn">—</button>
    <button class="btn btn-outline" id="close-btn">X</button>
</div>

the main.js

        $(function() {
        'use strict';
        var $page = $('#main'),
            options = {
                debug: !0,
                prefetch: !0,
                cacheLength: 4,
                onStart: {
                    duration: 350,
                    render: function($container) {
                        $container.addClass('is-exiting');
                        smoothState.restartCSSAnimations()
                    }
                },
                onReady: {
                    duration: 0,
                    render: function($container, $newContent) {
                        $container.removeClass('is-exiting');
                        $container.html($newContent)
                        initfunction();
                    }
                },
                onAfter: function($container, $newContent) {
                    initfunction();
                }
            },
            smoothState = $page.smoothState(options).data('smoothState')
    });
    $(document).ready(function() {
        initfunction();
    });

    function initfunction() {
        (function() {
            const {
                BrowserWindow
            } = require('electron').remote

            function init() {
                document.getElementById("min-btn").addEventListener("click", (e) => {
                    var window = BrowserWindow.getFocusedWindow();
                    window.minimize()
                });
                document.getElementById("close-btn").addEventListener("click", (e) => {
                    var window = BrowserWindow.getFocusedWindow();
                    window.close()
                })
            };
            document.onreadystatechange = () => {
                if (document.readyState == "complete") {
                    init()
                }
            }
        })()
    }
Zed
  • 25
  • 1
  • 4
  • It probably happens because you remove the buttons in the transition and then do not reattach the event listeners on re-render. In particular, your `init` is only called if `document.readyState == "complete"`, but that only happens once per page refresh (so on smoothstate change, it will not fire). Hope this helps – Andrei Cioara Mar 10 '19 at 21:15
  • @AndreiCioara what do you suggest me to do then? – Zed Mar 10 '19 at 23:07

0 Answers0