Support electron env and build for linux

This commit is contained in:
ziajka 2018-01-04 11:42:43 +01:00
parent 6dfa755c50
commit da01ac99fe
7 changed files with 39 additions and 8 deletions

View File

@ -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"
}
}
],

View File

@ -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": {

View File

@ -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 {}

View File

@ -0,0 +1,4 @@
export const environment = {
production: true,
electron: true
};

View File

@ -0,0 +1,4 @@
export const environment = {
production: false,
electron: true
};

View File

@ -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
};

View File

@ -3,9 +3,17 @@
<head>
<meta charset="utf-8">
<title>GNS3 Web UI Demo</title>
<!-- <base href="./"> //-->
<script>document.write('<base href="' + document.location + '" />');</script>
<script>
var userAgent = navigator.userAgent.toLowerCase();
// in case we're running in electron because we need it for resources
if (userAgent.indexOf(' electron/') > -1) {
document.write('<base href="' + document.location + '" />');
}
// in case base href is not set, when not defined during the build time (for instance github.io pages)
else if (document.getElementsByTagName('base').length == 0) {
document.write('<base href="/" />');
}
</script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="assets/favicon.ico">