mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-01-18 18:56:26 +00:00
Communication with electron, Ref. #13
This commit is contained in:
parent
37acae2697
commit
0ee66da007
43
main.js
43
main.js
@ -1,22 +1,30 @@
|
||||
const electron = require('electron');
|
||||
var fs = require('fs');
|
||||
// Module to control application life.
|
||||
const fs = require('fs');
|
||||
const app = electron.app;
|
||||
// Module to create native browser window.
|
||||
const BrowserWindow = electron.BrowserWindow;
|
||||
|
||||
const path = require('path');
|
||||
const url = require('url');
|
||||
const yargs = require('yargs');
|
||||
|
||||
require('./sentry');
|
||||
|
||||
// Keep a global reference of the window object, if you don't, the window will
|
||||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
let mainWindow;
|
||||
|
||||
let serverProc = null;
|
||||
|
||||
let isWin = /^win/.test(process.platform);
|
||||
let isDev = false;
|
||||
|
||||
const argv = yargs
|
||||
.describe('m', 'Maximizes window on startup.')
|
||||
.boolean('m')
|
||||
.describe('e', 'Environment, `dev` for developer mode and when not specified then production mode. ')
|
||||
.choices('e', ['dev', null])
|
||||
.argv;
|
||||
|
||||
if (argv.e == 'dev') {
|
||||
isDev = true;
|
||||
}
|
||||
|
||||
|
||||
const createServerProc = () => {
|
||||
@ -64,15 +72,26 @@ function createWindow () {
|
||||
mainWindow = new BrowserWindow({width: 800, height: 600});
|
||||
|
||||
// and load the index.html of the app.
|
||||
mainWindow.loadURL(url.format({
|
||||
pathname: path.join(__dirname, 'dist/index.html'),
|
||||
protocol: 'file:',
|
||||
slashes: true
|
||||
}));
|
||||
|
||||
if(isDev) {
|
||||
mainWindow.loadURL('http://localhost:4200/');
|
||||
mainWindow.webContents.openDevTools();
|
||||
}
|
||||
else {
|
||||
mainWindow.loadURL(url.format({
|
||||
pathname: path.join(__dirname, 'dist/index.html'),
|
||||
protocol: 'file:',
|
||||
slashes: true
|
||||
}));
|
||||
}
|
||||
|
||||
// Open the DevTools.
|
||||
// mainWindow.webContents.openDevTools();
|
||||
|
||||
if(argv.m) {
|
||||
mainWindow.maximize();
|
||||
}
|
||||
|
||||
// Emitted when the window is closed.
|
||||
mainWindow.on('closed', function () {
|
||||
// Dereference the window object, usually you would store windows
|
||||
@ -109,3 +128,5 @@ app.on('activate', function () {
|
||||
|
||||
// In this file you can include the rest of your app's specific main process
|
||||
// code. You can also put them in separate files and require them here.
|
||||
|
||||
|
||||
|
@ -16,7 +16,8 @@
|
||||
"test": "ng test",
|
||||
"lint": "ng lint",
|
||||
"e2e": "ng e2e",
|
||||
"electrondev": "concurrently -k \"yarn startforelectron\" \"electron .\"",
|
||||
"electron": "electron .",
|
||||
"electrondev": "concurrently -k \"yarn startforelectron\" \"electron . -e dev\"",
|
||||
"distlinux": "yarn buildforelectron && electron-builder --linux --x64",
|
||||
"distwin": "yarn buildforelectron && electron-builder --win --x64",
|
||||
"distmac": "yarn buildforelectron && electron-builder --mac --x64",
|
||||
@ -47,6 +48,7 @@
|
||||
"npm-check-updates": "^2.13.0",
|
||||
"raven-js": "^3.24.0",
|
||||
"rxjs": "^5.4.1",
|
||||
"yargs": "^11.0.0",
|
||||
"zone.js": "^0.8.20"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
23
sentry.js
23
sentry.js
@ -1,6 +1,8 @@
|
||||
const { SentryClient } = require('@sentry/electron');
|
||||
var fs = require('fs');
|
||||
const fs = require('fs');
|
||||
const { ipcMain } = require('electron');
|
||||
|
||||
let crashReportsEnabled = true;
|
||||
const DSN =
|
||||
'https://cb7b474b2e874afb8e400c47d1452ecc:7876224cbff543d992cb0ac4021962f8@sentry.io/1040940';
|
||||
|
||||
@ -8,8 +10,17 @@ const isDev = () => {
|
||||
return fs.existsSync('.git');
|
||||
};
|
||||
|
||||
if (!isDev()) {
|
||||
SentryClient.create({
|
||||
dsn: DSN
|
||||
});
|
||||
}
|
||||
const shouldSendCallback = () => {
|
||||
return !isDev() && crashReportsEnabled;
|
||||
};
|
||||
|
||||
|
||||
ipcMain.on('settings.changed', function (event, settings) {
|
||||
crashReportsEnabled = settings.crash_reports;
|
||||
});
|
||||
|
||||
|
||||
SentryClient.create({
|
||||
dsn: DSN,
|
||||
shouldSendCallback: shouldSendCallback
|
||||
});
|
||||
|
@ -25,6 +25,7 @@ export class AppComponent implements OnInit {
|
||||
ngOnInit(): void {
|
||||
if (this.electronService.isElectronApp) {
|
||||
this.settingsService.subscribe((settings) => {
|
||||
console.log("settings changed on angular");
|
||||
this.electronService.ipcRenderer.send('settings.changed', settings);
|
||||
});
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { PersistenceService, StorageType } from "angular-persistence";
|
||||
import { Subject } from "rxjs/Subject";
|
||||
import { BehaviorSubject } from "rxjs/BehaviorSubject";
|
||||
|
||||
|
||||
export interface Settings {
|
||||
@ -14,11 +15,10 @@ export class SettingsService {
|
||||
'crash_reports': true
|
||||
};
|
||||
|
||||
private settingsSubject: Subject<Settings>;
|
||||
private settingsSubject: BehaviorSubject<Settings>;
|
||||
|
||||
constructor(private persistenceService: PersistenceService) {
|
||||
this.settingsSubject = new Subject<Settings>();
|
||||
this.settingsSubject.next(this.getAll());
|
||||
this.settingsSubject = new BehaviorSubject<Settings>(this.getAll());
|
||||
}
|
||||
|
||||
get<T>(key: string) {
|
||||
|
Loading…
Reference in New Issue
Block a user