chore: merge branch 'release/2.0.1'

This commit is contained in:
Amadou Ada DIENE
2021-07-22 13:50:36 +02:00
49 changed files with 86743 additions and 82885 deletions

View File

@@ -1,28 +1,38 @@
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript"
],
"parser": "@typescript-eslint/parser",
"settings": {
"import/resolver": {
"node": {
"extensions": [
".js",
".jsx",
".ts",
".tsx"
]
}
}
}
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript"
],
"parser": "@typescript-eslint/parser",
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
},
"ignorePatterns": ["**/dist/**/*", "**/.dist/**/*"],
"rules": {
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_"
}
],
"@typescript-eslint/no-explicit-any": [
"error",
{
"ignoreRestArgs": true
}
]
}
}

1
.husky/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
_;

30
.husky/_/husky.sh Normal file
View File

@@ -0,0 +1,30 @@
#!/bin/sh
if [ -z "$husky_skip_init" ]; then
debug () {
[ "$HUSKY_DEBUG" = "1" ] && echo "husky (debug) - $1"
}
readonly hook_name="$(basename "$0")"
debug "starting $hook_name..."
if [ "$HUSKY" = "0" ]; then
debug "HUSKY env variable is set to 0, skipping hook"
exit 0
fi
if [ -f ~/.huskyrc ]; then
debug "sourcing ~/.huskyrc"
. ~/.huskyrc
fi
export readonly husky_skip_init=1
sh -e "$0" "$@"
exitCode="$?"
if [ $exitCode != 0 ]; then
echo "husky - $hook_name hook exited with code $exitCode (error)"
exit $exitCode
fi
exit 0
fi

4
.husky/commit-msg Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx --no-install commitlint --edit "$1"

5
.husky/pre-commit Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged
npx pretty-quick --staged

8
.prettierrc Normal file
View File

@@ -0,0 +1,8 @@
{
"useTabs": true,
"tabSize": 2,
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true
}

12
.versionrc.json Normal file
View File

@@ -0,0 +1,12 @@
{
"types": [
{ "type": "feat", "section": "Features" },
{ "type": "fix", "section": "Bug Fixes" },
{ "type": "chore", "hidden": true },
{ "type": "docs", "hidden": true },
{ "type": "style", "hidden": true },
{ "type": "refactor", "hidden": true },
{ "type": "perf", "hidden": true },
{ "type": "test", "hidden": true }
]
}

View File

@@ -1,40 +1,24 @@
# 2.0.0 (2021-07-19)
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### Bug Fixes
* reopening window crash on macos ([f442df7](https://github.com/sourcygen/electron-angular-quick-start/commit/f442df72c4120fb616d21c5c4e245a5eb478f57e))
## 2.1.0 (2021-07-22)
### Features
* disable remote content execution ([0c82cf4](https://github.com/sourcygen/electron-angular-quick-start/commit/0c82cf425930de7368debfbc6176a3ef8ed7591e))
* adapt angular part ([83301e0](https://github.com/sourcygen/electron-angular-quick-start/commit/83301e0fe7387e791d23f7c1d6cdaeb1f53e3cf4))
* adapt electron part ([73acf88](https://github.com/sourcygen/electron-angular-quick-start/commit/73acf88a079984e50c15e23e5ad0aa98b0a7c2a1))
* add electron dependencies ([f506c0c](https://github.com/sourcygen/electron-angular-quick-start/commit/f506c0c2ab613ec0d72863f5a30c2c1ce553dcd2))
* add electron e2e launch scripts ([7e02b37](https://github.com/sourcygen/electron-angular-quick-start/commit/7e02b37b10f54f7bbb66e88f7e433ba67594287b))
* add electron packaging scripts ([afd8916](https://github.com/sourcygen/electron-angular-quick-start/commit/afd8916d7143b258ed273d613f15135f91cb8edd))
* add spectron and utility dependencies ([a100e3c](https://github.com/sourcygen/electron-angular-quick-start/commit/a100e3c488fde1cc2d60229f47032331b201f7b5))
* angular upgrade : 9.1.1 => 10.1.3 ([66c7d03](https://github.com/sourcygen/electron-angular-quick-start/commit/66c7d033ac8bb6841d232e214b9b262fc08abcec))
* change project structure to meet targeted architecture ([9c8788f](https://github.com/sourcygen/electron-angular-quick-start/commit/9c8788fb2e419ae63c3a6545f4c5966547232702))
* change project structure to meet targeted architecture ([ea90fd8](https://github.com/sourcygen/electron-angular-quick-start/commit/ea90fd845f8188c5fd4f867d7ec7f80ffd1b6e3f))
* conventional commit setup ([4a0397f](https://github.com/sourcygen/electron-angular-quick-start/commit/4a0397f56e10e6e88312eeda2f9716d4314b1ea0))
* decrease security in e2e tests ([8543cf1](https://github.com/sourcygen/electron-angular-quick-start/commit/8543cf148c498caa3e3298d8f08b14d16b5426b0))
* electron upgrade : 8.2.3 => 10.1.3 ([0924b4a](https://github.com/sourcygen/electron-angular-quick-start/commit/0924b4a4bd5f45867d5aeb832079f89e997e36f2))
* env config setup ([8822440](https://github.com/sourcygen/electron-angular-quick-start/commit/8822440f7dfa4452b588520cca5179121b276188))
* i18n setup with ngx-translate ([f17719c](https://github.com/sourcygen/electron-angular-quick-start/commit/f17719c7e8d4c7798b299a6d500712f903ddda3e))
* icon settings ([720223e](https://github.com/sourcygen/electron-angular-quick-start/commit/720223ec7ff4984445dcb52fe06ffe3386756367))
* init electron e2e code source ([45a02e3](https://github.com/sourcygen/electron-angular-quick-start/commit/45a02e392c0fd755df33760db7f4adbbd31d9616))
* init new angular project with angular cli ([cae7f62](https://github.com/sourcygen/electron-angular-quick-start/commit/cae7f629aafe69edb9aaaa6907615e5a2138b05a))
* init shared code source ([647889c](https://github.com/sourcygen/electron-angular-quick-start/commit/647889cd70d8d334122ea33c376f8cb51cf3fe7d))
* log setup with winston ([fd598bb](https://github.com/sourcygen/electron-angular-quick-start/commit/fd598bb10de942869a857e8927831aa87f768024))
* migrate from electron-webpack to electron-forge ([4fa2999](https://github.com/sourcygen/electron-angular-quick-start/commit/4fa299996145deb61e3b65d3d05faab0bd8a25e1))
* move production dependencies into development dependencies ([47c74d0](https://github.com/sourcygen/electron-angular-quick-start/commit/47c74d015d130a15768be5e783b80f9bfcc97754))
* other dependencies upgrade ([39efb20](https://github.com/sourcygen/electron-angular-quick-start/commit/39efb2060034b27d9a45a1d197212bdcd61d7636))
* packaging config ([2559e97](https://github.com/sourcygen/electron-angular-quick-start/commit/2559e973dcf1478f81e25d6acb7332f3edf91dcc))
* use npm instead of yarn (issues with binaries) ([aa338ca](https://github.com/sourcygen/electron-angular-quick-start/commit/aa338ca75e401250b24da06755edbae06d083229))
- git hook config (husky eslint prettier) ([77b15bd](https://github.com/sourcygen/electron-angular-quick-start/commit/77b15bdfc4355afa63cd7517e87da0029a804691))
- cypress setup for angular e2e tests ([7a3d5d7](https://github.com/sourcygen/electron-angular-quick-start/commit/7a3d5d7d3aaf92c4de9c89349a14c59d84d38afb))
- crossplatform icon config ([4e9506a](https://github.com/sourcygen/electron-angular-quick-start/commit/4e9506aca5515dd32b481b9c6d26c5c79598dcea))
### Bug Fixes
- fixing eslint problems ([1a5a76f](https://github.com/sourcygen/electron-angular-quick-start/commit/1a5a76f9121115db65ad3e1cb07f0b008c2e958a))
# 2.0.0 (2021-07-19)
### Features
- migrate from electron-webpack to electron-forge ([4fa2999](https://github.com/sourcygen/electron-angular-quick-start/commit/4fa299996145deb61e3b65d3d05faab0bd8a25e1))
## 1.0.2 (2020-09-29)

103726
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,153 +1,155 @@
{
"name": "electron-angular-quick-start",
"productName": "electron-angular-quick-start",
"version": "2.0.0",
"description": "An Electron and Angular Quick-starter",
"repository": "https://github.com/sourcygen/electron-angular-quick-start.git",
"author": "Sourcygen",
"license": "MIT",
"main": ".webpack/main",
"keywords": [
"angular",
"angular 12",
"electron",
"electron 13",
"typescript",
"typescript 4",
"spectron",
"spectron 15",
"scss",
"live reload"
],
"workspaces": [
"workspaces/angular-app",
"workspaces/shared-lib"
],
"watch": {
"restart-electron-app": {
"patterns": [
"workspaces/electron-app",
"workspaces/shared-lib"
],
"extensions": "ts,tsx"
}
},
"scripts": {
"start": "npm-run-all -p start:shared-lib start:angular-app start:electron-app",
"start:shared-lib": "tsc -b workspaces/shared-lib -w",
"start:angular-app": "cd workspaces/angular-app && npm run start",
"start:electron-app": "wait-on http://localhost:4200 && npm-watch restart-electron-app",
"restart-electron-app": "electron-forge start",
"package": "npm run package:angular-app && npm run package:electron-app",
"package:angular-app": "cd workspaces/angular-app && npm run package",
"package:electron-app": "electron-forge package",
"make": "npm run package:angular-app && electron-forge make",
"publish": "electron-forge publish",
"lint": "eslint --ext .ts .",
"test:electron-e2e": "npm run package && cross-env X_NODE_ENV=e2e-test node workspaces/electron-e2e/jasmine.js",
"clean": "del -f .webpack out node_modules workspaces/shared-lib/dist workspaces/angular-app/node_modules workspaces/angular-app/dist",
"version": "npx conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"
},
"config": {
"forge": {
"packagerConfig": {},
"makers": [
{
"name": "@electron-forge/maker-dmg",
"config": {
"name": "EAQS"
}
},
{
"name": "@electron-forge/maker-squirrel",
"config": {
"name": "electron_angular_quick_start"
}
},
{
"name": "@electron-forge/maker-zip",
"platforms": []
},
{
"name": "@electron-forge/maker-deb",
"config": {}
},
{
"name": "@electron-forge/maker-rpm",
"config": {}
}
],
"plugins": [
[
"@electron-forge/plugin-webpack",
{
"mainConfig": "./webpack.main.config.js",
"renderer": {
"config": "./webpack.renderer.config.js",
"entryPoints": [
{
"html": "./workspaces/electron-app/renderer/index.html",
"js": "./workspaces/electron-app/renderer/index.ts",
"name": "main_window",
"preload": {
"js": "./workspaces/electron-app/renderer/preload.ts"
}
}
]
}
}
]
]
}
},
"devDependencies": {
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@electron-forge/cli": "^6.0.0-beta.57",
"@electron-forge/maker-deb": "^6.0.0-beta.57",
"@electron-forge/maker-dmg": "^6.0.0-beta.58",
"@electron-forge/maker-rpm": "^6.0.0-beta.57",
"@electron-forge/maker-squirrel": "^6.0.0-beta.57",
"@electron-forge/maker-zip": "^6.0.0-beta.57",
"@electron-forge/plugin-webpack": "6.0.0-beta.57",
"@types/jasmine": "^3.8.1",
"@types/jasminewd2": "^2.0.10",
"@types/lodash": "^4.14.171",
"@types/node": "^14.17.5",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"@vercel/webpack-asset-relocator-loader": "^1.6.0",
"conventional-changelog-cli": "^2.1.1",
"copy-webpack-plugin": "^9.0.1",
"cross-env": "^7.0.3",
"css-loader": "^5.0.0",
"del-cli": "^4.0.1",
"electron": "^13.1.7",
"eslint": "^7.6.0",
"eslint-plugin-import": "^2.20.0",
"fork-ts-checker-webpack-plugin": "^6.0.1",
"husky": "^7.0.1",
"jasmine": "^3.8.0",
"jasmine-core": "^3.8.0",
"jasmine-spec-reporter": "^7.0.0",
"node-loader": "^2.0.0",
"npm-run-all": "^4.1.5",
"npm-watch": "^0.10.0",
"spectron": "^15.0.0",
"style-loader": "^2.0.0",
"ts-loader": "^9.2.2",
"ts-node": "^10.1.0",
"typescript": "^4.0.2",
"wait-on": "^6.0.0"
},
"dependencies": {
"electron-squirrel-startup": "^1.0.0",
"fs-extra": "^10.0.0",
"winston": "^3.3.3"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
"name": "electron-angular-quick-start",
"productName": "electron-angular-quick-start",
"version": "2.1.0",
"description": "An Electron and Angular Quick-starter",
"repository": "https://github.com/sourcygen/electron-angular-quick-start.git",
"author": "Sourcygen",
"license": "MIT",
"main": ".webpack/main",
"keywords": [
"angular",
"angular 12",
"electron",
"electron 13",
"typescript",
"typescript 4",
"spectron",
"spectron 15",
"scss",
"live reload"
],
"workspaces": [
"workspaces/angular-app",
"workspaces/shared-lib"
],
"watch": {
"restart-electron-app": {
"patterns": [
"workspaces/electron-app",
"workspaces/shared-lib"
],
"extensions": "ts,tsx"
}
},
"scripts": {
"start": "npm-run-all -p start:shared-lib start:angular-app start:electron-app",
"start:shared-lib": "tsc -b workspaces/shared-lib -w",
"start:angular-app": "cd workspaces/angular-app && npm run start",
"start:electron-app": "wait-on http://localhost:4200 && npm-watch restart-electron-app",
"restart-electron-app": "electron-forge start",
"package": "npm run package:angular-app && npm run package:electron-app",
"package:angular-app": "cd workspaces/angular-app && npm run package",
"package:electron-app": "electron-forge package",
"make": "npm run package:angular-app && electron-forge make",
"publish": "electron-forge publish",
"lint": "eslint --ext .ts .",
"test:e2e": "npm run test:angular-e2e && npm run test:electron-e2",
"test:angular-e2e": "npm-run-all -p -r start:angular-app start:angular-e2e",
"start:angular-e2e": "wait-on http://localhost:4200 && cd workspaces/angular-app && npm run cypress:run",
"test:electron-e2e": "npm run package && cross-env X_NODE_ENV=e2e-test node workspaces/electron-e2e/jasmine.js",
"clean": "shx rm -rf .webpack out node_modules workspaces/shared-lib/.dist workspaces/angular-app/node_modules workspaces/angular-app/.dist",
"version": "npx conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md",
"prepare": "husky install",
"postinstall": "husky install && shx rm -rf .git/hooks && shx ln -s ../.husky .git/hooks",
"release": "standard-version",
"release:minor": "standard-version --release-as minor",
"release:patch": "standard-version --release-as patch",
"release:major": "standard-version --release-as major"
},
"config": {
"forge": {
"packagerConfig": {
"name": "electron-angular",
"icon": "./workspaces/electron-app/main/assets/icons/icon"
},
"makers": [
{
"name": "@electron-forge/maker-dmg",
"config": {}
},
{
"name": "@electron-forge/maker-deb",
"config": {}
},
{
"name": "@electron-forge/maker-squirrel"
}
],
"plugins": [
[
"@electron-forge/plugin-webpack",
{
"mainConfig": "./webpack.main.config.js",
"renderer": {
"config": "./webpack.renderer.config.js",
"entryPoints": [
{
"html": "./workspaces/electron-app/renderer/index.html",
"js": "./workspaces/electron-app/renderer/index.ts",
"name": "main_window",
"preload": {
"js": "./workspaces/electron-app/renderer/preload.ts"
}
}
]
}
}
]
]
}
},
"devDependencies": {
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@electron-forge/cli": "^6.0.0-beta.57",
"@electron-forge/maker-deb": "^6.0.0-beta.57",
"@electron-forge/maker-dmg": "^6.0.0-beta.58",
"@electron-forge/maker-rpm": "^6.0.0-beta.57",
"@electron-forge/maker-squirrel": "^6.0.0-beta.57",
"@electron-forge/maker-zip": "^6.0.0-beta.57",
"@electron-forge/plugin-webpack": "6.0.0-beta.57",
"@types/jasmine": "^3.8.1",
"@types/jasminewd2": "^2.0.10",
"@types/lodash": "^4.14.171",
"@types/node": "^14.17.5",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"@vercel/webpack-asset-relocator-loader": "^1.6.0",
"conventional-changelog-cli": "^2.1.1",
"copy-webpack-plugin": "^9.0.1",
"cross-env": "^7.0.3",
"css-loader": "^5.0.0",
"electron": "^13.1.7",
"eslint": "^7.6.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-prettier": "^3.4.0",
"fork-ts-checker-webpack-plugin": "^6.0.1",
"husky": "^7.0.1",
"jasmine": "^3.8.0",
"jasmine-core": "^3.8.0",
"jasmine-spec-reporter": "^7.0.0",
"lint-staged": "^11.0.1",
"node-loader": "^2.0.0",
"npm-run-all": "^4.1.5",
"npm-watch": "^0.10.0",
"prettier": "^2.3.2",
"shx": "^0.3.3",
"spectron": "^15.0.0",
"standard-version": "^9.3.1",
"style-loader": "^2.0.0",
"ts-loader": "^9.2.2",
"ts-node": "^10.1.0",
"typescript": "^4.3.5",
"wait-on": "^6.0.0"
},
"dependencies": {
"electron-squirrel-startup": "^1.0.0",
"fs-extra": "^10.0.0",
"winston": "^3.3.3"
},
"lint-staged": {
"*.ts": "npm run lint"
}
}

View File

@@ -1,23 +1,20 @@
{
"compilerOptions": {
"allowJs": true,
"module": "es2020",
"target": "es2015",
"skipLibCheck": true,
"esModuleInterop": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"sourceMap": true,
"baseUrl": ".",
"outDir": "dist",
"moduleResolution": "node",
"resolveJsonModule": true,
"paths": {
"*": ["node_modules/*"]
}
},
"include": [
"workspaces/electron-app/**/*",
"workspaces/electron-e2e/**/*"
]
"compilerOptions": {
"allowJs": true,
"module": "es2020",
"target": "es2015",
"skipLibCheck": true,
"esModuleInterop": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"sourceMap": true,
"baseUrl": ".",
"outDir": ".dist",
"moduleResolution": "node",
"resolveJsonModule": true,
"paths": {
"*": ["node_modules/*"]
}
},
"include": ["workspaces/electron-app/**/*", "workspaces/electron-e2e/**/*"]
}

View File

@@ -1,30 +1,30 @@
const path = require("path");
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
/**
* This is the main entry point for your application, it's the first file
* that runs in the main process.
*/
entry: './workspaces/electron-app/main/index.ts',
// Put your normal webpack config below here
module: {
rules: require('./webpack.rules'),
},
resolve: {
extensions: ['.js', '.ts', '.jsx', '.tsx', '.css', '.json'],
modules: [path.resolve(__dirname, "node_modules"), "node_modules"]
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{ from: "workspaces/electron-app/main/assets" },
{
from: "workspaces/angular-app/dist",
to: "../renderer/angular_window",
noErrorOnMissing: true
}
],
}),
],
};
/**
* This is the main entry point for your application, it's the first file
* that runs in the main process.
*/
entry: './workspaces/electron-app/main/index.ts',
// Put your normal webpack config below here
module: {
rules: require('./webpack.rules'),
},
resolve: {
extensions: ['.js', '.ts', '.jsx', '.tsx', '.css', '.json'],
modules: [path.resolve(__dirname, 'node_modules'), 'node_modules'],
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{ from: 'workspaces/electron-app/main/assets' },
{
from: 'workspaces/angular-app/.dist/angular-app',
to: '../renderer/angular_window',
noErrorOnMissing: true,
},
],
}),
],
};

View File

@@ -1,16 +0,0 @@
# Editor configuration, see https://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[*.ts]
quote_type = single
[*.md]
max_line_length = off
trim_trailing_whitespace = false

View File

@@ -1,7 +1,7 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/.dist
/tmp
/out-tsc
# Only exists if Bazel was run

View File

@@ -1,111 +1,132 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"angular-app": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
},
"@schematics/angular:application": {
"strict": true
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "./dist",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"outputHashing": "all"
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "angular-app:build:production"
},
"development": {
"browserTarget": "angular-app:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "angular-app:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
}
}
}
}
},
"defaultProject": "angular-app"
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"angular-app": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "scss"
},
"@schematics/angular:application": {
"strict": true
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "./.dist/angular-app",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.scss"],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"outputHashing": "all"
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "angular-app:build:production"
},
"development": {
"browserTarget": "angular-app:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "angular-app:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"inlineStyleLanguage": "scss",
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.scss"],
"scripts": []
}
},
"cypress-run": {
"builder": "@cypress/schematic:cypress",
"options": {
"devServerTarget": "angular-app:serve"
},
"configurations": {
"production": {
"devServerTarget": "angular-app:serve:production"
}
}
},
"cypress-open": {
"builder": "@cypress/schematic:cypress",
"options": {
"watch": true,
"headless": false
}
},
"e2e": {
"builder": "@cypress/schematic:cypress",
"options": {
"devServerTarget": "angular-app:serve",
"watch": true,
"headless": false
},
"configurations": {
"production": {
"devServerTarget": "angular-app:serve:production"
}
}
}
}
}
},
"defaultProject": "angular-app"
}

View File

@@ -0,0 +1,11 @@
{
"integrationFolder": "cypress/integration",
"supportFile": "cypress/support/index.ts",
"videosFolder": "cypress/videos",
"screenshotsFolder": "cypress/screenshots",
"pluginsFile": "cypress/plugins/index.ts",
"fixturesFolder": "cypress/fixtures",
"baseUrl": "http://localhost:4200",
"screenshotOnRunFailure": false,
"video": false
}

View File

@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}

View File

@@ -0,0 +1,7 @@
describe('My First Test', () => {
it('Visits the initial project page', () => {
cy.visit('/');
cy.contains('Welcome');
cy.contains('electron-angular-quick-start app is running!');
});
});

View File

@@ -0,0 +1,5 @@
// Plugins enable you to tap into, modify, or extend the internal behavior of Cypress
// For more info, visit https://on.cypress.io/plugins-api
module.exports = (_on, _config) => {
// configure plugins here
};

View File

@@ -0,0 +1,43 @@
// ***********************************************
// This example namespace declaration will help
// with Intellisense and code completion in your
// IDE or Text Editor.
// ***********************************************
// declare namespace Cypress {
// interface Chainable<Subject = any> {
// customCommand(param: any): typeof customCommand;
// }
// }
//
// function customCommand(param: any): void {
// console.warn(param);
// }
//
// NOTE: You can use it like so:
// Cypress.Commands.add('customCommand', customCommand);
//
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

View File

@@ -0,0 +1,17 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// When a command from ./commands is ready to use, import with `import './commands'` syntax
// import './commands';

View File

@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"include": ["**/*.ts"],
"compilerOptions": {
"sourceMap": false,
"types": ["cypress"]
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,37 +1,42 @@
{
"name": "angular-app",
"version": "2.0.0",
"scripts": {
"start": "ng serve",
"package": "ng build --configuration production --base-href ./"
},
"private": true,
"dependencies": {
"@angular/animations": "~12.1.2",
"@angular/common": "~12.1.2",
"@angular/compiler": "~12.1.2",
"@angular/core": "~12.1.2",
"@angular/forms": "~12.1.2",
"@angular/platform-browser": "~12.1.2",
"@angular/platform-browser-dynamic": "~12.1.2",
"@angular/router": "~12.1.2",
"@ngx-translate/core": "^13.0.0",
"@ngx-translate/http-loader": "^6.0.0",
"electron": "^13.1.7",
"rxjs": "~6.6.0",
"tslib": "^2.2.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "~12.1.2",
"@angular/cli": "~12.1.2",
"@angular/compiler-cli": "~12.1.2",
"@types/node": "^12.11.1",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "~1.7.0",
"typescript": "~4.3.2"
}
"name": "angular-app",
"version": "2.0.0",
"scripts": {
"start": "ng serve",
"package": "ng build --configuration production --base-href ./",
"e2e": "ng e2e",
"cypress:open": "cypress open",
"cypress:run": "cypress run"
},
"private": true,
"dependencies": {
"@angular/animations": "~12.1.2",
"@angular/common": "~12.1.2",
"@angular/compiler": "~12.1.2",
"@angular/core": "~12.1.2",
"@angular/forms": "~12.1.2",
"@angular/platform-browser": "~12.1.2",
"@angular/platform-browser-dynamic": "~12.1.2",
"@angular/router": "~12.1.2",
"@ngx-translate/core": "^13.0.0",
"@ngx-translate/http-loader": "^6.0.0",
"electron": "^13.1.7",
"rxjs": "~6.6.0",
"tslib": "^2.2.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "~12.1.2",
"@angular/cli": "~12.1.2",
"@angular/compiler-cli": "~12.1.2",
"@cypress/schematic": "^1.4.2",
"@types/node": "^12.11.1",
"karma": "~6.3.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "~1.7.0",
"typescript": "^4.3.5",
"cypress": "8.0.0"
}
}

View File

@@ -9,27 +9,27 @@ import { AppComponent } from './app.component';
import { MutiplesComponent } from './components/mutiples/mutiples.component';
// AoT requires an exported function for factories
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
export function HttpLoaderFactory(http: HttpClient): TranslateHttpLoader {
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}
@NgModule({
declarations: [AppComponent, MutiplesComponent],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
ReactiveFormsModule,
TranslateModule.forRoot({
defaultLanguage: 'en',
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient],
},
}),
],
providers: [],
bootstrap: [AppComponent],
declarations: [AppComponent, MutiplesComponent],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
ReactiveFormsModule,
TranslateModule.forRoot({
defaultLanguage: 'en',
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient],
},
}),
],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}

View File

@@ -5,44 +5,47 @@ import { WindowApiConst } from 'shared-lib';
import { ElectronIpcService } from '../../services/electron-ipc.service';
@Component({
selector: 'app-mutiples',
templateUrl: './mutiples.component.html',
styleUrls: ['./mutiples.component.scss'],
selector: 'app-mutiples',
templateUrl: './mutiples.component.html',
styleUrls: ['./mutiples.component.scss'],
})
export class MutiplesComponent implements OnInit {
timesTableForm = new FormGroup({
input: new FormControl(Math.round(Math.random() * 100) % 10),
});
timesTableForm = new FormGroup({
input: new FormControl(Math.round(Math.random() * 100) % 10),
});
multiples = [];
multiples: number[] = [];
constructor(
private electronIpc: ElectronIpcService,
private translate: TranslateService
) {}
constructor(
private electronIpc: ElectronIpcService,
private translate: TranslateService
) {}
ngOnInit(): void {
// Specifying what to do with received data from main process
this.electronIpc.receive(WindowApiConst.MULTIPLES_OUTPUT, (...data: []) => {
// Update current data
this.multiples = data;
});
ngOnInit(): void {
// Specifying what to do with received data from main process
this.electronIpc.receive<number[]>(
WindowApiConst.MULTIPLES_OUTPUT,
(output: number[]) => {
// Update current data
this.multiples = output;
}
);
// Reset multiples on form changes
this.timesTableForm.valueChanges.subscribe((value) => {
this.multiples = [];
});
// Reset multiples on form changes
this.timesTableForm.valueChanges.subscribe(() => {
this.multiples = [];
});
// Init time tables with given random value
this.onSubmit();
}
// Init time tables with given random value
this.onSubmit();
}
translateIn(lang: string) {
this.translate.use(lang);
}
translateIn(lang: string): void {
this.translate.use(lang);
}
onSubmit() {
const intput = this.timesTableForm.value.input;
this.electronIpc.send(WindowApiConst.MULTIPLES_INPUT, intput);
}
onSubmit(): void {
const input = this.timesTableForm.value.input;
this.electronIpc.send(WindowApiConst.MULTIPLES_INPUT, input);
}
}

View File

@@ -2,43 +2,39 @@ import { Injectable, NgZone } from '@angular/core';
import { WindowApi } from 'shared-lib';
@Injectable({
providedIn: 'root',
providedIn: 'root',
})
export class ElectronIpcService {
private _api!: WindowApi;
private _api!: WindowApi;
constructor(private zone: NgZone) {
if (window && (window as any).api) {
try {
this._api = (window as any).api;
} catch (e) {
throw e;
}
console.log('Preloader API has been loaded successfully');
} else {
console.warn('Preloader API is not loaded');
}
}
constructor(private zone: NgZone) {
if (window && (window as Window).api) {
this._api = (window as Window).api;
console.log('Preloader API has been loaded successfully');
} else {
console.warn('Preloader API is not loaded');
}
}
public receive(channel: string, func: (...data: any) => void): void {
if (this._api) {
this._api.receive(channel, (...data) => {
console.log(`Received from main process channel [${channel}]`, data);
public receive<Out>(channel: string, func: (output: Out) => void): void {
if (this._api) {
this._api.receive<Out>(channel, (output) => {
console.log(`Received from main process channel [${channel}]`, output);
// Next code might run outside of Angular zone and therefore Angular
// doesn't recognize it needs to run change detection
// Further details on SO : https://stackoverflow.com/a/49136353/11480016
this.zone.run(() => {
func(...data);
});
});
}
}
// Next code might run outside of Angular zone and therefore Angular
// doesn't recognize it needs to run change detection
// Further details on SO : https://stackoverflow.com/a/49136353/11480016
this.zone.run(() => {
func(output);
});
});
}
}
public send(channel: string, ...data: any): void {
if (this._api) {
console.log(`Sending to main process channel [${channel}]`, data);
this._api.send(channel, ...data);
}
}
public send<In>(channel: string, input: In): void {
if (this._api) {
console.log(`Sending to main process channel [${channel}]`, input);
this._api.send<In>(channel, input);
}
}
}

View File

@@ -1,31 +1,28 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2017",
"module": "es2020",
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
},
"references": [{ "path": "../shared-lib" }]
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./.dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2017",
"module": "es2020",
"lib": ["es2018", "dom"]
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
},
"references": [{ "path": "../shared-lib" }]
}

View File

@@ -1,29 +1,29 @@
{
"development": {
"config_id": "development",
"mainLogFile": "dist/dev-main.log",
"mainLogLevel": "debug",
"isIconAvailable": true,
"isNodeIntegration": false,
"isContextIsolation": true,
"isEnableRemoteModule": false,
"isOpenDevTools": true
},
"e2e-test": {
"config_id": "e2e-test",
"mainLogFile": "dist/e2e-main.log",
"mainLogLevel": "error",
"isIconAvailable": true,
"isNodeIntegration": true,
"isContextIsolation": false,
"isEnableRemoteModule": true,
"isOpenDevTools": false
},
"production": {
"config_id": "production",
"mainLogFile": "main.log",
"mainLogLevel": "error",
"isIconAvailable": false,
"isOpenDevTools": true
}
"development": {
"configId": "development",
"mainLogFile": "dist/dev-main.log",
"mainLogLevel": "debug",
"isIconAvailable": true,
"isNodeIntegration": false,
"isContextIsolation": true,
"isEnableRemoteModule": false,
"isOpenDevTools": true
},
"e2e-test": {
"configId": "e2e-test",
"mainLogFile": "dist/e2e-main.log",
"mainLogLevel": "error",
"isIconAvailable": true,
"isNodeIntegration": true,
"isContextIsolation": false,
"isEnableRemoteModule": true,
"isOpenDevTools": false
},
"production": {
"configId": "production",
"mainLogFile": "main.log",
"mainLogLevel": "error",
"isIconAvailable": false,
"isOpenDevTools": false
}
}

View File

@@ -0,0 +1,14 @@
# Install the icon generator globally
> npm i -g electron-icon-maker
# Run following command from anywhere you have your input file to generate platforms icons
> electron-icon-maker --input=icon.png --output=./out
# Rename and move files to match with next config
- ./workspaces/electron-app/main/assets/icons/icon.png for Linux
- ./workspaces/electron-app/main/assets/icons/icon.icns for MacOs
- ./workspaces/electron-app/main/assets/icons/icon.ico for Windows
x

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 231 KiB

View File

@@ -2,64 +2,62 @@ import { app, BrowserWindow, shell } from 'electron';
import { Window } from './window';
export class App {
private static _wrapper: Window;
private static _wrapper: Window;
public static launch() {
app.on('window-all-closed', App.quit);
app.on('activate', App.start);
app.on('ready', App.start);
public static launch(): void {
app.on('window-all-closed', App.quit);
app.on('activate', App.start);
app.on('ready', App.start);
// Fix warning by applying electron new default value for this property
// Further details : https://github.com/electron/electron/issues/18397
app.allowRendererProcessReuse = true;
// Fix warning by applying electron new default value for this property
// Further details : https://github.com/electron/electron/issues/18397
app.allowRendererProcessReuse = true;
// Limit navigation and open external links in default browser
app.on('web-contents-created', App.openExternalLinksInDefaultBrowser);
}
// Limit navigation and open external links in default browser
app.on('web-contents-created', App.openExternalLinksInDefaultBrowser);
}
public static get window(): BrowserWindow | any {
return this._wrapper ? this._wrapper.window : null;
}
public static get electronWindow(): BrowserWindow | undefined {
return this._wrapper ? this._wrapper.electronWindow : undefined;
}
private static start() {
// On MacOS it is common to re-create a window from app even after all windows have been closed
if (!App.window) {
App._wrapper = new Window();
}
}
private static start() {
// On MacOS it is common to re-create a window from app even after all windows have been closed
if (!App.electronWindow) {
App._wrapper = new Window();
}
}
private static quit() {
// On MacOS it is common for applications to stay open until the user explicitly quits
if (process.platform !== 'darwin') {
app.quit();
}
}
private static quit() {
// On MacOS it is common for applications to stay open until the user explicitly quits
if (process.platform !== 'darwin') {
app.quit();
}
}
private static openExternalLinksInDefaultBrowser = (
event: Electron.Event,
contents: Electron.WebContents
) => {
// Disabling creation of new windows
contents.on(
'new-window',
(event: Electron.Event, navigationUrl: string) => {
// Blocking this event from loading in current app
event.preventDefault();
// Telling the user platform to open this event's url in the default browser
shell.openExternal(navigationUrl);
}
);
private static openExternalLinksInDefaultBrowser = (
event: Electron.Event,
contents: Electron.WebContents
) => {
// Disabling creation of new windows
contents.setWindowOpenHandler((handler: Electron.HandlerDetails) => {
// Telling the user platform to open this event's url in the default browser
shell.openExternal(handler.url);
// Limiting navigation
contents.on(
'will-navigate',
(event: Electron.Event, navigationUrl: string) => {
const parsedUrl = new URL(navigationUrl);
// Allowing local navigation only
if (parsedUrl.origin !== 'http://localhost:4200') {
event.preventDefault();
}
}
);
};
// Blocking this event from loading in current app
return { action: 'deny' };
});
// Limiting navigation
contents.on(
'will-navigate',
(event: Electron.Event, navigationUrl: string) => {
const parsedUrl = new URL(navigationUrl);
// Allowing local navigation only
if (parsedUrl.origin !== 'http://localhost:4200') {
event.preventDefault();
}
}
);
};
}

View File

@@ -1,116 +1,119 @@
import { app, BrowserWindow, ipcMain, nativeImage } from "electron";
import * as path from "path";
import * as url from "url";
import { AbstractService } from "../services/abstract-service";
import { MultiplesService } from "../services/multiples-service";
import { Logger } from "../utils/logger";
import { app, BrowserWindow, ipcMain, nativeImage } from 'electron';
import * as path from 'path';
import { AbstractService } from '../services/abstract-service';
import { MultiplesService } from '../services/multiples-service';
import { Logger } from '../utils/logger';
declare const global: any;
declare const global: Global;
declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string;
export class Window {
private _window: BrowserWindow | any;
private _electronWindow: BrowserWindow | undefined;
constructor() {
this.createWindow();
this.loadRenderer();
this.registerService(MultiplesService);
}
constructor() {
this.createWindow();
this.loadRenderer();
this.registerService<number, number[]>(new MultiplesService());
}
private createWindow(): void {
this._window = new BrowserWindow({
width: 800,
height: 600,
backgroundColor: "#FFFFFF",
// FIXME
// icon: this.loadIcon(),
webPreferences: {
// Default behavior in Electron since 5, that
// limits the powers granted to remote content
// except in e2e test when those powers are required by Spectron
nodeIntegration: global.gConfig.isNodeIntegration,
// Isolate window context to protect against prototype pollution
// except in e2e test when that access is required by Spectron
contextIsolation: global.gConfig.isContextIsolation,
// Ensure that JS values can't unsafely cross between worlds
// when using contextIsolation
worldSafeExecuteJavaScript: global.gConfig.isContextIsolation,
// Disable the remote module to enhance security
// except in e2e test when that access is required by Spectron
enableRemoteModule: global.gConfig.isEnableRemoteModule,
// Use a preload script to enhance security
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
},
});
}
private createWindow(): void {
this._electronWindow = new BrowserWindow({
width: 1280,
height: 720,
backgroundColor: '#FFFFFF',
icon: this.loadIcon(),
webPreferences: {
// Default behavior in Electron since 5, that
// limits the powers granted to remote content
// except in e2e test when those powers are required by Spectron
nodeIntegration: global.appConfig.isNodeIntegration,
// Isolate window context to protect against prototype pollution
// except in e2e test when that access is required by Spectron
contextIsolation: global.appConfig.isContextIsolation,
// Ensure that JS values can't unsafely cross between worlds
// when using contextIsolation
worldSafeExecuteJavaScript: global.appConfig.isContextIsolation,
// Disable the remote module to enhance security
// except in e2e test when that access is required by Spectron
enableRemoteModule: global.appConfig.isEnableRemoteModule,
// Use a preload script to enhance security
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY,
},
});
}
private loadIcon(): Electron.NativeImage {
let iconObj = null;
if (global.gConfig.isIconAvailable) {
const iconPath = path.join(__dirname, "icons/icon.png");
Logger.debug("Icon Path", iconPath);
iconObj = nativeImage.createFromPath(iconPath);
// Change dock icon on MacOS
if (iconObj && process.platform === "darwin") {
app.dock.setIcon(iconObj);
}
}
return iconObj;
}
private loadIcon(): Electron.NativeImage | undefined {
let iconObj = undefined;
if (global.appConfig.isIconAvailable) {
const iconPath = path.join(__dirname, 'icons/icon.png');
Logger.debug('Icon Path', iconPath);
iconObj = nativeImage.createFromPath(iconPath);
// Change dock icon on MacOS
if (iconObj && process.platform === 'darwin') {
app.dock.setIcon(iconObj);
}
}
return iconObj;
}
private loadRenderer(): void {
if (global.gConfig.config_id === "development") {
// Dev mode, take advantage of the live reload by loading local URL
this.window.loadURL(`http://localhost:4200`);
} else {
// Else mode, we simply load angular bundle
const indexPath = url.format({
pathname: path.join(__dirname, `../renderer/angular_window/index.html`),
protocol: "file:",
slashes: true,
});
this.window.loadURL(indexPath);
}
private loadRenderer(): void {
if (global.appConfig.configId === 'development') {
// Dev mode, take advantage of the live reload by loading local URL
this.electronWindow.loadURL(`http://localhost:4200`);
} else {
// Else mode, we simply load angular bundle
const indexPath = path.join(
__dirname,
'../renderer/angular_window/index.html'
);
this.electronWindow.loadURL(`file://${indexPath}`);
}
if (global.gConfig.isOpenDevTools) {
this.openDevTools();
}
if (global.appConfig.isOpenDevTools) {
this.openDevTools();
}
// When the window is closed`
this._window.on("closed", () => {
// Remove IPC Main listeners
ipcMain.removeAllListeners();
// Delete current reference
delete this._window;
});
}
// When the window is closed`
this._electronWindow.on('closed', () => {
// Remove IPC Main listeners
ipcMain.removeAllListeners();
// Delete current reference
delete this._electronWindow;
});
}
private openDevTools(): void {
this._window.webContents.openDevTools();
this._window.webContents.on("devtools-opened", () => {
this._window.focus();
setImmediate(() => {
this._window.focus();
});
});
}
private openDevTools(): void {
this._electronWindow.webContents.openDevTools();
this._electronWindow.webContents.on('devtools-opened', () => {
this._electronWindow.focus();
setImmediate(() => {
this._electronWindow.focus();
});
});
}
private registerService(AnyService: typeof AbstractService) {
const service = new AnyService();
ipcMain.on(service.receptionChannel(), async (event, ...args) => {
// Handling input
Logger.debug(`Received [${service.receptionChannel()}]`, args);
const data = await service.process(...args);
private registerService<In, Out>(service: AbstractService<In, Out>) {
ipcMain.on(
service.receptionChannel(),
async (event: Electron.IpcMainEvent, ...args: any[]) => {
// Handling input
const input = args[0];
Logger.debug(`[${service.receptionChannel()}] =====> `, input);
const output: Out = await service.process(input);
// Handling output
if (service.sendingChannel()) {
Logger.debug(`Sent [${service.sendingChannel()}]`, data);
this._window.webContents.send(service.sendingChannel(), ...data);
}
});
}
// Handling output
if (service.sendingChannel()) {
Logger.debug(`[${service.sendingChannel()}] =====> `, output);
this._electronWindow.webContents.send(
service.sendingChannel(),
output
);
}
}
);
}
public get window(): BrowserWindow | any {
return this._window;
}
public get electronWindow(): BrowserWindow | undefined {
return this._electronWindow;
}
}

View File

@@ -1,19 +1,27 @@
import * as fs from "fs-extra";
import * as _ from "lodash";
import * as path from "path";
import { App } from "./components/app";
import * as fs from 'fs-extra';
import * as _ from 'lodash';
import * as path from 'path';
import { AppConfig } from 'shared-lib';
import { App } from './components/app';
declare const global: any;
declare const global: Global;
declare global {
// Global augmentation of the `Global` interface
interface Global {
appConfig: AppConfig;
}
}
// Load config
const currentEnv = process.env.X_NODE_ENV || process.env.NODE_ENV;
const appConfig =
currentEnv === "development"
? fs.readJsonSync(path.join(__dirname, "config.json"))
: fs.readJsonSync(path.join(__dirname, "config.json"));
const defaultConf = appConfig.development;
const currentConf = appConfig[currentEnv];
global.gConfig = _.merge(defaultConf, currentConf);
const appConfigs = fs.readJsonSync(path.join(__dirname, 'config.json'));
const defaultConf = appConfigs.development;
const currentConf = appConfigs[currentEnv];
global.appConfig =
currentEnv === 'development'
? defaultConf
: _.merge(defaultConf, currentConf);
// Launch app
App.launch();

View File

@@ -1,13 +1,13 @@
export class AbstractService {
receptionChannel(): string {
throw new Error('Method not implemented.');
}
export class AbstractService<In, Out> {
receptionChannel(): string {
throw new Error('Method not implemented yet.');
}
sendingChannel(): string {
throw new Error('Method not implemented.');
}
sendingChannel(): string {
throw new Error('Method not implemented yet.');
}
process(...args: any): any {
throw new Error('Method not implemented.');
}
process(_input: In): Out {
throw new Error('Method not implemented yet.');
}
}

View File

@@ -1,21 +1,21 @@
import { WindowApiConst } from "shared-lib";
import { AbstractService } from "./abstract-service";
import { WindowApiConst } from 'shared-lib';
import { AbstractService } from './abstract-service';
export class MultiplesService extends AbstractService {
receptionChannel(): string {
return WindowApiConst.MULTIPLES_INPUT;
}
export class MultiplesService extends AbstractService<number, number[]> {
receptionChannel(): string {
return WindowApiConst.MULTIPLES_INPUT;
}
sendingChannel(): string {
return WindowApiConst.MULTIPLES_OUTPUT;
}
sendingChannel(): string {
return WindowApiConst.MULTIPLES_OUTPUT;
}
process(...args: any): any {
// From 1 to 10, return input multiples
const multiples = [];
for (let n = 1; n <= 10; n++) {
multiples.push(n * args[0]);
}
return multiples;
}
process(input: number): number[] {
// From 1 to 10, return input multiples
const multiples = [];
for (let n = 1; n <= 10; n++) {
multiples.push(n * input);
}
return multiples;
}
}

View File

@@ -1,139 +1,143 @@
import { app } from "electron";
import * as os from "os";
import * as path from "path";
import * as winston from "winston";
import { app } from 'electron';
import * as os from 'os';
import * as path from 'path';
import * as winston from 'winston';
declare const global: any;
declare const global: Global;
export class Logger {
private static singleton: Logger;
private _logger: winston.Logger;
private static singleton: Logger;
private _logger: winston.Logger;
public static error(message: string, ...meta: any[]) {
Logger.initSingleton();
Logger.singleton._logger.error(message, ...meta);
}
public static error(message: string, ...meta: any[]): void {
Logger.initSingleton();
Logger.singleton._logger.error(message, meta);
}
public static warn(message: string, ...meta: any[]) {
Logger.initSingleton();
Logger.singleton._logger.warn(message, ...meta);
}
public static warn(message: string, ...meta: any[]): void {
Logger.initSingleton();
Logger.singleton._logger.warn(message, meta);
}
public static info(message: string, ...meta: any[]) {
Logger.initSingleton();
Logger.singleton._logger.info(message, ...meta);
}
public static info(message: string, ...meta: any[]): void {
Logger.initSingleton();
Logger.singleton._logger.info(message, meta);
}
public static http(message: string, ...meta: any[]) {
Logger.initSingleton();
Logger.singleton._logger.http(message, ...meta);
}
public static http(message: string, ...meta: any[]): void {
Logger.initSingleton();
Logger.singleton._logger.http(message, meta);
}
public static verbose(message: string, ...meta: any[]) {
Logger.initSingleton();
Logger.singleton._logger.verbose(message, ...meta);
}
public static verbose(message: string, ...meta: any[]): void {
Logger.initSingleton();
Logger.singleton._logger.verbose(message, meta);
}
public static debug(message: string, ...meta: any[]) {
Logger.initSingleton();
Logger.singleton._logger.debug(message, ...meta);
}
public static debug(message: string, ...meta: any[]): void {
Logger.initSingleton();
Logger.singleton._logger.debug(message, meta);
}
public static silly(message: string, ...meta: any[]) {
Logger.initSingleton();
Logger.singleton._logger.silly(message, ...meta);
}
public static silly(message: string, ...meta: any[]): void {
Logger.initSingleton();
Logger.singleton._logger.silly(message, meta);
}
private static initSingleton() {
if (!Logger.singleton) {
Logger.singleton = new Logger();
}
}
private static initSingleton(): void {
if (!Logger.singleton) {
Logger.singleton = new Logger();
}
}
private constructor() {
this._logger = winston.createLogger({
level: "debug",
format: winston.format.json(),
defaultMeta: { service: "user-service" },
transports: [
new winston.transports.File({
filename: this.getLogFilename(),
level: global.gConfig.mainLogLevel,
format: winston.format.combine(
winston.format.timestamp(),
this.fileFormat
),
}),
],
});
private constructor() {
this._logger = winston.createLogger({
level: 'debug',
format: winston.format.json(),
defaultMeta: { service: 'user-service' },
transports: [
new winston.transports.File({
filename: this.getLogFilename(),
level: global.appConfig.mainLogLevel,
format: winston.format.combine(
winston.format.timestamp(),
this.fileFormat
),
}),
],
});
// If we're not in production then log also to the `console` with the format:
// `${info.timestamp} ${info.level}: ${info.message} JSON.stringify({ ...rest }) `
if (global.gConfig.config_id === "development") {
this._logger.add(
new winston.transports.Console({
stderrLevels: ["error", "warn"],
format: winston.format.combine(
winston.format.timestamp(),
this.consoleFormat
),
})
);
}
}
// If we're not in production then log also to the `console` with the format:
// `${info.timestamp} ${info.level}: ${info.message} JSON.stringify({ ...rest }) `
if (global.appConfig.configId === 'development') {
this._logger.add(
new winston.transports.Console({
stderrLevels: ['error', 'warn'],
format: winston.format.combine(
winston.format.timestamp(),
this.consoleFormat
),
})
);
}
}
/**
* Returns log filename with standard path
* In production, returns absolute standard path depending on platform
*/
private getLogFilename() {
let filename = global.gConfig.mainLogFile;
if (global.gConfig.config_id === "production") {
const appName = app.getName();
if (process.platform == "linux") {
filename = `.config/${appName}/${filename}`;
} else if (process.platform == "darwin") {
filename = `Library/Logs/${appName}/${filename}`;
} else if (process.platform == "win32") {
filename = `AppData\\Roaming\\${appName}\\${filename}`;
}
}
return path.join(os.homedir(), filename);
}
/**
* Returns log filename with standard path
* In production, returns absolute standard path depending on platform
*/
private getLogFilename() {
let filename = global.appConfig.mainLogFile;
if (global.appConfig.configId === 'production') {
const appName = app.getName();
if (process.platform == 'linux') {
filename = `.config/${appName}/${filename}`;
} else if (process.platform == 'darwin') {
filename = `Library/Logs/${appName}/${filename}`;
} else if (process.platform == 'win32') {
filename = `AppData\\Roaming\\${appName}\\${filename}`;
}
}
return path.join(os.homedir(), filename);
}
/**
* Custom winston file format
* Write JSON logs with given format :
* `${timestamp} ${level} : ${info.message} : ${meta})`
*/
private fileFormat = winston.format.printf((data: any) => {
return JSON.stringify(this.prepareLogData(data));
});
/**
* Custom winston file format
* Write JSON logs with given format :
* `${timestamp} ${level} : ${info.message} : ${meta})`
*/
private fileFormat = winston.format.printf(
(data: winston.Logform.TransformableInfo) => {
return JSON.stringify(this.prepareLogData(data));
}
);
/**
* Custom winston console format
* Write logs with given format :
* `${timestamp} ${level} : ${info.message} : JSON.stringify({ ...meta }) `
*/
private consoleFormat = winston.format.printf((data: any) => {
const preparedData = this.prepareLogData(data);
return (
`${preparedData.timestamp} ${preparedData.level} : ` +
`${preparedData.message} : ${JSON.stringify(preparedData.meta)}`
);
});
/**
* Custom winston console format
* Write logs with given format :
* `${timestamp} ${level} : ${info.message} : JSON.stringify({ ...meta }) `
*/
private consoleFormat = winston.format.printf(
(data: winston.Logform.TransformableInfo) => {
const preparedData = this.prepareLogData(data);
return (
`${preparedData.timestamp} ${preparedData.level} : ` +
`${preparedData.message} : ${JSON.stringify(preparedData.meta)}`
);
}
);
private prepareLogData = (data: any) => {
const additionalData = { ...data };
delete additionalData.timestamp;
delete additionalData.level;
delete additionalData.message;
delete additionalData.service;
return {
timestamp: data.timestamp,
level: data.level,
message: data.message,
meta: additionalData,
};
};
private prepareLogData = (data: winston.Logform.TransformableInfo) => {
const additionalData = { ...data };
delete additionalData.timestamp;
delete additionalData.level;
delete additionalData.message;
delete additionalData.service;
return {
timestamp: data.timestamp,
level: data.level,
message: data.message,
meta: additionalData,
};
};
}

View File

@@ -1,32 +1,35 @@
// To secure user platform when running renderer process stuff,
// Node.JS and Electron APIs are only available in this script
import { contextBridge, ipcRenderer } from "electron";
import { WindowApi, WindowApiConst } from "shared-lib";
import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron';
import { WindowApi, WindowApiConst } from 'shared-lib';
// So we expose protected methods that allow the renderer process
// to use the ipcRenderer without exposing the entire object
const windowApi: WindowApi = {
send: (channel: any, ...data: any) => {
if (WindowApiConst.SENDING_SAFE_CHANNELS.includes(channel)) {
ipcRenderer.send(channel, ...data);
}
},
receive: (channel: string, func: (...data: any) => void) => {
if (WindowApiConst.RECEIVING_SAFE_CHANNELS.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event, ...args) => func(...args));
}
},
send: <In>(channel: string, input: In) => {
if (WindowApiConst.SENDING_SAFE_CHANNELS.includes(channel)) {
ipcRenderer.send(channel, input);
}
},
receive: <Out>(channel: string, func: (output: Out) => void) => {
if (WindowApiConst.RECEIVING_SAFE_CHANNELS.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event: IpcRendererEvent, ...args: any[]) =>
func(args[0])
);
}
},
};
declare const window: any;
if (process.env.X_NODE_ENV === "e2e-test") {
// Injecting windowApi directly
window.api = windowApi;
declare const window: Window;
if (process.env.X_NODE_ENV === 'e2e-test') {
// Injecting windowApi directly
window.api = windowApi;
} else {
// ContextBridge API can only be used when contextIsolation is enabled
// which is normally the case except in e2e test mode
contextBridge.exposeInMainWorld("api", windowApi);
// ContextBridge API can only be used when contextIsolation is enabled
// which is normally the case except in e2e test mode
contextBridge.exposeInMainWorld('api', windowApi);
}
console.log("The preload script has been injected successfully.");
console.log(typeof window);
console.log('The preload script has been injected successfully.');

View File

@@ -1,22 +1,24 @@
const Jasmine = require("jasmine");
const { SpecReporter } = require("jasmine-spec-reporter");
const Jasmine = require('jasmine');
const { SpecReporter } = require('jasmine-spec-reporter');
const jasmine = new Jasmine();
jasmine.loadConfig({
showColors: true,
defaultTimeoutInterval: 15000,
spec_dir: "workspaces/electron-e2e",
spec_files: ["./**/*-spec.ts"],
helpers: ["./**/*-helper.ts"],
random: false,
seed: null,
stopSpecOnExpectationFailure: false,
showColors: true,
defaultTimeoutInterval: 15000,
spec_dir: 'workspaces/electron-e2e',
spec_files: ['./**/*-spec.ts'],
helpers: ['./**/*-helper.ts'],
random: false,
seed: undefined,
stopSpecOnExpectationFailure: false,
});
jasmine.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
require("ts-node").register({
project: require("path").join(__dirname, "./tsconfig.json"),
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.json'),
});
jasmine.env.clearReporters();
jasmine.addReporter(new SpecReporter({ spec: { displayStacktrace: 'pretty' } }));
jasmine.addReporter(
new SpecReporter({ spec: { displayStacktrace: 'pretty' } })
);
jasmine.execute();

View File

@@ -1,35 +1,35 @@
import * as path from "path";
import { Application } from "spectron";
import * as path from 'path';
import { Application } from 'spectron';
describe("A simple test to verify a visible window is opened with a title", () => {
// Init local app
let app = new Application({
path: path.join(__dirname, "../../../node_modules/.bin/electron"),
args: [path.join(__dirname, "../../../.webpack/main/index.js")],
});
describe('A simple test to verify a visible window is opened with a title', () => {
// Init local app
const app = new Application({
path: path.join(__dirname, '../../../node_modules/.bin/electron'),
args: [path.join(__dirname, '../../../.webpack/main/index.js')],
});
beforeAll(async () => {
// Init local app and wait until window loaded
await app.start();
await app.client.waitUntilWindowLoaded();
});
beforeAll(async () => {
// Init local app and wait until window loaded
await app.start();
await app.client.waitUntilWindowLoaded();
});
afterAll(async () => {
if (app && app.isRunning()) {
// Wait 1 second and then stop local app
await new Promise((resolve) => setTimeout(resolve, 1000));
await app.stop();
}
});
afterAll(async () => {
if (app && app.isRunning()) {
// Wait 1 second and then stop local app
await new Promise((resolve) => setTimeout(resolve, 1000));
await app.stop();
}
});
it("shows an initial window", async () => {
// Checking there is one visible window
expect(await app.browserWindow.isVisible()).toEqual(true);
// Please note that getWindowCount() will return 2 if `dev tools` are opened.
expect(await app.client.getWindowCount()).toEqual(1);
});
it('shows an initial window', async () => {
// Checking there is one visible window
expect(await app.browserWindow.isVisible()).toEqual(true);
// Please note that getWindowCount() will return 2 if `dev tools` are opened.
expect(await app.client.getWindowCount()).toEqual(1);
});
it("should have expected title", async () => {
expect(await app.client.getTitle()).toEqual("ElectronAngularQuickStart");
});
it('should have expected title', async () => {
expect(await app.client.getTitle()).toEqual('ElectronAngularQuickStart');
});
});

View File

@@ -1,10 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/e2e",
"module": "commonjs",
"target": "es5",
"noEmit": true,
"types": ["jasmine", "jasminewd2", "node"]
}
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./.dist",
"module": "commonjs",
"target": "es5",
"noEmit": true,
"types": ["jasmine", "jasminewd2", "node"]
}
}

View File

@@ -1,2 +1,2 @@
# Generated JS files
dist
/.dist

View File

@@ -1,15 +1,15 @@
export interface WindowApi {
/**
* This method is used by the renderer process to receive data from the main process
* @param channel used by the renderer to receive data and by the main to send them
* @param func the callback function to execute when data are available
*/
receive(channel: any, func: (...data: any) => void): void;
/**
* This method is used by the renderer process to receive data from the main process
* @param channel used by the renderer to receive data and by the main to send them
* @param func the callback function to execute when data are available
*/
receive<Out>(channel: string, func: (output: Out) => void): void;
/**
* This method is used by the renderer process to send data to the main process
* @param channel used by the renderer to send data and by the main to receive them
* @param data the data sent by the renderer process to the main process
*/
send(channel: string, ...data: any): void;
/**
* This method is used by the renderer process to send data to the main process
* @param channel used by the renderer to send data and by the main to receive them
* @param data the data sent by the renderer process to the main process
*/
send<In>(channel: string, input: In): void;
}

View File

@@ -1,2 +1,11 @@
import { WindowApi } from './apis/window-api';
export * from './apis/window-api';
export * from './apis/window-api-consts';
export * from './models/config/app-config';
declare global {
// Global augmentation of the `Window` interface
interface Window {
api: WindowApi;
}
}

View File

@@ -0,0 +1,25 @@
export interface AppConfig {
/** The configuration identifier */
configId: string;
/** The main logger output file path */
mainLogFile: string;
/** The main logger output level */
mainLogLevel: string;
/** Tells if we should try to load app icon */
isIconAvailable: boolean;
/** Tells if `nodeIntegration` webPreference is enabled */
isNodeIntegration: boolean;
/** Tells if `contextIsolation` and `worldSafeExecuteJavaScript` webPreferences are enabled */
isContextIsolation: boolean;
/** Tells if `isEnableRemoteModule` webPreference is enabled */
isEnableRemoteModule: boolean;
/** Tells if we should open dev tools */
isOpenDevTools: boolean;
}

View File

@@ -1,9 +1,8 @@
{
"name": "shared-lib",
"version": "2.0.0",
"main": "dist/index.js",
"scripts": {
},
"author": "Sourcygen",
"license": "MIT"
"name": "shared-lib",
"version": "2.0.0",
"main": ".dist/index.js",
"scripts": {},
"author": "Sourcygen",
"license": "MIT"
}

View File

@@ -1,10 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"sourceMap": true,
"composite": true,
"declaration": true,
"outDir": "./dist"
},
"include": ["./**/*.ts"]
"extends": "../../tsconfig.json",
"compilerOptions": {
"sourceMap": true,
"composite": true,
"declaration": true,
"outDir": "./.dist"
},
"include": ["./**/*.ts"]
}