Gatohost / gatoclient

Gatoclient Rewritten - What people would have wanted
23 stars 16 forks source link

fix CSS imports + other various fixes #11

Closed LukeTheDuke240 closed 2 years ago

LukeTheDuke240 commented 2 years ago

Describe the bug CSS Imports do not work due to the wacky way you import css (appending it one after the other in a linear fashion) Additionally, the mainWindow is loaded weirdly using a 5 second timeout, lets speed that up a bit

Fix

Main.js

splashWindow.once('ready-to-show', () => {
    // if updates enabled call: autoUpdate();
    // else, launch immediately:
    launchGame();
});

Replace double function call with something cleaner, call loadURL only after window is set up, and add a .once listener so that the window is shown once ready.

    function launchGame() {
        mainWindow.setBackgroundColor('#000000');
        mainWindow.setSize(1600, 900);
        mainWindow.center();
        mainWindow.removeMenu();
        if (userPrefs['fullscreen'] == true) {
            mainWindow.setFullScreen(true);
            mainWindowIsFullscreen = true;
        }

        mainWindow.loadURL(url.format({
            pathname: 'https://krunker.io',
            icon: __dirname + 'src/cat.ico' // Doesn't work anymore just ignore it
        }));

        mainWindow.once('ready-to-show', () => {
            splashWindow.destroy();
            mainWindow.webContents.send('injectClientCSS', clientCSS);
            mainWindow.webContents.send('injectCustomCSS', customCSS);
            mainWindow.show();
        });
    }

Add show: false to mainWindow so that we do not have to hide it after creation

    //Make the window
    mainWindow = new BrowserWindow({
        autoHideMenuBar: true,
        show: false,
        webPreferences: {
            preload: path.join(__dirname, 'preload.js'),
            enableBlinkFeatures: 'enable-heavy-ad-intervention'
        }
    });

Read custom css before showing mainWindow and cache it.. The css is then injected once the window is shown.

    // CSS swap
    fs.readFile(swapperFolder + '/main_custom.css', "utf-8", function (error, data) {
        if (!error) {
            clientCSS = data.replace(/\s{2,10}/g, ' ').trim();
        }
    });

Preload.js Replace single CSS function with 2: one for client css and one for custom

ipcRenderer.on('injectClientCSS', (event, css) => {
    let s = document.createElement("style");
    s.setAttribute("id", "gatoclientCSS");
    s.innerHTML = css;
    document.getElementsByTagName("body")[0].appendChild(s);
});
ipcRenderer.on('injectCustomCSS', (event, css) => {
    let s = document.createElement("style");
    s.setAttribute("id", "customCSS");
    s.innerHTML = css;
    document.getElementsByTagName("body")[0].appendChild(s);
});

Additional requests Please provide a way to skip the auto update process to improve launch performance. Also please, please remove that 35MB gif file and replace it with something more efficient to save on bandwidth.

creepycats commented 2 years ago

Goated Fix. If you want badge dm i gib