From da01ac99fe2526ac096f6c7ff5753efc1bbb5a75 Mon Sep 17 00:00:00 2001 From: ziajka Date: Thu, 4 Jan 2018 11:42:43 +0100 Subject: [PATCH] Support electron env and build for linux --- .angular-cli.json | 4 +++- package.json | 4 ++-- src/app/app-routing.module.ts | 14 +++++++++++++- src/environments/environment.electron.prod.ts | 4 ++++ src/environments/environment.electron.ts | 4 ++++ src/environments/environment.ts | 3 ++- src/index.html | 14 +++++++++++--- 7 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 src/environments/environment.electron.prod.ts create mode 100644 src/environments/environment.electron.ts diff --git a/.angular-cli.json b/.angular-cli.json index be4d2227..725534db 100644 --- a/.angular-cli.json +++ b/.angular-cli.json @@ -28,7 +28,9 @@ "environmentSource": "environments/environment.ts", "environments": { "dev": "environments/environment.ts", - "prod": "environments/environment.prod.ts" + "prod": "environments/environment.prod.ts", + "electronProd": "environments/environment.electron.prod.ts", + "electronDev": "environments/environment.electron.ts" } } ], diff --git a/package.json b/package.json index 84276a59..87476502 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,8 @@ "test": "ng test", "lint": "ng lint", "e2e": "ng e2e", - "electrondev": "concurrently -k \"ng serve\" \"electron .\"", - "distlinux": "ng build --prod && electron-builder --linux" + "electrondev": "concurrently -k \"ng serve -e electronDev\" \"electron .\"", + "distlinux": "ng build -e electronProd && electron-builder --linux" }, "build": { "directories": { diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 0c5e2539..efbda56f 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -1,3 +1,5 @@ +import { environment } from "../environments/environment"; + import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; @@ -6,6 +8,7 @@ import { ServersComponent } from "./servers/servers.component"; import { ProjectsComponent } from "./projects/projects.component"; import { DefaultLayoutComponent } from "./default-layout/default-layout.component"; + const routes: Routes = [ { path: '', component: DefaultLayoutComponent, children: [ @@ -17,8 +20,17 @@ const routes: Routes = [ { path: 'server/:server_id/project/:project_id', component: ProjectMapComponent }, ]; +let routerModule; +if (environment.electron) { + // angular in electron has problem with base-href and links separated by slashes, because of that + // we use simply hashes + routerModule = RouterModule.forRoot(routes, {useHash: true}); +} else { + routerModule = RouterModule.forRoot(routes); +} + @NgModule({ - imports: [ RouterModule.forRoot(routes, {useHash: true}) ], + imports: [ routerModule ], exports: [ RouterModule ] }) export class AppRoutingModule {} diff --git a/src/environments/environment.electron.prod.ts b/src/environments/environment.electron.prod.ts new file mode 100644 index 00000000..b7954d59 --- /dev/null +++ b/src/environments/environment.electron.prod.ts @@ -0,0 +1,4 @@ +export const environment = { + production: true, + electron: true +}; diff --git a/src/environments/environment.electron.ts b/src/environments/environment.electron.ts new file mode 100644 index 00000000..2a4b4a8f --- /dev/null +++ b/src/environments/environment.electron.ts @@ -0,0 +1,4 @@ +export const environment = { + production: false, + electron: true +}; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index b7f639ae..99a525bc 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -4,5 +4,6 @@ // The list of which env maps to which file can be found in `.angular-cli.json`. export const environment = { - production: false + production: false, + electron: false }; diff --git a/src/index.html b/src/index.html index 36372e75..9c999545 100644 --- a/src/index.html +++ b/src/index.html @@ -3,9 +3,17 @@ GNS3 Web UI Demo - - - +