Sunday, 30 April 2017

Electron (electron-packager) Script with jQuery is not loaded

when I am building and packaging my electron app with electron-packager or electron-builder I got that problem that a js file I load in my app.js is not properly loaded / throws errors. I cant look up if there are any error besides jQuery because I cant oben the web console after packaging anymore. When I try to click the elements with the ids minimize etc. it simply does nothing. Here are some snippets:

package.json

{
  "name": "CloudSystem.iO",
  "productName": "CloudSystem.iO",
  "description": "A minimal Electron application",
  "version": "1.0.0",
  "main": "app.js",
  "private": true,
  "scripts": {
    "start": "electron .",
    "package": "electron-packager . CloudSystem.iO --platform=win32 --arch=x64 --overwrite --out ./dist/build --icon ./build/icon.ico",
    "build": "build --win --x64 --prepackaged ./dist/build/CloudSystem.iO-win32-x64",
    "dbuild": "build --win --x64"
  },
  "author": "Felix Gaebler",
  "devDependencies": {
    "electron": "1.4.15",
    "electron-cookies": "1.1.0",
    "extract-zip": "1.6.0"
  },
  "dependencies": {},
  "build": {
      "app-bundle-id": "org.test.mytest",
      "app-category-type": "public.app-category.utilities",
      "win": {
          "title": "CloudSystem.iO",
          "version": "1.0.0",
          "msi": true,
          "authors": "Felix Gaebler"
      }
    }
}

Part of app.js where subfile is loaded

const {app, BrowserWindow} = require('electron')
window = new BrowserWindow({title: 'CloudSystemIO', icon: 'img/logo.png', width: 1200, height: 800, minHeight: 79, minWidth: 500, center: true, frame: false, resizable: false, backgroundColor: '#22313a', show: false})

window.webContents.on('did-finish-load', ()=>{
    window.webContents.executeJavaScript("require('./js/desktop.js')");
});

Loaded js file (desktop.js)

var app_remote = require('electron').remote;
var cookies = require('electron-cookies');
var app_window = app_remote.getCurrentWindow();
var app_maximize = false;

$("#minimize").on("click", function() {
        app_window.minimize();
});

$("#maximize").on("click", function() {
        if (app_maximize) {
                app_window.unmaximize();
                $("#maximize").attr("class", "fa fa-window-maximize");
        } else {
                app_window.maximize();
                $("#maximize").attr("class", "fa fa-window-restore");
        }
        app_maximize = !app_maximize;
});

$("#close").on("click", function() {
        swal({title: 'Are you sure you want to quit?', showCancelButton: true, confirmButtonText: 'Quit', customClass: 'sweet'}).then(function () {
          app_window.close();
        });
});


via Felix Gaebler

No comments:

Post a Comment