2017-04-11 4 views
0

Ich habe ein Problem zu verstehen, wie Winkel und Elektron zusammenarbeiten, über Routing sprechen. Nachdem das Hauptfenster mit Elektronen zu schaffen, was ich tun möchte, ist, eine Route verwendet wird, um ein neues Fenster mit dieser Route öffnete aber gab Fehler wie die folgenden:Angular2 und Elektronenroutenausgabe

http://localhost:4200/test/inline.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/polyfills.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/scripts.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/styles.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/vendor.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/main.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/inline.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/polyfills.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/scripts.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/styles.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/vendor.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:4200/test/main.bundle.js Failed to load resource: the server responded with a status of 404 (Not Found) 

Electron main.js Datei ist:

'use strict'; 
const electron = require('electron'); 
// Module to control application life. 
const { app, BrowserWindow, ipcMain } = electron; 

let win; 
let winAttendant; 

ipcMain.on('supportRequest', (e, type, threadObjectId) => { 
    // console.log(args[0]); 
    // e.sender.send('channel1', 'ok got it'); 
    // console.log('1:' + e + '2:' + type + '3:'+ threadObjectId) 
    if (type == 1) { 
     attendantWindow(1, threadObjectId); 
    } else if (type == 2) { 
     attendantWindow(2, threadObjectId); 
    } else { 
     attendantWindow(0); 
    } 

}) 

function attendantWindow(type, threadObjectId) { 
    if (type == 1) { 
     winAttendant = new BrowserWindow({ 
      x: 500, 
      y: 500, 
      minWidth: 300, 
      minHeight: 650 
     }); 

     winAttendant.loadURL('http://localhost:4200/attendantpage/'+ threadObjectId); 

     winAttendant.on('closed',() => { 
      // Dereference the window object, usually you would store windows 
      // in an array if your app supports multi windows, this is the time 
      // when you should delete the corresponding element. 
      win = null; 
     }); 
    } else if (type == 2) { 
     console.log('type is: 2 and id: ' + threadObjectId) 
     winAttendant = new BrowserWindow({ 
      x: 500, 
      y: 500, 
      minWidth: 300, 
      minHeight: 650 
     }); 
     console.log('http://localhost:4200/test/'); 
     winAttendant.loadURL('http://localhost:4200/test/'); 

     winAttendant.on('closed',() => { 
      // Dereference the window object, usually you would store windows 
      // in an array if your app supports multi windows, this is the time 
      // when you should delete the corresponding element. 
      win = null; 
     }); 
    } else { 
     winAttendant.close(); 
    } 
} 

function createWindow() { 

    let electronScreen = electron.screen; 
    let size = electronScreen.getPrimaryDisplay().workAreaSize; 

    // Create the browser window. 
    win = new BrowserWindow({ 
     minWidth: 900, 
     minHeight: 700, 
     center: true 
    }); 

    let url = 'file://' + __dirname + '/index.html'; 
    let Args = process.argv.slice(1); 

    Args.forEach(function (val) { 
     if (val === "--serve") { 
      url = 'http://localhost:4200' 
     } 
    }); 

    // and load the index.html of the app. 
    win.loadURL(url); 

    // Open the DevTools. 
    // win.webContents.openDevTools(); 

    // Emitted when the window is closed. 
    win.on('closed',() => { 
     // Dereference the window object, usually you would store windows 
     // in an array if your app supports multi windows, this is the time 
     // when you should delete the corresponding element. 
     win = null; 
    }); 
} 

// This method will be called when Electron has finished 
// initialization and is ready to create browser windows. 
// Some APIs can only be used after this event occurs. 
app.on('ready', createWindow); 

// Quit when all windows are closed. 
app.on('window-all-closed',() => { 
    // On OS X it is common for applications and their menu bar 
    // to stay active until the user quits explicitly with Cmd + Q 
    if (process.platform !== 'darwin') { 
     app.quit(); 
    } 
}); 

app.on('activate',() => { 
    // On OS X it's common to re-create a window in the app when the 
    // dock icon is clicked and there are no other windows open. 
    if (win === null) { 
     createWindow(); 
    } 
}); 

Komponente in einem neuen Fenster zu öffnen ist eine einfache neue und saubere Komponente mit ng GC-Test erstellt.

Kann mir jemand helfen, den Fehler zu verstehen?

Dank

Antwort

0

Ich wurde dieses Problem, weil der falsche Weg zu versuchen, mit Electron und angular2 zu beschäftigen.

in der richtigen Art und Weise zu behandeln und übergeben Sie Parameter zwischen Elektron und Angular2 nur Angular2 ActivatedRoute + ipcMain von Elektronen verwenden:

In Elektron main.js:

ipcMain.on('chat', (e, args) => { 
    console.log('mainjs threadId: ', args); 
    threadId = args; 
    createChatWindow(threadId); 
}); 

function createChatWindow(threadId) { 
    // Initialize the window to our specified dimensions 
    chatWin = new BrowserWindow({width: 400, height: 500}); 

    // Specify entry point 
    chatWin.loadURL('http://localhost:4200/attendantsupportchat;threadId='+threadId.threadId+';type='+threadId.type); 
    console.log(threadId.threadId); 

    // Remove window once app is closed 
    chatWin.on('closed', function() { 
    win = null; 
    }); 
}; 

In Angular2 Komponente:

import { ActivatedRoute } from '@angular/router'; 

dann im Konstruktor wie folgt initialisieren:

public activatedRoute: ActivatedRoute; 

und verwenden, wo so gebraucht wie:

this.paramsFromElectron = this.activatedRoute.snapshot.params; 
this.threadId = this.paramsFromElectron.threadId; 
this.threadType = this.paramsFromElectron.type; 

Hoffnung könnte

+0

Es funktioniert für eine gehostete Anwendung hilfreich sein 'http: // localhost: 4200' aber was ist eine lokale? – Ismael