Compare commits

..

21 Commits

Author SHA1 Message Date
undergroundwires
efd63ff85d Bump dependencies to latest
Purge unused dependencies.

Update dependencies to latest except:

- ts-lint. Keep locked to 9.0.1 because that's the latest version that
  works with Webpack 4 that's still used by
  vue-cli-plugin-electron-builder.
- Keep eslint at version 7 because tests cannot be run/compiled with
  version 7, see eslint/eslint#15678, vuejs/vue-cli#6759.

Newer versions of ESLint modules do not allow linebreak after or before
= operator (operator-linebreak). This commit also changes files to
comply with it.

Closes #116, #119, #122, #130.
2022-03-08 18:03:19 +01:00
undergroundwires
242a497e7d Bump node environment to 16.x
- Bump setup-node action to v2.
- Use composite actions to reuse same setting. This is preferred over
  reusable templates because reusable templates are on job-level but
  setting up node should be a step.
2022-03-07 21:38:30 +01:00
undergroundwires
05a6a84c37 Add donation information 2022-03-05 13:10:27 +01:00
undergroundwires
112e79a64c Fix Microsoft Defender alert for uninstaller #114
Microsoft Defender considers the uninstaller virus. It's a
false-psoitive caused by `electron-builder` used to build NSIS package.

This commit solves the issue by explicitly adding `electron-builder` as
dependency. This way, `vue-cli-plugin-electron-builder` always resolves
to the desired version. Now the version used for `electron-builder` is
more controlled. New uninstaller generated by latest specified patch
does not trigger an alert, which solves the false-positive issue.

See also:
  - electron-userland/electron-builder#4793,
  - electron-userland/electron-builder#4878.
2022-02-27 14:55:11 +01:00
undergroundwires
eeb1d5b0c4 Refactor to use version object #59
Enable writing safer version aware logic.
2022-02-26 17:15:30 +01:00
undergroundwires
d6bc33ec86 Fix Windows 11 being detected as Windows 10
The logic was expecting major version in Windows 11 to be 11. However,
in Windows 11, major version is not changed and it is till 10. This
commit corrects logic to check build number that's guaranteed to be
higher in Windows 11.
2022-02-23 06:52:46 +01:00
undergroundwires
956052c8ff Fix error when reverting Windows Defender setting 2022-02-21 17:20:34 +01:00
undergroundwires
3785e410db Document WpnService breaking on Windows 10 #110 2022-02-20 15:44:08 +01:00
undergroundwires
481a02afd5 Refactor to remove hardcoding of aliases
Unify definition of  aliases in single place.

Make TypeScript configuration file (`tsconfig.json`) source of truth
regarding aliases.

Both webpack (through `vue.config.js`) and ESLint (through
`.eslintrc.js`) now reads the alias configuration from `tsconfig.json`.
2022-02-02 19:28:12 +01:00
undergroundwires
5bbbb9cecc Refactor to remove code coupling with Webpack
Remove using Webpack import syntax such as: `js-yaml-loader!@/..`. It's
a non-standard syntax that couples the code to Webpack.

Configure instead by specifying Webpack loader in Vue configuration
file.

Enable related ESLint rules.

Remove unused dependency `raw-loader` and refactor
`NoUnintendedInlining` test to load files using file system (dropping
webpack dependency).

Refactor to use `import type` for type imports to show the indent
clearly and satisfy failing ESLint rules.
2022-01-31 17:22:34 +01:00
undergroundwires
db47440d47 Improve existing documentation
Improve documentation for different markdown documentation files. Goal
is to simplify and make the language and content more clear.
2022-01-30 13:15:34 +01:00
undergroundwires
1bcc6c8b2b Improve documentation for architecture
- Simplify `README.md` by creating and moving some documentation to
`architecture.md`.
- Add more documentation for state handling between layers.
- Improve some documentation to use clearer language.
2022-01-29 15:47:44 +01:00
undergroundwires
3c3ec80525 Improve documentation for developing
Move existing documentation to `docs/development.md` to have simpler
`README.md` but more dedicated and extensive documentation for
development.

Improve existing documentation for different commands for the project.

Document VSCode recommendations in `extensions.json` file and add
exception in `.gitignore` to be able to add it to repository.
2022-01-26 08:14:25 +01:00
undergroundwires
803ef2bb3e Move stubs from ./stubs to ./shared/Stubs
Gathers all shared test code in single place.
2022-01-25 08:37:03 +01:00
undergroundwires
43ce834750 Fix Windows DoSvc not being disabled #115
- Disable DoSvc using registry to support newer Windows versions.
- Add more documentation for DoSvc.
2022-01-22 23:57:57 +01:00
undergroundwires
44d79e2c9a Add more and unify tests for absent object cases
- Unify test data for nonexistence of an object/string and collection.
- Introduce more test through adding missing test data to existing tests.
- Improve logic for checking absence of values to match tests.
- Add missing tests for absent value validation.
- Update documentation to include shared test functionality.
2022-01-21 22:34:11 +01:00
undergroundwires
0e52a99efa Transpile dependencies for wider browser support
This commit ensures that all dependencies in `node_modules` will be
transpiled by Babel.

Dependencies are not transpiled by babel as default. `babel-loader`
ignores all files inside `node_modules`.

Not using it may allow packages using newer JavaScript (such as ES6) to
cause unintended crashed on older browsers.

This configuration is the default in projects created by newer versions
of Vue CLI.
2022-01-20 20:07:49 +01:00
undergroundwires
834ce8cf9e Add AirBnb TypeScript overrides for linting
AirBnb only imports JavaScript rules and some fail for TypeScript files.
This commit overrides those rules with TypeScript equivalents.

Changes here can be mostly replaced when Vue natively support TypeScript
for Airbnb (vuejs/eslint-config-airbnb#23).

Enables @typescript-eslint/indent even though it's broken and it will
not be fixed typescript-eslint/typescript-eslint#1824 until prettifier
is used, because it is still useful.

Change broken rules with TypeScript variants:
  - `no-useless-constructor`
      eslint/eslint#14118
      typescript-eslint/typescript-eslint#873
  - `no-shadow`
      eslint/eslint#13044
      typescript-eslint/typescript-eslint#2483
      typescript-eslint/typescript-eslint#325
      typescript-eslint/typescript-eslint#2552
      typescript-eslint/typescript-eslint#2484
      typescript-eslint/typescript-eslint#2466
2022-01-19 22:28:33 +01:00
undergroundwires
2354f0ba9f Fix reverting of Windows NVIDIA telemetry service
- Fix revert logic deleting the service instead of enabling it.
- Use unified "DisableService" function to improve enable/disable logic.
- Separate disabling of service from opting out.
- Add documentation reference.
2022-01-18 21:23:30 +01:00
undergroundwires
8e96c19126 Improve performance of selecting scripts
Increase performance by only notifying GUI about changes in selection
when there really is a change. It removes extra processing from all
event listeners that act on selection state change.
2022-01-07 22:06:05 +01:00
undergroundwires-bot
99fb4c73f5 ⬆️ bump everywhere to 0.11.3 2022-01-06 20:53:52 +00:00
203 changed files with 4880 additions and 3698 deletions

View File

@@ -1,4 +1,10 @@
const { rules: baseBestPracticesRules } = require('eslint-config-airbnb-base/rules/best-practices');
const { rules: baseErrorsRules } = require('eslint-config-airbnb-base/rules/errors');
const { rules: baseES6Rules } = require('eslint-config-airbnb-base/rules/es6');
const { rules: baseImportsRules } = require('eslint-config-airbnb-base/rules/imports');
const { rules: baseStyleRules } = require('eslint-config-airbnb-base/rules/style');
const { rules: baseVariablesRules } = require('eslint-config-airbnb-base/rules/variables');
const tsconfigJson = require('./tsconfig.json');
module.exports = {
root: true,
@@ -39,6 +45,18 @@ module.exports = {
mocha: true,
},
},
{
files: ['**/*.ts?(x)', '**/*.d.ts'],
parserOptions: {
// Setting project is required for some rules such as @typescript-eslint/dot-notation,
// @typescript-eslint/return-await and @typescript-eslint/no-throw-literal.
// If this property is missing they fail due to missing parser.
project: ['./tsconfig.json'],
},
rules: {
...getTypeScriptOverrides(),
},
},
{
files: ['**/tests/**/*.{j,t}s?(x)'],
rules: {
@@ -59,9 +77,8 @@ function getOwnRules() {
groups: [ // Enforce more strict order than AirBnb
'builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object', 'type'],
pathGroups: [ // Fix manually configured paths being incorrectly grouped as "external"
'@/**', // @/..
'@tests/**', // @tests/.. (not matching anything after @** because there can be third parties as well)
'js-yaml-loader!@/**', // E.g. js-yaml-loader!@/..
...getAliasesFromTsConfig(),
'js-yaml-loader!@/**',
].map((pattern) => ({ pattern, group: 'internal' })),
},
],
@@ -71,10 +88,6 @@ function getOwnRules() {
function getTodoRules() { // Should be worked on separate future commits
return {
'import/no-extraneous-dependencies': 'off',
// Requires webpack configuration change with import '..yaml' files.
'import/no-webpack-loader-syntax': 'off',
'import/extensions': 'off',
'import/no-unresolved': 'off',
// Accessibility improvements:
'vuejs-accessibility/form-control-has-label': 'off',
'vuejs-accessibility/click-events-have-key-events': 'off',
@@ -113,3 +126,166 @@ function getOpinionatedRuleOverrides() {
],
};
}
function getTypeScriptOverrides() {
/*
Here until Vue supports AirBnb Typescript overrides (vuejs/eslint-config-airbnb#23).
Based on `eslint-config-airbnb-typescript`.
Source: https://github.com/iamturns/eslint-config-airbnb-typescript/blob/v16.1.0/lib/shared.js
It cannot be used directly due to compilation errors.
*/
return {
'brace-style': 'off',
'@typescript-eslint/brace-style': baseStyleRules['brace-style'],
camelcase: 'off',
'@typescript-eslint/naming-convention': [
'error',
{ selector: 'variable', format: ['camelCase', 'PascalCase', 'UPPER_CASE'] },
{ selector: 'function', format: ['camelCase', 'PascalCase'] },
{ selector: 'typeLike', format: ['PascalCase'] },
],
'comma-dangle': 'off',
'@typescript-eslint/comma-dangle': [
baseStyleRules['comma-dangle'][0],
{
...baseStyleRules['comma-dangle'][1],
enums: baseStyleRules['comma-dangle'][1].arrays,
generics: baseStyleRules['comma-dangle'][1].arrays,
tuples: baseStyleRules['comma-dangle'][1].arrays,
},
],
'comma-spacing': 'off',
'@typescript-eslint/comma-spacing': baseStyleRules['comma-spacing'],
'default-param-last': 'off',
'@typescript-eslint/default-param-last': baseBestPracticesRules['default-param-last'],
'dot-notation': 'off',
'@typescript-eslint/dot-notation': baseBestPracticesRules['dot-notation'],
'func-call-spacing': 'off',
'@typescript-eslint/func-call-spacing': baseStyleRules['func-call-spacing'],
// ❌ Broken for some cases, but still useful.
// Here until Prettifier is used.
indent: 'off',
'@typescript-eslint/indent': baseStyleRules.indent,
'keyword-spacing': 'off',
'@typescript-eslint/keyword-spacing': baseStyleRules['keyword-spacing'],
'lines-between-class-members': 'off',
'@typescript-eslint/lines-between-class-members': baseStyleRules['lines-between-class-members'],
'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor': baseStyleRules['no-array-constructor'],
'no-dupe-class-members': 'off',
'@typescript-eslint/no-dupe-class-members': baseES6Rules['no-dupe-class-members'],
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': baseBestPracticesRules['no-empty-function'],
'no-extra-parens': 'off',
'@typescript-eslint/no-extra-parens': baseErrorsRules['no-extra-parens'],
'no-extra-semi': 'off',
'@typescript-eslint/no-extra-semi': baseErrorsRules['no-extra-semi'],
// ❌ Fails due to missing parser
// 'no-implied-eval': 'off',
// 'no-new-func': 'off',
// '@typescript-eslint/no-implied-eval': baseBestPracticesRules['no-implied-eval'],
'no-loss-of-precision': 'off',
'@typescript-eslint/no-loss-of-precision': baseErrorsRules['no-loss-of-precision'],
'no-loop-func': 'off',
'@typescript-eslint/no-loop-func': baseBestPracticesRules['no-loop-func'],
'no-magic-numbers': 'off',
'@typescript-eslint/no-magic-numbers': baseBestPracticesRules['no-magic-numbers'],
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': baseBestPracticesRules['no-redeclare'],
// ESLint variant does not work with TypeScript enums.
'no-shadow': 'off',
'@typescript-eslint/no-shadow': baseVariablesRules['no-shadow'],
'no-throw-literal': 'off',
'@typescript-eslint/no-throw-literal': baseBestPracticesRules['no-throw-literal'],
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': baseBestPracticesRules['no-unused-expressions'],
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': baseVariablesRules['no-unused-vars'],
// https://erkinekici.com/articles/linting-trap#no-use-before-define
// 'no-use-before-define': 'off',
// '@typescript-eslint/no-use-before-define': baseVariablesRules['no-use-before-define'],
// ESLint variant does not understand TypeScript constructors.
// eslint/eslint/#14118, typescript-eslint/typescript-eslint#873
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': baseES6Rules['no-useless-constructor'],
quotes: 'off',
'@typescript-eslint/quotes': baseStyleRules.quotes,
semi: 'off',
'@typescript-eslint/semi': baseStyleRules.semi,
'space-before-function-paren': 'off',
'@typescript-eslint/space-before-function-paren': baseStyleRules['space-before-function-paren'],
'require-await': 'off',
'@typescript-eslint/require-await': baseBestPracticesRules['require-await'],
'no-return-await': 'off',
'@typescript-eslint/return-await': baseBestPracticesRules['no-return-await'],
'space-infix-ops': 'off',
'@typescript-eslint/space-infix-ops': baseStyleRules['space-infix-ops'],
'object-curly-spacing': 'off',
'@typescript-eslint/object-curly-spacing': baseStyleRules['object-curly-spacing'],
'import/extensions': [
baseImportsRules['import/extensions'][0],
baseImportsRules['import/extensions'][1],
{
...baseImportsRules['import/extensions'][2],
ts: 'never',
tsx: 'never',
},
],
// Changes required is not yet implemented:
// 'import/no-extraneous-dependencies': [
// baseImportsRules['import/no-extraneous-dependencies'][0],
// {
// ...baseImportsRules['import/no-extraneous-dependencies'][1],
// devDependencies: baseImportsRules[
// 'import/no-extraneous-dependencies'
// ][1].devDependencies.reduce((result, devDep) => {
// const toAppend = [devDep];
// const devDepWithTs = devDep.replace(/\bjs(x?)\b/g, 'ts$1');
// if (devDepWithTs !== devDep) {
// toAppend.push(devDepWithTs);
// }
// return [...result, ...toAppend];
// }, []),
// },
// ],
};
}
function getAliasesFromTsConfig() {
return Object.keys(tsconfigJson.compilerOptions.paths)
.map((path) => `${path}*`);
}

1
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1 @@
github: undergroundwires

8
.github/actions/setup-node/action.yml vendored Normal file
View File

@@ -0,0 +1,8 @@
runs:
using: composite
steps:
-
name: Setup node
uses: actions/setup-node@v2
with:
node-version: 16.x

View File

@@ -18,9 +18,7 @@ jobs:
uses: actions/checkout@v2
-
name: Setup node
uses: actions/setup-node@v1
with:
node-version: 15.x
uses: ./.github/actions/setup-node
-
name: Install dependencies
run: npm ci
@@ -42,9 +40,7 @@ jobs:
uses: actions/checkout@v2
-
name: Setup node
uses: actions/setup-node@v1
with:
node-version: 15.x
uses: ./.github/actions/setup-node
-
name: Install dependencies
run: npm ci

View File

@@ -19,9 +19,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: 15.x
uses: ./.github/actions/setup-node
- name: Install dependencies
run: npm ci
- name: Lint

View File

@@ -16,9 +16,7 @@ jobs:
uses: actions/checkout@v2
-
name: Setup node
uses: actions/setup-node@v1
with:
node-version: 15.x
uses: ./.github/actions/setup-node
-
name: NPM audit
run: exit "$(npm audit)" # Since node 15.x, it does not fail with error if we don't explicitly exit

View File

@@ -20,9 +20,7 @@ jobs:
- name: Checkout to bump commit
run: git checkout "$(git rev-list "${{ github.event.release.tag_name }}"..master | tail -1)"
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: 15.x
uses: ./.github/actions/setup-node
- name: Install dependencies
run: npm ci
- name: Run unit tests
@@ -31,4 +29,4 @@ jobs:
run: npm run electron:build -- -p always # https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/recipes.html#upload-release-to-github
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
EP_GH_IGNORE_TIME: true # Otherwise publishing fails if GitHub release is more than 2 hours old https://github.com/electron-userland/electron-builder/issues/2074
EP_GH_IGNORE_TIME: true # Otherwise publishing fails if GitHub release is more than 2 hours old https://github.com/electron-userland/electron-builder/issues/2074

View File

@@ -1,8 +1,8 @@
name: release-site
on:
release:
types: [created] # will be triggered when a NON-draft release is created and published.
release:
types: [created] # will be triggered when a NON-draft release is created and published.
jobs:
aws-deploy: # see: https://github.com/undergroundwires/aws-static-site-with-cd
@@ -77,30 +77,28 @@ jobs:
name: "App: Checkout"
uses: actions/checkout@v2
with:
path: site
path: app
ref: master # otherwise we don't get version bump commit
-
name: "App: Setup node"
uses: actions/setup-node@v1
with:
node-version: 15.x
uses: ./app/.github/actions/setup-node
-
name: "App: Install dependencies"
run: npm ci
working-directory: site
working-directory: app
-
name: "App: Run unit tests"
run: npm run test:unit
working-directory: site
working-directory: app
-
name: "App: Build"
run: npm run build
working-directory: site
working-directory: app
-
name: "App: Deploy to S3"
run: >-
bash "aws/scripts/deploy/deploy-to-s3.sh" \
--folder site/dist \
--folder app/dist \
--web-stack-name privacysexy-web-stack --web-stack-s3-name-output-name S3BucketName \
--storage-class ONEZONE_IA \
--role-arn ${{secrets.AWS_S3_SITE_DEPLOYMENT_ROLE_ARN}} \

View File

@@ -17,9 +17,7 @@ jobs:
uses: actions/checkout@v2
-
name: Setup node
uses: actions/setup-node@v1
with:
node-version: 15.x
uses: ./.github/actions/setup-node
-
name: Install dependencies
run: npm ci

View File

@@ -19,9 +19,7 @@ jobs:
uses: actions/checkout@v2
-
name: Setup node
uses: actions/setup-node@v1
with:
node-version: 15.x
uses: ./.github/actions/setup-node
-
name: Install dependencies
run: npm ci

View File

@@ -16,10 +16,8 @@ jobs:
name: Checkout
uses: actions/checkout@v2
-
name: Setup node
uses: actions/setup-node@v1
with:
node-version: 15.x
name: Set-up node
uses: ./.github/actions/setup-node
-
name: Install dependencies
run: npm ci

3
.gitignore vendored
View File

@@ -1,7 +1,8 @@
node_modules
dist/
.vs
.vscode
.vscode/**/*
!.vscode/extensions.json
#Electron-builder output
/dist_electron
# Cypress

23
.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,23 @@
{
"recommendations": [
// Common
"editorconfig.editorconfig", // Applies .editorconfig to follow project style.
"wengerk.highlight-bad-chars", // Highlights bad chars.
"wayou.vscode-todo-highlight", // Highlights TODO.
"wix.vscode-import-cost", // Shows in KB how much a require include in code.
// Documentation
"davidanson.vscode-markdownlint", // Lints markdown.
// TypeScript / JavaScript
"dbaeumer.vscode-eslint", // Lints JavaScript/TypeScript.
"pmneo.tsimporter", // Provides better auto-complete for TypeScripts imports.
// Vue
"jcbuisson.vue", // Highlights syntax.
"octref.vetur", // Adds Vetur, Vue tooling support.
// Scripting
"timonwong.shellcheck", // Lints bash files.
"ms-vscode.powershell", // Lints PowerShell files.
"ms-python.python", // Lints Python files.
// Distribution
"ms-azuretools.vscode-docker" // Adds Docker support.
]
}

View File

@@ -1,5 +1,27 @@
# Changelog
## 0.11.3 (2022-01-05)
* Fix double backlashes in Windows vscode scripts | [5f091bb](https://github.com/undergroundwires/privacy.sexy/commit/5f091bb6abed878271e2321cd784f34436c677bd)
* Fix OS desktop detection tests and edge cases | [a8358b8](https://github.com/undergroundwires/privacy.sexy/commit/a8358b8e7a93214f3d22a4488007ded5f623d845)
* Fix clearing Windows product key showing dialog | [9b6636e](https://github.com/undergroundwires/privacy.sexy/commit/9b6636e21a922a4750dc19f4854f8ae679187926)
* Document and unrecommend Cloud Experience Host | [9b5e0b0](https://github.com/undergroundwires/privacy.sexy/commit/9b5e0b0591fee56af52d83334a1f19180a49516f)
* Add initial e2e testing with cypress | [ddd2e70](https://github.com/undergroundwires/privacy.sexy/commit/ddd2e704dbd361cbd219f3dfe644b983ad254095)
* Restructure pipelines and badges | [5a2c263](https://github.com/undergroundwires/privacy.sexy/commit/5a2c263af35b8785e75ead6c43c3f17186dc15c8)
* Fix failing of functions without revert code | [87de017](https://github.com/undergroundwires/privacy.sexy/commit/87de017afd6e08acbd2deea150c6af9c7ee778fc)
* Fix typos in privacy modal #109 | [a1871a2](https://github.com/undergroundwires/privacy.sexy/commit/a1871a2982c9e3192193f836b97b1a6ccda5a2ab)
* Refactor to add readonly interfaces | [c3c5b89](https://github.com/undergroundwires/privacy.sexy/commit/c3c5b897f308f613c252182a02cdd4cfa7150fa3)
* Document and unrecommend AAD app removal #24, #54 | [455084c](https://github.com/undergroundwires/privacy.sexy/commit/455084c17b32d11d046515e8dc1447adf4bea4c3)
* Migrate from TSLint to ESLint | [61b475f](https://github.com/undergroundwires/privacy.sexy/commit/61b475fa8de433cdada2efa7eac197683aacd956)
* Add build checks and improve existing CI/CD checks | [17298f0](https://github.com/undergroundwires/privacy.sexy/commit/17298f0b2c51cb9becc0eb2ffe0d93d6a4c503a6)
* Upgrade to Vue CLI 5 (and webpack 5) | [96265b7](https://github.com/undergroundwires/privacy.sexy/commit/96265b75deafb85978b16460138fb4a814c07cfe)
* Refactor code to comply with ESLint rules | [5b1fbe1](https://github.com/undergroundwires/privacy.sexy/commit/5b1fbe1e2fb1354a5f060f8c8e3794ce756e16a7)
* Fix mutated line endings on Windows | [bd23faa](https://github.com/undergroundwires/privacy.sexy/commit/bd23faa28f6d781581a33d5b780f4b33f7e2cd8b)
* Refactor to improve iterations | [31f7091](https://github.com/undergroundwires/privacy.sexy/commit/31f70913a2f30baf5a9d6690f192e6a63da50114)
* win: unrecommend and document Live ID service #100 | [d11a674](https://github.com/undergroundwires/privacy.sexy/commit/d11a674a3c4ad8f4972a870c2f0977ac53297273)
[compare](https://github.com/undergroundwires/privacy.sexy/compare/0.11.2...0.11.3)
## 0.11.2 (2021-12-03)
* Fix Windows TrustedInstaller session errors | [20a0071](https://github.com/undergroundwires/privacy.sexy/commit/20a0071c0d3d769a8f31218abdbfc4cafa25c6ff)

View File

@@ -1,34 +1,51 @@
# Contributing
- Love your input! Contributing to this project should be as easy and transparent as possible, whether it's:
- Reporting a bug
- Discussing the current state of the code
- Submitting a fix
- Proposing new features
- Becoming a maintainer
Love your input! Contributing to this project should be as easy and transparent as possible, whether it's:
- reporting a bug,
- discussing the current state of the code,
- submitting a fix,
- proposing new features,
- or becoming a maintainer.
As a small open source project with small community, it can sometimes take a long time to address the issues so please be patient.
## Pull request process
- [GitHub flow](https://guides.github.com/introduction/flow/index.html) with [GitOps](./img/architecture/gitops.png) is used
- Your pull requests are actively welcomed.
- The steps:
1. Fork the repo and create your branch from master.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints.
6. Issue that pull request!
- 🙏 DO
- Document your changes in the pull request
- ❗ DON'T
- Do not update the versions, current version is only [set by the maintainer](./img/architecture/gitops.png) and updated automatically by [bump-everywhere](https://github.com/undergroundwires/bump-everywhere)
Your pull requests are actively welcomed. We collaborate using [GitHub flow](https://docs.github.com/en/get-started/quickstart/github-flow).
The steps:
1. Fork the repo and create your branch from master.
2. If you've added code that requires testing, add tests. See [tests.md](./docs/tests.md).
3. If you've done a major change, update the documentation. See [docs/](./docs/).
4. Ensure the test suite passes. See [development.md | Testing](./docs/development.md#testing) for commands.
5. Make sure your code lints.See [development.md | Linting](./docs/development.md#linting) for commands.
6. Issue that pull request!
**🙏 DO:**
- Document why (what you're trying to solve) rather than what in the pull request.
**❗ DON'T:**
- Do not update the versions, current version is [set by the maintainer](./docs/ci-cd.md#gitops) and updated automatically by [bump-everywhere](https://github.com/undergroundwires/bump-everywhere).
Automated pipelines will run to control your PR and they will publish your code once the maintainer merges your PR.
📖 You can read more in [ci-cd.md](./docs/ci-cd.md).
## Extend scripts
Here's quick information for you who want to add more scripts.
You have two alternatives:
1. [Create an issue](https://github.com/undergroundwires/privacy.sexy/issues/new/choose) and ask for someone else to add the script for you.
2. Or send a PR yourself. This would make it faster to get your code into the project. You need to add scripts to related OS in [collections](src/application/collections/) folder. Then you'd sent a pull request, see [pull request process](#pull-request-process).
- 📖 If you're unsure about the syntax, check [collection-files.md](docs/collection-files.md).
- 📖 If you wish to use templates, use [templating.md](./docs/templating.md).
## License
By contributing, you agree that your contributions will be licensed under its [GNU General Public License v3.0](./LICENSE).
## Read more
- See [tests](./docs/tests.md) for testing
- See [extend script](./README.md#extend-scripts) for quick steps to extend scripts
- See [architecture overview](./README.md#architecture-overview) to deep dive into privacy.sexy codebase
By contributing, you agree that your [GNU General Public License v3.0](./LICENSE) will be the license for your contributions.

View File

@@ -4,6 +4,12 @@
<!-- markdownlint-disable MD033 -->
<p align="center">
<a href="https://undergroundwires.dev/donate?project=privacy.sexy">
<img
alt="donation badge"
src="https://undergroundwires.dev/img/badges/donate/flat.svg"
/>
</a>
<a href="https://github.com/undergroundwires/privacy.sexy/blob/master/CONTRIBUTING.md">
<img
alt="contributions are welcome"
@@ -97,79 +103,39 @@
## Get started
- Online version at [https://privacy.sexy](https://privacy.sexy)
- 💡 No need to run any compiled software on your computer.
- Alternatively download offline version for [Windows](https://github.com/undergroundwires/privacy.sexy/releases/download/0.11.2/privacy.sexy-Setup-0.11.2.exe), [macOS](https://github.com/undergroundwires/privacy.sexy/releases/download/0.11.2/privacy.sexy-0.11.2.dmg) or [Linux](https://github.com/undergroundwires/privacy.sexy/releases/download/0.11.2/privacy.sexy-0.11.2.AppImage).
- 💡 Single click to execute your script.
- ❗ Come back regularly to apply latest version for stronger privacy and security.
- 🌍️ **Online**: [https://privacy.sexy](https://privacy.sexy).
- 🖥️ **Offline**: Check [releases page](https://github.com/undergroundwires/privacy.sexy/releases), or download directly for: [Windows](https://github.com/undergroundwires/privacy.sexy/releases/download/0.11.2/privacy.sexy-Setup-0.11.2.exe), [macOS](https://github.com/undergroundwires/privacy.sexy/releases/download/0.11.2/privacy.sexy-0.11.2.dmg), [Linux](https://github.com/undergroundwires/pr.vacy.sexy/releases/download/0.11.2/privacy.sexy-0.11.2.AppImage).
[![privacy.sexy application](img/screenshot.png?raw=true)](https://privacy.sexy)
Online version does not require to run any software on your computer. Offline version has more functions such as running the scripts directly.
## Why
💡 You should apply your configuration from time to time (more than once). It would strengthen your privacy and security control because privacy.sexy and its scripts get better and stronger in every new version.
- Rich tweak pool to harden security & privacy of the OS and other software on it
- Free (both free as in beer and free as in speech)
- No need to run any compiled software that has access to your system, just run the generated scripts
- Have full visibility into what the tweaks do as you enable them
- Ability to revert (undo) applied scripts
- Everything is transparent: both application and its infrastructure are open-source and automated
- Easily extendable with [own powerful templating language](./docs/templating.md)
- Each script is independently executable without cross-dependencies
[![privacy.sexy application](img/screenshot.png?raw=true )](https://privacy.sexy)
## Extend scripts
## Features
- You can either [create an issue](https://github.com/undergroundwires/privacy.sexy/issues/new/choose)
- Or send a PR:
1. Fork the repository
2. Add more scripts in respective script collection in [collections](src/application/collections/) folder.
- 📖 If you're unsure about the syntax you can refer to the [collection files | documentation](docs/collection-files.md).
- 🙏 For any new script, please add `revertCode` and `docs` values if possible.
3. Send a pull request 👌
- **Rich**: Hundreds of scripts that aims to give you control of your data.
- **Free**: Both free as in "beer" and free as in "speech".
- **Transparent**. Have full visibility into what the tweaks do as you enable them.
- **Reversible**. Revert if something feels wrong.
- **Accessible**. No need to run any compiled software on your computer with web version.
- **Open**. What you see as code in this repository is what you get. The application itself, its infrastructure and deployments are open-source and automated thanks to [bump-everywhere](https://github.com/undergroundwires/bump-everywhere).
- **Tested.** A lot of tests. Automated and manual. Community-testing and verification. Stability improvements comes before new features.
- **Extensible**. Effortlessly [extend scripts](./CONTRIBUTING.md#extend-scripts) with a custom designed [templating language](./docs/templating.md).
- **Portable and simple**. Every script is independently executable without cross-dependencies.
## Commands
## Support
- Project setup: `npm install`
- Testing
- Run unit tests: `npm run test:unit`
- Run integration tests: `npm run test:integration`
- Run e2e (end-to-end) tests
- Interactive mode with GUI: `npm run test:e2e`
- Headless mode without GUI: `npm run test:e2e -- --headless`
- Lint: `npm run lint`
- **Desktop app**
- Development: `npm run electron:serve`
- Production: `npm run electron:build` to build an executable
- **Webpage**
- Development: `npm run serve` to compile & hot-reload for development.
- Production: `npm run build` to prepare files for distribution.
- Or run using Docker:
1. Build: `docker build -t undergroundwires/privacy.sexy:0.11.2 .`
2. Run: `docker run -it -p 8080:80 --rm --name privacy.sexy-0.11.2 undergroundwires/privacy.sexy:0.11.2`
**Sponsor 💕**. Consider sponsoring on [GitHub Sponsors](https://github.com/sponsors/undergroundwires), or you can donate using [other ways such as crypto or a coffee](https://undergroundwires.dev/donate).
## Architecture overview
**Star 🤩**. Feel free to give it a star ⭐ .
### Application
**Contribute 👷**. Contributions of any type are welcome. See [CONTRIBUTING.md](./CONTRIBUTING.md) as the starting point. It includes useful information like [how to add new scripts](./CONTRIBUTING.md#extend-scripts).
- Powered by **TypeScript**, **Vue.js** and **Electron** 💪
- and driven by **Domain-driven design**, **Event-driven architecture**, **Data-driven programming** concepts.
- Application uses highly decoupled models & services in different DDD layers.
- 📖 Read more on • [Presentation](./docs/presentation.md) • [Application](./docs/application.md)
## Development
![DDD + vue.js](img/architecture/app-ddd.png)
Refer to [development.md](./docs/development.md) for Docker usage and reading more about setting up your development environment.
### AWS Infrastructure
Check [architecture.md](./docs/architecture.md) for an overview of design and how different parts and layers work together. You can refer to [application.md](./docs/application.md) for a closer look at application layer codebase and [presentation.md](./docs/presentation.md) for code related to GUI layer. [collection-files.md](./docs/collection-files.md) explains the YAML files that are the core of the application and [templating.md](./docs/templating.md) documents how to use templating language in those files. In [ci-cd.md](./docs/ci-cd.md), you can read more about the pipelines that automates maintenance tasks and ensures you get what see.
[![AWS solution](img/architecture/aws-solution.png)](https://github.com/undergroundwires/aws-static-site-with-cd)
- It uses infrastructure from the following repository: [aws-static-site-with-cd](https://github.com/undergroundwires/aws-static-site-with-cd)
- Runs on AWS 100% serverless and automatically provisioned using [GitHub Actions](.github/workflows/).
- Maximum security & automation and minimum AWS costs are the highest priorities of the design.
#### GitOps: CI/CD to AWS
- CI/CD is fully automated for this repo using different GIT events & GitHub actions.
- Versioning, tagging, creation of `CHANGELOG.md` and releasing is automated using [bump-everywhere](https://github.com/undergroundwires/bump-everywhere) action
- Everything that's merged in the master goes directly to production.
- 📖 Read more on [CI/CD pipelines](./docs/ci-cd.md)
[![CI/CD to AWS with GitHub Actions](img/architecture/gitops.png)](.github/workflows/)
[docs/](./docs/) folder includes all other documentation.

View File

@@ -1,44 +1,45 @@
# Application
- It's mainly responsible for
- creating and event based [application state](#application-state)
- [parsing](#parsing) and [compiling](#compiling) [application data](#application-data)
- Consumed by [presentation layer](./presentation.md)
Application layer is mainly responsible for:
- creating an event-based and mutable [application state](#application-state),
- [parsing and compiling](#parsing-and-compiling) the [application data](#application-data).
📖 Refer to [architecture.md | Layered Application](./architecture.md#layered-application) to read more about the layered architecture.
## Structure
- [`/src/` **`application/`**](./../src/application/): Contains all application related code.
- [**`collections/`**](./../src/application/collections/): Holds [collection files](./collection-files.md)
- [**`Common/`**](./../src/application/Common/): Contains common functionality that is shared in application layer.
- `..`: other classes are categorized using folders-by-feature structure
Application layer code exists in [`/src/application`](./../src/application/) and includes following structure:
- [**`collections/`**](./../src/application/collections/): Holds [collection files](./collection-files.md).
- [**`Common/`**](./../src/application/Common/): Contains common functionality in application layer.
- `...`: rest of the application layer source code organized using folders-by-feature structure.
## Application state
- [ApplicationContext.ts](./../src/application/Context/ApplicationContext.ts) holds the [CategoryCollectionState](./../src/application/Context/State/CategoryCollectionState.ts) for each OS
- Uses [state pattern](https://en.wikipedia.org/wiki/State_pattern)
- Same instance is shared throughout the application to ensure consistent state
- 📖 See [Application State | Presentation layer](./presentation.md#application-state) to read more about how the state should be managed by the presentation layer.
- 📖 See [ApplicationContext.ts](./../src/application/Context/ApplicationContext.ts) to start diving into the state code.
It uses [state pattern](https://en.wikipedia.org/wiki/State_pattern) with context and state objects. [`ApplicationContext.ts`](./../src/application/Context/ApplicationContext.ts) the "Context" of state pattern provides an instance of [`CategoryCollectionState.ts`](./../src/application/Context/State/CategoryCollectionState.ts) (the "State" of the state pattern) for every supported collection.
Presentation layer uses a singleton (same instance of) [`ApplicationContext.ts`](./../src/application/Context/ApplicationContext.ts) throughout the application to ensure consistent state.
📖 Refer to [architecture.md | Application State](./architecture.md#application-state) to get an overview of event handling and [presentation.md | Application State](./presentation.md#application-state) for deeper look into how the presentation layer manages state.
## Application data
- Compiled to [`Application`](./../src/domain/Application.ts) domain object.
- The scripts are defined and controlled in different data files per OS
- Enables [data-driven programming](https://en.wikipedia.org/wiki/Data-driven_programming) and easier contributions
- Application data is defined in collection files and
- 📖 See [Application data | Presentation layer](./presentation.md#application-data) to read how the application data is read by the presentation layer.
- 📖 See [collection files documentation](./collection-files.md) to read more about how the data files are structured/defined and see [collection yaml files](./../src/application/collections/) to directly check the code.
Application data is collection files using YAML. You can refer to [collection-files.md](./collection-files.md) to read more about the scheme and structure of application data files. You can also check the source code [collection yaml files](./../src/application/collections/) to directly see the application data using that scheme.
## Parsing
Application layer [parses and compiles](#parsing-and-compiling) application data into [`Application`](./../src/domain/Application.ts)). Once parsed, application layer provides the necessary functionality to presentation layer based on the application data. You can read more about how presentation layer consumes the application data in [presentation.md | Application Data](./presentation.md#application-data).
- Application data is parsed to domain object [`Application.ts`](./../src/domain/Application.ts)
- Steps
1. (Compile time) Load application data from [collection yaml files](./../src/application/collections/) using webpack loader
2. (Runtime) Parse and compile application and make it available to presentation layer by [`ApplicationFactory.ts`](./../src/application/ApplicationFactory.ts)
Application layer enables [data-driven programming](https://en.wikipedia.org/wiki/Data-driven_programming) by leveraging the data to the rest of the source code. It makes it easy for community to contribute on the project by using a declarative language used in collection files.
### Compiling
### Parsing and compiling
- Parsing the application files includes compiling scripts using [collection file defined functions](./collection-files.md#function)
- To extend the syntax:
1. Add a new parser under [SyntaxParsers](./../src/application/Parser/Script/Compiler/Expressions/SyntaxParsers) where you can look at other parsers to understand more.
2. Register your in [CompositeExpressionParser](./../src/application/Parser/Script/Compiler/Expressions/Parser/CompositeExpressionParser.ts)
Application layer parses the application data to compile the domain object [`Application.ts`](./../src/domain/Application.ts).
A webpack loader loads (or injects) application data ([collection yaml files](./../src/application/collections/)) into the application layer in compile time. Application layer ([`ApplicationFactory.ts`](./../src/application/ApplicationFactory.ts)) parses and compiles this data in runtime.
Application layer compiles templating syntax during parsing to create the end scripts. You can read more about templating syntax in [templating.md](./templating.md) and how application data uses them through functions in [collection-files.md | Function](./collection-files.md#function).
The steps to extend the templating syntax:
1. Add a new parser under [SyntaxParsers](./../src/application/Parser/Script/Compiler/Expressions/SyntaxParsers) where you can look at other parsers to understand more.
2. Register your in [CompositeExpressionParser](./../src/application/Parser/Script/Compiler/Expressions/Parser/CompositeExpressionParser.ts).

66
docs/architecture.md Normal file
View File

@@ -0,0 +1,66 @@
# Architecture overview
This repository consists of:
- A [layered application](#layered-application).
- [AWS infrastructure](#aws-infrastructure) as code and instructions to host the website.
- [GitOps](#gitops) practices for development, maintenance and deployment.
## Layered application
Application is
- powered by **TypeScript**, **Vue.js** and **Electron** 💪,
- and driven by **Domain-driven design**, **Event-driven architecture**, **Data-driven programming** concepts.
Application uses highly decoupled models & services in different DDD layers:
- presentation layer (see [presentation.md](./presentation.md)),
- application layer (see [application.md](./application.md)),
- and domain layer.
Application layer depends on and consumes domain layer. [Presentation layer](./presentation.md) consumes and depends on application layer along with domain layer. Application and presentation layers can communicate through domain model.
![DDD + vue.js](./../img/architecture/app-ddd.png)
### Application state
State handling uses an event-driven subscription model to signal state changes and special functions to register changes. It does not depend on third party packages.
Each layer treat application layer differently.
![State](./../img/architecture/app-state.png)
*[Presentation layer](./presentation.md)*:
- Each component holds their own state about presentation-related data.
- Components register shared state changes into application state using functions.
- Components listen to shared state changes using event subscriptions.
- 📖 Read more: [presentation.md | Application state](./presentation.md#application-state).
*[Application layer](./application.md)*:
- Stores the application-specific state.
- The state it exposed for read with getter functions and set using setter functions, setter functions also fire application events that allows other parts of application and the view in presentation layer to react.
- So state is mutable, and fires related events when mutated.
- 📖 Read more: [application.md | Application state](./application.md#application-state).
It's comparable with flux ([`redux`](https://redux.js.org/)) or flux-like ([`vuex`](https://vuex.vuejs.org/)) patterns. Flux component "view" is [presentation layer](./presentation.md) in Vue. Flux functions "dispatcher", "store" and "action creation" functions lie in the [application layer](./application.md). A difference is that application state in privacy.sexy is mutable and lies in single flux "store" that holds app state and logic. The "actions" mutate the state directly which in turns act as dispatcher to notify its own event subscriptions (callbacks).
## AWS infrastructure
The web-site runs on serverless AWS infrastructure. Infrastructure is open-source and deployed as code. [aws-static-site-with-cd](https://github.com/undergroundwires/aws-static-site-with-cd) project includes the source code.
[![AWS solution](../img/architecture/aws-solution.png)](https://github.com/undergroundwires/aws-static-site-with-cd)
The design priorities highest security then minimizing cloud infrastructure costs.
This project includes [GitHub Actions](../.github/workflows/) to automatically provision the infrastructure with zero-touch and without any "hidden" steps, ensuring everything is open-source and transparent. Git repositories includes all necessary instructions and automation with [GitOps](#gitops) practices.
## GitOps
CI/CD pipelines automate operational tasks based on different Git events. [bump-everywhere](https://github.com/undergroundwires/bump-everywhere) enables this automation.
📖 Read more in [`ci-cd.md`](./ci-cd.md#gitops).
[![CI/CD using GitHub Actions](../img/architecture/gitops.png)](../.github/workflows/)

View File

@@ -1,10 +1,26 @@
# Pipelines
# CI/CD overview
Pipelines are found under [`.github/workflows`](./../.github/workflows).
## GitOps
CI/CD is fully automated using different Git events and GitHub actions. This repository uses [bump-everywhere](https://github.com/undergroundwires/bump-everywhere) to automate versioning, tagging, creation of `CHANGELOG.md` and GitHub releases. A dedicated workflow [release.desktop.yaml](./../.github/workflows/release.desktop.yaml) creates desktop installers and executables and attaches them into GitHub releases.
Everything that's merged in the master goes directly to production.
[![CI/CD using GitHub Actions](./../img/architecture/gitops.png)](../.github/workflows/)
## Pipeline files
privacy.sexy uses [GitHub actions](https://github.com/features/actions) to define and run pipelines as code.
GitHub workflows i.e. pipelines exist in [`/.github/workflows/`](./../.github/workflows/) folder without any subfolders due to GitHub actions requirements [1] .
Local GitHub actions are defined in [`/.github/actions/`](./../.github/actions/) and used to reuse same workflow steps.
## Pipeline types
They are categorized based on their type:
We categorize pipelines into different categories. We use these names in convention when naming files and actions, see [naming conventions](#naming-conventions).
The categories consist of:
- `tests`: Different types of tests to verify functionality.
- `checks`: Other controls such as vulnerability scans or styling checks.
@@ -12,8 +28,18 @@ They are categorized based on their type:
## Naming conventions
Pipeline files are named using: **`<type>.<name>.yaml`**.
Convention for naming pipeline files: **`<type>.<name>.yaml`**.
**`type`**: Sub-folders do not work for GitHub workflows so that's why `<type>.` prefix is used. See also [pipeline types](#pipeline-types).
**`type`**:
**`name`**: Pipeline themselves are named using kebab case. It allows for easier URL references for their status badges. E.g. file name `tests.unit.yaml`, pipeline name: `name: unit-tests`
- Sub-folders do not work for GitHub workflows [1] so we use `<type>.` prefix to organize them.
- See also [pipeline types](#pipeline-types) for list of all usable types.
**`name`**:
- We name workflows using kebab-case.
- E.g. file name `tests.unit.yaml`, pipeline file should set the naem as: `name: unit-tests`.
- Kebab-case allows to have better URL references to them.
- [README.md](./../README.md) uses URL references to show status badges for actions.
[1]: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#about-yaml-syntax-for-workflows

53
docs/development.md Normal file
View File

@@ -0,0 +1,53 @@
# Development
Before your commit, a good practice is to:
1. [Run unit tests](#testing)
2. [Lint your code](#linting)
You could run other types of tests as well, but they may take longer time and overkill for your changes. Automated actions executes the tests for a pull request or change in the main branch. See [ci-cd.md](./ci-cd.md) for more information.
## Commands
### Prerequisites
- Install node >15.x.
- Install dependencies using `npm install`.
### Testing
- Run unit tests: `npm run test:unit`
- Run integration tests: `npm run test:integration`
- Run e2e (end-to-end) tests
- Interactive mode with GUI: `npm run test:e2e`
- Headless mode without GUI: `npm run test:e2e -- --headless`
📖 Read more about testing in [tests](./tests.md).
### Linting
- Lint all (recommended 💡): `npm run lint`
- Markdown: `npm run lint:md`
- Markdown consistency `npm run lint:md:consistency`
- Markdown relative URLs: `npm run lint:md:relative-urls`
- JavaScript/TypeScript: `npm run lint:eslint`
- Yaml: `npm run lint:yaml`
### Running
- Run in local server: `npm run serve`
- 💡 Meant for local development with features such as hot-reloading.
- Run using Docker:
1. Build: `docker build -t undergroundwires/privacy.sexy:latest .`
2. Run: `docker run -it -p 8080:80 --rm --name privacy.sexy undergroundwires/privacy.sexy:latest`
### Building
- Build web application: `npm run build`
- Build desktop application: `npm run electron:build`
## Recommended extensions
You should use EditorConfig to follow project style.
For Visual Studio Code, [`.vscode/extensions.json`](./../.vscode/extensions.json) includes list of recommended extensions.

View File

@@ -1,53 +1,63 @@
# Presentation layer
- Consists of Vue.js components and other UI-related code.
- Desktop application is created using [Electron](https://www.electronjs.org/).
- Event driven as in components simply listens to events from the state and act accordingly.
Presentation layer consists of UI-related code. It uses Vue.js as JavaScript framework and includes Vue.js components. It also includes [Electron](https://www.electronjs.org/) to provide functionality to desktop application.
It's designed event-driven from bottom to top. It listens user events (from top) and state events (from bottom) to update state or the GUI.
📖 Refer to [architecture.md (Layered Application)](./architecture.md#layered-application) to read more about the layered architecture.
## Structure
- [`/src/` **`presentation/`**](./../src/presentation/): Contains all presentation related code including Vue and Electron configurations
- [**`bootstrapping/`**](./../src/presentation/bootstrapping/): Registers Vue global objects including components and plugins.
- [**`components/`**](./../src/presentation/components/): Contains all Vue components and their helper classes.
- [**`Shared/`**](./../src/presentation/components/Shared): Contains Vue components and component helpers that are shared across other components.
- [**`assets/`**](./../src/presentation/assets/styles/): Contains assets that will be processed by webpack.
- [**`Shared/`**](./../src/presentation/components/Shared): Contains Vue components and component helpers that other components share.
- [**`assets/`**](./../src/presentation/assets/styles/): Contains assets that webpack will process.
- [**`fonts/`**](./../src/presentation/assets/fonts/): Contains fonts
- [**`styles/`**](./../src/presentation/assets/styles/): Contains shared styles used throughout different components.
- [**`components/`**](./../src/presentation/assets/styles/components): Contains styles that are reusable and tightly coupled a Vue/HTML component.
- [**`components/`**](./../src/presentation/assets/styles/components): Contains reusable styles coupled to a Vue/HTML component.
- [**`vendors-extensions/`**](./../src/presentation/assets/styles/third-party-extensions): Contains styles that override third-party components used.
- [**`main.scss`**](./../src/presentation/assets/styles/main.scss): Primary Sass file, passes along all other styles, should be the only file used from other components.
- [**`main.scss`**](./../src/presentation/assets/styles/main.scss): Primary Sass file, passes along all other styles, should be the single file used from other components.
- [**`main.ts`**](./../src/presentation/main.ts): Application entry point that mounts and starts Vue application.
- [**`electron/`**](./../src/presentation/electron/): Electron configuration for the desktop application.
- [**`main.ts`**](./../src/presentation/main.ts): Main process of Electron, started as first thing when app starts.
- [**`/public/`**](./../public/): Contains static assets that will directly be copied and not go through webpack.
- [**`/vue.config.js`**](./../vue.config.js): Global Vue CLI configurations loaded by `@vue/cli-service`
- [**`/postcss.config.js`**](./../postcss.config.js): PostCSS configurations that are used by Vue CLI internally
- [**`/babel.config.js`**](./../babel.config.js): Babel configurations for polyfills used by `@vue/cli-plugin-babel`
- [**`/public/`**](./../public/): Contains static assets that are directly copied and do not go through webpack.
- [**`/vue.config.js`**](./../vue.config.js): Global Vue CLI configurations loaded by `@vue/cli-service`.
- [**`/postcss.config.js`**](./../postcss.config.js): PostCSS configurations used by Vue CLI internally.
- [**`/babel.config.js`**](./../babel.config.js): Babel configurations for polyfills used by `@vue/cli-plugin-babel`.
## Application data
- Components and should use [ApplicationFactory](./../src/application/ApplicationFactory.ts) singleton to reach the application domain.
- [Application.ts](../src/domain/Application.ts) domain model is the stateless application representation including
- available scripts, collections as defined in [collection files](./collection-files.md)
- package information as defined in [`package.json`](./../package.json)
- 📖 See [Application data | Application layer](./presentation.md#application-data) where application data is parsed and compiled.
Components (should) use [ApplicationFactory](./../src/application/ApplicationFactory.ts) singleton to reach the application domain to avoid [parsing and compiling](./application.md#parsing-and-compiling) the application again.
[Application.ts](../src/domain/Application.ts) is an immutable domain model that represents application state. It includes:
- available scripts, collections as defined in [collection files](./collection-files.md),
- package information as defined in [`package.json`](./../package.json).
You can read more about how application layer provides application data to he presentation in [application.md | Application data](./application.md#application-data).
## Application state
- Stateful components mutate or/and react to state changes in [ApplicationContext](./../src/application/Context/ApplicationContext.ts).
- Stateless components that does not handle state extends `Vue`
- Stateful components that depends on the collection state such as user selection, search queries and more extends [`StatefulVue`](./../src/presentation/components/Shared/StatefulVue.ts)
- The single source of truth is a singleton of the state created and made available to presentation layer by [`StatefulVue`](./../src/presentation/components/Shared/StatefulVue.ts)
- `StatefulVue` includes abstract `handleCollectionState` that is fired once the component is loaded and also each time [collection](./collection-files.md) is changed.
- Do not forget to subscribe from events when component is destroyed or if needed [collection](./collection-files.md) is changed.
- 💡 `events` in base class [`StatefulVue`](./../src/presentation/components/Shared/StatefulVue.ts) makes lifecycling easier
- 📖 See [Application state | Application layer](./presentation.md#application-state) where the state is implemented using using state pattern.
Inheritance of a Vue components marks whether it uses application state . Components that does not handle application state extends `Vue`. Stateful components mutate or/and react to state changes (such as user selection or search queries) in [ApplicationContext](./../src/application/Context/ApplicationContext.ts) extend [`StatefulVue`](./../src/presentation/components/Shared/StatefulVue.ts) class to access the context / state.
[`StatefulVue`](./../src/presentation/components/Shared/StatefulVue.ts) functions include:
- Creating a singleton of the state and makes it available to presentation layer as single source of truth.
- Providing virtual abstract `handleCollectionState` callback that it calls when
- the Vue loads the component,
- and also every time when state changes.
- Providing `events` member to make lifecycling of state subscriptions events easier because it ensures that components unsubscribe from listening to state events when
- the component is no longer used (destroyed),
- an if [ApplicationContext](./../src/application/Context/ApplicationContext.ts) changes the active [collection](./collection-files.md) to a different one.
📖 Refer to [architecture.md | Application State](./architecture.md#application-state) to get an overview of event handling and [application.md | Application State](./presentation.md#application-state) for deeper look into how the application layer manages state.
## Modals
- [Dialog.vue](./../src/presentation/components/Shared/Dialog.vue) is a shared component that can be used to show modal windows
- Simply wrap the content inside of its slot and call `.show()` method on its reference.
- Example:
[Dialog.vue](./../src/presentation/components/Shared/Dialog.vue) is a shared component that other components used to show modal windows.
You can use it by wrapping the content inside of its `slot` and call `.show()` function on its reference. For example:
```html
<Dialog ref="testDialog">
@@ -58,15 +68,15 @@
## Sass naming convention
- Use lowercase for variables/functions/mixins e.g.
- Use lowercase for variables/functions/mixins, e.g.:
- Variable: `$variable: value;`
- Function: `@function function() {}`
- Mixin: `@mixin mixin() {}`
- Use - for a phrase/compound word e.g.
- Use - for a phrase/compound word, e.g.:
- Variable: `$some-variable: value;`
- Function: `@function some-function() {}`
- Mixin: `@mixin some-mixin() {}`
- Grouping and name variables from generic to specific e.g.
- Grouping and name variables from generic to specific, e.g.:
- ✅ `$border-blue`, `$border-blue-light`, `$border-blue-lightest`, `$border-red`
- ❌ `$blue-border`, `$light-blue-border`, `$lightest-blue-border`, `$red-border`

View File

@@ -3,14 +3,15 @@
## Benefits of templating
- Generating scripts by sharing code to increase best-practice usage and maintainability.
- Creating self-contained scripts without depending on each other that can be easily shared.
- Creating self-contained scripts without cross-dependencies.
- Use of pipes for writing cleaner code and letting pipes do dirty work.
## Expressions
- Expressions in the language are defined inside mustaches (double brackets, `{{` and `}}`).
- Expression syntax is inspired mainly by [Go Templates](https://pkg.go.dev/text/template).
- Expressions are used in and enabled by functions where they can be used.
- Expressions start and end with mustaches (double brackets, `{{` and `}}`).
- E.g. `Hello {{ $name }} !`
- Syntax is close to [Go Templates ❤️](https://pkg.go.dev/text/template) that has inspired this templating language.
- Functions enables usage of expressions.
- In script definition parts of a function, see [`Function`](./collection-files.md#Function).
- When doing a call as argument values, see [`FunctionCall`](./collection-files.md#Function).
@@ -55,34 +56,36 @@ A function can call other functions such as:
### with
- Skips the block if the variable is absent or empty.
- Binds its context (`.`) value of provided argument for the parameter if provided one.
- A block is defined as `{{ with $parameterName }} Parameter value is {{ . }} here {{ end }}`.
- The parameters used for `with` condition should be declared as optional, otherwise `with` block becomes redundant.
- Example:
Skips its "block" if the variable is absent or empty. Its "block" is between `with` start (`{{ with .. }}`) and end (`{{ end }`}) expressions. E.g. `{{ with $parameterName }} Hi, I'm a block! {{ end }}`.
```yaml
function: FunctionThatOutputsConditionally
parameters:
- name: 'argument'
optional: true
code: |-
{{ with $argument }}
Value is: {{ . }}
{{ end }}
```
Binds its context (`.`) value of provided argument for the parameter if provided one. E.g. `{{ with $parameterName }} Parameter value is {{ . }} here {{ end }}`.
💡 Declare parameters used for `with` condition as optional. Set `optional: true` for the argument if you use it like `{{ with $argument }} .. {{ end }}`.
Example:
```yaml
function: FunctionThatOutputsConditionally
parameters:
- name: 'argument'
optional: true
code: |-
{{ with $argument }}
Value is: {{ . }}
{{ end }}
```
### Pipes
- Pipes are set of functions available for handling text in privacy.sexy.
- Pipes are functions available for handling text.
- Allows stacking actions one after another also known as "chaining".
- Just like [Unix pipelines](https://en.wikipedia.org/wiki/Pipeline_(Unix)), the concept is simple: each pipeline's output becomes the input of the following pipe.
- Pipes are provided and defined by the compiler and consumed by collection files.
- Pipes can be combined with [parameter substitution](#parameter-substitution) and [with](#with).
- Like [Unix pipelines](https://en.wikipedia.org/wiki/Pipeline_(Unix)), the concept is simple: each pipeline's output becomes the input of the following pipe.
- You cannot create pipes. [A dedicated compiler](./application.md#parsing-and-compiling) provides pre-defined pipes to consume in collection files.
- You can combine pipes with other expressions such as [parameter substitution](#parameter-substitution) and [with](#with) syntax.
- ❗ Pipe names must be camelCase without any space or special characters.
- **Existing pipes**
- `inlinePowerShell`: Converts a multi-lined PowerShell script to a single line.
- `escapeDoubleQuotes`: Escapes `"` characters to be used inside double quotes (`"`)
- `escapeDoubleQuotes`: Escapes `"` characters, allows you to use them inside double quotes (`"`).
- **Example usages**
- `{{ with $code }} echo "{{ . | inlinePowerShell }}" {{ end }}`
- `{{ with $code }} echo "{{ . | inlinePowerShell | escapeDoubleQuotes }}" {{ end }}`

View File

@@ -1,61 +1,81 @@
# Tests
- There are two different types of tests executed:
1. [Unit tests](#unit-tests)
2. [Integration tests](#integration-tests)
3. [End-to-end (E2E) tests](#e2e-tests)
- All tests
- Uses [Mocha](https://mochajs.org/) and [Chai](https://www.chaijs.com/).
- Are written in files that includes `.spec` extension.
- 💡 You can use path/module alias `@/tests` in import statements.
There are different types of tests executed:
1. [Unit tests](#unit-tests)
2. [Integration tests](#integration-tests)
3. [End-to-end (E2E) tests](#e2e-tests)
Common aspects for all tests:
- They use [Mocha](https://mochajs.org/) and [Chai](https://www.chaijs.com/).
- Their files end with `.spec.{ts|js}` suffix.
💡 You can use path/module alias `@/tests` in import statements.
## Unit tests
- Tests each component in isolation.
- Defined in [`./tests/unit`](./../tests/unit).
- They follow same folder structure as [`./src`](./../src).
- Unit tests test each component in isolation.
- All unit tests goes under [`./tests/unit`](./../tests/unit).
- They rely on [stubs](./../tests/unit/shared/Stubs) for isolation.
### Naming
### Unit tests structure
- [`./src/`](./../src/)
- Includes source code that unit tests will test.
- [`./tests/unit/`](./../tests/unit/)
- Includes test code.
- Tests follow same folder structure as [`./src/`](./../src).
- E.g. if system under test lies in [`./src/application/ApplicationFactory.ts`](./../src/application/ApplicationFactory.ts) then its tests would be in test would be at [`./tests/unit/application/ApplicationFactory.spec.ts`](./../tests/unit/application/ApplicationFactory.spec.ts).
- [`shared/`](./../tests/unit/shared/)
- Includes common functionality that's shared across unit tests.
- [`Assertions/`](./../tests/unit/shared/Assertions):
- Common assertions that extend [Chai Assertion Library](https://www.chaijs.com/).
- Asserting functions should start with `expect` prefix.
- [`TestCases/`](./../tests/unit/shared/TestCases/)
- Shared test cases.
- Functions that calls `it()` from [Mocha test framework](https://mochajs.org/) should have `it` prefix.
- E.g. `itEachAbsentCollectionValue()`.
- [`Stubs/`](./../tests/unit/shared/Stubs)
- Includes stubs to be able to test components in isolation.
- Stubs have minimal and dummy behavior to be functional, they may also have spying or mocking functions.
### Unit tests naming
- Each test suite first describe the system under test.
- E.g. tests for class `Application` is categorized under `Application`.
- Tests for specific methods are categorized under method name (if applicable).
- E.g. test for `run()` is categorized under `run`.
- E.g. tests for class `Application.ts` are all inside `Application.spec.ts`.
- `describe` blocks tests for same function (if applicable).
- E.g. test for `run()` are inside `describe('run', () => ..)`.
### Act, arrange, assert
- Tests use act, arrange and assert (AAA) pattern when applicable.
- **Arrange**
- Should set up the test case.
- Sets up the test case.
- Starts with comment line `// arrange`.
- **Act**
- Should cover the main thing to be tested.
- Executes the actual test.
- Starts with comment line `// act`.
- **Assert**
- Should elicit some sort of response.
- Elicit some sort of expectation.
- Starts with comment line `// assert`.
### Stubs
- Stubs are defined in [`./tests/stubs`](./../tests/unit/stubs).
- They implement dummy behavior to be functional.
## Integration tests
- Tests functionality of a component in combination with others (not isolated).
- Ensure dependencies to third parties work as expected.
- Defined in [`./tests/integration`](./../tests/integration).
- Defined in [./tests/integration](./../tests/integration).
## E2E tests
- Test the functionality and performance of a running application.
- E2E tests are configured by vue plugin [`e2e-cypress`](https://github.com/vuejs/vue-cli/tree/dev/packages/@vue/cli-plugin-e2e-cypress#readme) for Vue CLI.
- Names and folders are structured logically based on tests.
- Vue CLI plugin [`e2e-cypress`](https://github.com/vuejs/vue-cli/tree/dev/packages/@vue/cli-plugin-e2e-cypress#readme) configures E2E tests.
- Test names and folders have logical structure based on tests executed.
- The structure is following:
- [`cypress.json`](./../cypress.json): Cypress configuration file.
- [`./tests/e2e/`](./../tests/e2e/): Base Cypress folder.
- [`/specs/`](./../tests/e2e/specs/): Test files, test are named with `.spec.js` extension.
- [`/plugins/index.js`](./../tests/e2e/plugins/index.js): Plugin file executed before project is loaded.
- [`/specs/`](./../tests/e2e/specs/): Test files named with `.spec.js` extension.
- [`/plugins/index.js`](./../tests/e2e/plugins/index.js): Plugin file executed before loading project.
- [`/support/index.js`](./../tests/e2e/support/index.js): Support file, runs before every single spec file.
- *(Ignored)* `/videos`: Asset folder for videos taken during tests.
- *(Ignored)* `/screenshots`: Asset folder for Screenshots taken during tests.

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

4280
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "privacy.sexy",
"version": "0.11.2",
"version": "0.11.3",
"private": true,
"description": "Enforce privacy & security best-practices on Windows and macOS, because privacy is sexy 🍑🍆",
"author": "undergroundwires",
@@ -23,20 +23,20 @@
},
"main": "background.js",
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.36",
"@fortawesome/free-brands-svg-icons": "^5.15.4",
"@fortawesome/free-regular-svg-icons": "^5.15.4",
"@fortawesome/free-solid-svg-icons": "^5.15.4",
"@fortawesome/fontawesome-svg-core": "^1.3.0",
"@fortawesome/free-brands-svg-icons": "^6.0.0",
"@fortawesome/free-regular-svg-icons": "^6.0.0",
"@fortawesome/free-solid-svg-icons": "^6.0.0",
"@fortawesome/vue-fontawesome": "^2.0.6",
"@juggle/resize-observer": "^3.3.1",
"ace-builds": "^1.4.13",
"core-js": "^3.18.3",
"cross-fetch": "^3.1.4",
"ace-builds": "^1.4.14",
"core-js": "^3.21.1",
"cross-fetch": "^3.1.5",
"electron-progressbar": "^2.0.1",
"file-saver": "^2.0.5",
"install": "^0.13.0",
"liquor-tree": "^0.2.70",
"npm": "^8.1.1",
"npm": "^8.5.3",
"v-tooltip": "2.1.3",
"vue": "^2.6.14",
"vue-class-component": "^7.2.6",
@@ -44,49 +44,50 @@
"vue-property-decorator": "^9.1.2"
},
"devDependencies": {
"@types/ace": "0.0.47",
"@types/chai": "^4.2.22",
"@types/file-saver": "^2.0.3",
"@types/mocha": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"@vue/cli-plugin-babel": "~5.0.0-rc.1",
"@vue/cli-plugin-e2e-cypress": "~5.0.0-rc.1",
"@vue/cli-plugin-eslint": "~5.0.0-rc.1",
"@vue/cli-plugin-typescript": "~5.0.0-rc.1",
"@vue/cli-plugin-unit-mocha": "~5.0.0-rc.1",
"@vue/cli-service": "~5.0.0-rc.1",
"@types/ace": "^0.0.48",
"@types/chai": "^4.3.0",
"@types/file-saver": "^2.0.5",
"@types/mocha": "^9.1.0",
"@typescript-eslint/eslint-plugin": "^5.13.0",
"@typescript-eslint/parser": "^5.13.0",
"@vue/cli-plugin-babel": "~5.0.1",
"@vue/cli-plugin-e2e-cypress": "~5.0.1",
"@vue/cli-plugin-eslint": "~5.0.1",
"@vue/cli-plugin-typescript": "~5.0.1",
"@vue/cli-plugin-unit-mocha": "~5.0.1",
"@vue/cli-service": "~5.0.1",
"@vue/eslint-config-airbnb": "^6.0.0",
"@vue/eslint-config-typescript": "^9.1.0",
"@vue/test-utils": "1.2.2",
"chai": "^4.3.4",
"cypress": "^8.3.0",
"electron": "^15.3.0",
"@vue/eslint-config-typescript": "^10.0.0",
"@vue/test-utils": "1.3.0",
"chai": "^4.3.6",
"cypress": "^9.5.1",
"electron": "^17.1.0",
"electron-builder": "^22.14.13",
"electron-devtools-installer": "^3.2.0",
"electron-log": "^4.4.1",
"electron-updater": "^4.3.9",
"eslint": "^7.32.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-vue": "^8.0.3",
"eslint-plugin-vuejs-accessibility": "^1.1.0",
"electron-log": "^4.4.6",
"electron-updater": "^5.0.0",
"eslint": "7.32.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-vue": "^8.5.0",
"eslint-plugin-vuejs-accessibility": "^1.1.1",
"js-yaml-loader": "^1.2.2",
"markdownlint-cli": "^0.29.0",
"raw-loader": "^4.0.2",
"remark-cli": "^10.0.0",
"markdownlint-cli": "^0.31.1",
"remark-cli": "^10.0.1",
"remark-lint-no-dead-urls": "^1.1.0",
"remark-preset-lint-consistent": "^5.1.0",
"remark-validate-links": "^11.0.1",
"sass": "^1.43.3",
"sass-loader": "10.2.0",
"remark-preset-lint-consistent": "^5.1.1",
"remark-validate-links": "^11.0.2",
"sass": "^1.49.9",
"sass-loader": "^12.6.0",
"ts-loader": "9.0.1",
"tslib": "^2.3.1",
"typescript": "^4.4.4",
"typescript": "^4.6.2",
"vue-cli-plugin-electron-builder": "^2.1.1",
"vue-template-compiler": "^2.6.14",
"yaml-lint": "^1.2.4"
},
"//devDependencies": {
"ts-loader": "Here as workaround for vue-cli-plugin-electron-builder using older webpack 4"
"ts-loader": "Here as workaround for vue-cli-plugin-electron-builder using older webpack 4",
"eslint": "Stuck at 7.32.0 because Vue CLI not supporting 8.x.x"
},
"homepage": "https://privacy.sexy",
"repository": {

View File

@@ -3,17 +3,17 @@ import { AsyncLazy } from '@/infrastructure/Threading/AsyncLazy';
import { IApplicationFactory } from './IApplicationFactory';
import { parseApplication } from './Parser/ApplicationParser';
export type ApplicationGetter = () => IApplication;
const ApplicationGetter: ApplicationGetter = parseApplication;
export type ApplicationGetterType = () => IApplication;
const ApplicationGetter: ApplicationGetterType = parseApplication;
export class ApplicationFactory implements IApplicationFactory {
public static readonly Current: IApplicationFactory = new ApplicationFactory(ApplicationGetter);
private readonly getter: AsyncLazy<IApplication>;
protected constructor(costlyGetter: ApplicationGetter) {
protected constructor(costlyGetter: ApplicationGetterType) {
if (!costlyGetter) {
throw new Error('undefined getter');
throw new Error('missing getter');
}
this.getter = new AsyncLazy<IApplication>(() => Promise.resolve(costlyGetter()));
}

View File

@@ -1,7 +1,7 @@
// Compares to Array<T> objects for equality, ignoring order
export function scrambledEqual<T>(array1: readonly T[], array2: readonly T[]) {
if (!array1) { throw new Error('undefined first array'); }
if (!array2) { throw new Error('undefined second array'); }
if (!array1) { throw new Error('missing first array'); }
if (!array2) { throw new Error('missing second array'); }
const sortedArray1 = sort(array1);
const sortedArray2 = sort(array2);
return sequenceEqual(sortedArray1, sortedArray2);
@@ -12,8 +12,8 @@ export function scrambledEqual<T>(array1: readonly T[], array2: readonly T[]) {
// Compares to Array<T> objects for equality in same order
export function sequenceEqual<T>(array1: readonly T[], array2: readonly T[]) {
if (!array1) { throw new Error('undefined first array'); }
if (!array2) { throw new Error('undefined second array'); }
if (!array1) { throw new Error('missing first array'); }
if (!array2) { throw new Error('missing second array'); }
if (array1.length !== array2.length) {
return false;
}

View File

@@ -21,7 +21,7 @@ function parseEnumValue<T extends EnumType, TEnumValue extends EnumType>(
enumVariable: EnumVariable<T, TEnumValue>,
): TEnumValue {
if (!value) {
throw new Error(`undefined ${enumName}`);
throw new Error(`missing ${enumName}`);
}
if (typeof value !== 'string') {
throw new Error(`unexpected type of ${enumName}: "${typeof value}"`);
@@ -54,8 +54,8 @@ export function assertInRange<T extends EnumType, TEnumValue extends EnumType>(
value: TEnumValue,
enumVariable: EnumVariable<T, TEnumValue>,
) {
if (value === undefined) {
throw new Error('undefined enum value');
if (value === undefined || value === null) {
throw new Error('absent enum value');
}
if (!(value in enumVariable)) {
throw new RangeError(`enum value "${value}" is out of range`);

View File

@@ -20,7 +20,7 @@ export abstract class ScriptingLanguageFactory<T> implements IScriptingLanguageF
protected registerGetter(language: ScriptingLanguage, getter: Getter<T>) {
assertInRange(language, ScriptingLanguage);
if (!getter) {
throw new Error('undefined getter');
throw new Error('missing getter');
}
if (this.getters.has(language)) {
throw new Error(`${ScriptingLanguage[language]} is already registered`);

View File

@@ -27,12 +27,12 @@ export class ApplicationContext implements IApplicationContext {
initialContext: OperatingSystem,
) {
validateApp(app);
assertInRange(initialContext, OperatingSystem);
this.states = initializeStates(app);
this.changeContext(initialContext);
}
public changeContext(os: OperatingSystem): void {
assertInRange(os, OperatingSystem);
if (this.currentOs === os) {
return;
}
@@ -51,7 +51,7 @@ export class ApplicationContext implements IApplicationContext {
function validateApp(app: IApplication) {
if (!app) {
throw new Error('undefined app');
throw new Error('missing app');
}
}

View File

@@ -11,8 +11,8 @@ export async function buildContext(
factory: IApplicationFactory = ApplicationFactory.Current,
environment = Environment.CurrentEnvironment,
): Promise<IApplicationContext> {
if (!factory) { throw new Error('undefined factory'); }
if (!environment) { throw new Error('undefined environment'); }
if (!factory) { throw new Error('missing factory'); }
if (!environment) { throw new Error('missing environment'); }
const app = await factory.getApp();
const os = getInitialOs(app, environment);
return new ApplicationContext(app, os);

View File

@@ -10,8 +10,8 @@ export interface IReadOnlyApplicationContext {
}
export interface IApplicationContext extends IReadOnlyApplicationContext {
readonly state: ICategoryCollectionState;
changeContext(os: OperatingSystem): void;
readonly state: ICategoryCollectionState;
changeContext(os: OperatingSystem): void;
}
export interface IApplicationContextChangedEvent {

View File

@@ -21,9 +21,9 @@ export class ApplicationCode implements IApplicationCode {
private readonly scriptingDefinition: IScriptingDefinition,
private readonly generator: IUserScriptGenerator = new UserScriptGenerator(),
) {
if (!userSelection) { throw new Error('userSelection is null or undefined'); }
if (!scriptingDefinition) { throw new Error('scriptingDefinition is null or undefined'); }
if (!generator) { throw new Error('generator is null or undefined'); }
if (!userSelection) { throw new Error('missing userSelection'); }
if (!scriptingDefinition) { throw new Error('missing scriptingDefinition'); }
if (!generator) { throw new Error('missing generator'); }
this.setCode(userSelection.selectedScripts);
userSelection.changed.on((scripts) => {
this.setCode(scripts);

View File

@@ -17,8 +17,8 @@ export class UserScriptGenerator implements IUserScriptGenerator {
selectedScripts: ReadonlyArray<SelectedScript>,
scriptingDefinition: IScriptingDefinition,
): IUserScript {
if (!selectedScripts) { throw new Error('undefined scripts'); }
if (!scriptingDefinition) { throw new Error('undefined definition'); }
if (!selectedScripts) { throw new Error('missing scripts'); }
if (!scriptingDefinition) { throw new Error('missing definition'); }
if (!selectedScripts.length) {
return { code: '', scriptPositions: new Map<SelectedScript, ICodePosition>() };
}

View File

@@ -109,6 +109,9 @@ export class UserSelection implements IUserSelection {
.getAllScripts()
.filter((script) => !this.scripts.exists(script.id))
.map((script) => new SelectedScript(script, false));
if (scriptsToSelect.length === 0) {
return;
}
for (const script of scriptsToSelect) {
this.scripts.addItem(script);
}
@@ -116,6 +119,9 @@ export class UserSelection implements IUserSelection {
}
public deselectAll(): void {
if (this.scripts.length === 0) {
return;
}
const selectedScriptIds = this.scripts.getItems().map((script) => script.id);
for (const scriptId of selectedScriptIds) {
this.scripts.removeItem(scriptId);
@@ -127,20 +133,35 @@ export class UserSelection implements IUserSelection {
if (!scripts || scripts.length === 0) {
throw new Error('Scripts are empty. Use deselectAll() if you want to deselect everything');
}
// Unselect from selected scripts
if (this.scripts.length !== 0) {
this.scripts.getItems()
.filter((existing) => !scripts.some((script) => existing.id === script.id))
.map((script) => script.id)
.forEach((scriptId) => this.scripts.removeItem(scriptId));
let totalChanged = 0;
totalChanged += this.unselectMissingWithoutNotifying(scripts);
totalChanged += this.selectNewWithoutNotifying(scripts);
if (totalChanged > 0) {
this.changed.notify(this.scripts.getItems());
}
// Select from unselected scripts
}
private unselectMissingWithoutNotifying(scripts: readonly IScript[]): number {
if (this.scripts.length === 0 || scripts.length === 0) {
return 0;
}
const existingItems = this.scripts.getItems();
const missingIds = existingItems
.filter((existing) => !scripts.some((script) => existing.id === script.id))
.map((script) => script.id);
for (const id of missingIds) {
this.scripts.removeItem(id);
}
return missingIds.length;
}
private selectNewWithoutNotifying(scripts: readonly IScript[]): number {
const unselectedScripts = scripts
.filter((script) => !this.scripts.exists(script.id))
.map((script) => new SelectedScript(script, false));
for (const toSelect of unselectedScripts) {
this.scripts.addItem(toSelect);
for (const newScript of unselectedScripts) {
this.scripts.addItem(newScript);
}
this.changed.notify(this.scripts.getItems());
return unselectedScripts.length;
}
}

View File

@@ -27,7 +27,7 @@ export class DetectorBuilder {
private detect(userAgent: string): OperatingSystem {
if (!userAgent) {
throw new Error('User agent is null or undefined');
throw new Error('missing userAgent');
}
if (this.existingPartsInUserAgent.some((part) => !userAgent.includes(part))) {
return undefined;

View File

@@ -1,9 +1,9 @@
import { CollectionData } from 'js-yaml-loader!@/*';
import type { CollectionData } from '@/application/collections/';
import { IApplication } from '@/domain/IApplication';
import { IProjectInformation } from '@/domain/IProjectInformation';
import { ICategoryCollection } from '@/domain/ICategoryCollection';
import WindowsData from 'js-yaml-loader!@/application/collections/windows.yaml';
import MacOsData from 'js-yaml-loader!@/application/collections/macos.yaml';
import WindowsData from '@/application/collections/windows.yaml';
import MacOsData from '@/application/collections/macos.yaml';
import { parseProjectInformation } from '@/application/Parser/ProjectInformationParser';
import { Application } from '@/domain/Application';
import { parseCategoryCollection } from './CategoryCollectionParser';
@@ -32,10 +32,10 @@ const PreParsedCollections: readonly CollectionData [] = [
];
function validateCollectionsData(collections: readonly CollectionData[]) {
if (!collections.length) {
throw new Error('no collection provided');
if (!collections || !collections.length) {
throw new Error('missing collections');
}
if (collections.some((collection) => !collection)) {
throw new Error('undefined collection provided');
throw new Error('missing collection provided');
}
}

View File

@@ -1,4 +1,4 @@
import { CollectionData } from 'js-yaml-loader!@/*';
import type { CollectionData } from '@/application/collections/';
import { OperatingSystem } from '@/domain/OperatingSystem';
import { ICategoryCollection } from '@/domain/ICategoryCollection';
import { CategoryCollection } from '@/domain/CategoryCollection';
@@ -29,7 +29,7 @@ export function parseCategoryCollection(
function validate(content: CollectionData): void {
if (!content) {
throw new Error('content is null or undefined');
throw new Error('missing content');
}
if (!content.actions || content.actions.length <= 0) {
throw new Error('content does not define any action');

View File

@@ -1,6 +1,6 @@
import {
import type {
CategoryData, ScriptData, CategoryOrScriptData, InstructionHolder,
} from 'js-yaml-loader!@/*';
} from '@/application/collections/';
import { Script } from '@/domain/Script';
import { Category } from '@/domain/Category';
import { parseDocUrls } from './DocumentationParser';
@@ -13,7 +13,7 @@ export function parseCategory(
category: CategoryData,
context: ICategoryCollectionParseContext,
): Category {
if (!context) { throw new Error('undefined context'); }
if (!context) { throw new Error('missing context'); }
ensureValid(category);
const children: ICategoryChildren = {
subCategories: new Array<Category>(),
@@ -33,7 +33,7 @@ export function parseCategory(
function ensureValid(category: CategoryData) {
if (!category) {
throw Error('category is null or undefined');
throw Error('missing category');
}
if (!category.children || category.children.length === 0) {
throw Error(`category has no children: "${category.category}"`);

View File

@@ -1,8 +1,8 @@
import { DocumentableData, DocumentationUrlsData } from 'js-yaml-loader!@/*';
import type { DocumentableData, DocumentationUrlsData } from '@/application/collections/';
export function parseDocUrls(documentable: DocumentableData): ReadonlyArray<string> {
if (!documentable) {
throw new Error('documentable is null or undefined');
throw new Error('missing documentable');
}
const { docs } = documentable;
if (!docs || !docs.length) {

View File

@@ -1,12 +1,14 @@
import { IProjectInformation } from '@/domain/IProjectInformation';
import { ProjectInformation } from '@/domain/ProjectInformation';
import { Version } from '@/domain/Version';
export function parseProjectInformation(
environment: NodeJS.ProcessEnv,
): IProjectInformation {
const version = new Version(environment.VUE_APP_VERSION);
return new ProjectInformation(
environment.VUE_APP_NAME,
environment.VUE_APP_VERSION,
version,
environment.VUE_APP_REPOSITORY_URL,
environment.VUE_APP_HOMEPAGE_URL,
);

View File

@@ -1,4 +1,4 @@
import { FunctionData } from 'js-yaml-loader!@/*';
import type { FunctionData } from '@/application/collections/';
import { IScriptingDefinition } from '@/domain/IScriptingDefinition';
import { ILanguageSyntax } from '@/domain/ScriptCode';
import { IScriptCompiler } from './Compiler/IScriptCompiler';
@@ -17,7 +17,7 @@ export class CategoryCollectionParseContext implements ICategoryCollectionParseC
scripting: IScriptingDefinition,
syntaxFactory: ISyntaxFactory = new SyntaxFactory(),
) {
if (!scripting) { throw new Error('undefined scripting'); }
if (!scripting) { throw new Error('missing scripting'); }
this.syntax = syntaxFactory.create(scripting.language);
this.compiler = new ScriptCompiler(functionsData, this.syntax);
}

View File

@@ -8,23 +8,25 @@ import { ExpressionEvaluationContext, IExpressionEvaluationContext } from './Exp
export type ExpressionEvaluator = (context: IExpressionEvaluationContext) => string;
export class Expression implements IExpression {
public readonly parameters: IReadOnlyFunctionParameterCollection;
constructor(
public readonly position: ExpressionPosition,
public readonly evaluator: ExpressionEvaluator,
public readonly parameters
: IReadOnlyFunctionParameterCollection = new FunctionParameterCollection(),
parameters?: IReadOnlyFunctionParameterCollection,
) {
if (!position) {
throw new Error('undefined position');
throw new Error('missing position');
}
if (!evaluator) {
throw new Error('undefined evaluator');
throw new Error('missing evaluator');
}
this.parameters = parameters ?? new FunctionParameterCollection();
}
public evaluate(context: IExpressionEvaluationContext): string {
if (!context) {
throw new Error('undefined context');
throw new Error('missing context');
}
validateThatAllRequiredParametersAreSatisfied(this.parameters, context.args);
const args = filterUnusedArguments(this.parameters, context.args);

View File

@@ -13,7 +13,7 @@ export class ExpressionEvaluationContext implements IExpressionEvaluationContext
public readonly pipelineCompiler: IPipelineCompiler = new PipelineCompiler(),
) {
if (!args) {
throw new Error('undefined args, send empty collection instead');
throw new Error('missing args, send empty collection instead.');
}
}
}

View File

@@ -15,7 +15,7 @@ export class ExpressionsCompiler implements IExpressionsCompiler {
args: IReadOnlyFunctionCallArgumentCollection,
): string {
if (!args) {
throw new Error('undefined args, send empty collection instead');
throw new Error('missing args, send empty collection instead.');
}
if (!code) {
return code;

View File

@@ -10,8 +10,11 @@ const Parsers = [
export class CompositeExpressionParser implements IExpressionParser {
public constructor(private readonly leafs: readonly IExpressionParser[] = Parsers) {
if (!leafs) {
throw new Error('missing leafs');
}
if (leafs.some((leaf) => !leaf)) {
throw new Error('undefined leaf');
throw new Error('missing leaf');
}
}

View File

@@ -16,7 +16,7 @@ export abstract class RegexParser implements IExpressionParser {
private* findRegexExpressions(code: string): Iterable<IExpression> {
if (!code) {
throw new Error('undefined code');
throw new Error('missing code');
}
const matches = code.matchAll(this.regex);
for (const match of matches) {

View File

@@ -4,7 +4,10 @@ export class EscapeDoubleQuotes implements IPipe {
public readonly name: string = 'escapeDoubleQuotes';
public apply(raw: string): string {
return raw?.replaceAll('"', '"^""');
if (!raw) {
return raw;
}
return raw.replaceAll('"', '"^""');
/* eslint-disable max-len */
/*
"^"" is the most robust and stable choice.

View File

@@ -15,8 +15,11 @@ export class PipeFactory implements IPipeFactory {
private readonly pipes = new Map<string, IPipe>();
constructor(pipes: readonly IPipe[] = RegisteredPipes) {
if (!pipes) {
throw new Error('missing pipes');
}
if (pipes.some((pipe) => !pipe)) {
throw new Error('undefined pipe in list');
throw new Error('missing pipe in list');
}
for (const pipe of pipes) {
this.registerPipe(pipe);

View File

@@ -23,8 +23,8 @@ function extractPipeNames(pipeline: string): string[] {
}
function ensureValidArguments(value: string, pipeline: string) {
if (!value) { throw new Error('undefined value'); }
if (!pipeline) { throw new Error('undefined pipeline'); }
if (!value) { throw new Error('missing value'); }
if (!pipeline) { throw new Error('missing pipeline'); }
if (!pipeline.trimStart().startsWith('|')) {
throw new Error('pipeline does not start with pipe');
}

View File

@@ -8,7 +8,7 @@ export class FunctionCallArgument implements IFunctionCallArgument {
) {
ensureValidParameterName(parameterName);
if (!argumentValue) {
throw new Error(`undefined argument value for "${parameterName}"`);
throw new Error(`missing argument value for "${parameterName}"`);
}
}
}

View File

@@ -6,7 +6,7 @@ export class FunctionCallArgumentCollection implements IFunctionCallArgumentColl
public addArgument(argument: IFunctionCallArgument): void {
if (!argument) {
throw new Error('undefined argument');
throw new Error('missing argument');
}
if (this.hasArgument(argument.parameterName)) {
throw new Error(`argument value for parameter ${argument.parameterName} is already provided`);
@@ -20,14 +20,14 @@ export class FunctionCallArgumentCollection implements IFunctionCallArgumentColl
public hasArgument(parameterName: string): boolean {
if (!parameterName) {
throw new Error('undefined parameter name');
throw new Error('missing parameter name');
}
return this.arguments.has(parameterName);
}
public getArgument(parameterName: string): IFunctionCallArgument {
if (!parameterName) {
throw new Error('undefined parameter name');
throw new Error('missing parameter name');
}
const arg = this.arguments.get(parameterName);
if (!arg) {

View File

@@ -22,9 +22,9 @@ export class FunctionCallCompiler implements IFunctionCallCompiler {
calls: IFunctionCall[],
functions: ISharedFunctionCollection,
): ICompiledCode {
if (!functions) { throw new Error('undefined functions'); }
if (!calls) { throw new Error('undefined calls'); }
if (calls.some((f) => !f)) { throw new Error('undefined function call'); }
if (!functions) { throw new Error('missing functions'); }
if (!calls) { throw new Error('missing calls'); }
if (calls.some((f) => !f)) { throw new Error('missing function call'); }
const context: ICompilationContext = {
allFunctions: functions,
callSequence: calls,

View File

@@ -7,10 +7,10 @@ export class FunctionCall implements IFunctionCall {
public readonly args: IReadOnlyFunctionCallArgumentCollection,
) {
if (!functionName) {
throw new Error('empty function name in function call');
throw new Error('missing function name in function call');
}
if (!args) {
throw new Error('undefined args');
throw new Error('missing args');
}
}
}

View File

@@ -1,4 +1,4 @@
import { FunctionCallData, FunctionCallsData, FunctionCallParametersData } from 'js-yaml-loader!@/*';
import type { FunctionCallData, FunctionCallsData, FunctionCallParametersData } from '@/application/collections/';
import { IFunctionCall } from './IFunctionCall';
import { FunctionCallArgumentCollection } from './Argument/FunctionCallArgumentCollection';
import { FunctionCallArgument } from './Argument/FunctionCallArgument';
@@ -6,7 +6,7 @@ import { FunctionCall } from './FunctionCall';
export function parseFunctionCalls(calls: FunctionCallsData): IFunctionCall[] {
if (calls === undefined) {
throw new Error('undefined call data');
throw new Error('missing call data');
}
const sequence = getCallSequence(calls);
return sequence.map((call) => parseFunctionCall(call));
@@ -24,7 +24,7 @@ function getCallSequence(calls: FunctionCallsData): FunctionCallData[] {
function parseFunctionCall(call: FunctionCallData): IFunctionCall {
if (!call) {
throw new Error('undefined function call');
throw new Error('missing call data');
}
const callArgs = parseArgs(call.parameters);
return new FunctionCall(call.function, callArgs);

View File

@@ -1,4 +1,4 @@
import { FunctionData } from 'js-yaml-loader!@/*';
import type { FunctionData } from '@/application/collections/';
import { ISharedFunctionCollection } from './ISharedFunctionCollection';
export interface ISharedFunctionsParser {

View File

@@ -19,7 +19,7 @@ export class FunctionParameterCollection implements IFunctionParameterCollection
private ensureValidParameter(parameter: IFunctionParameter) {
if (!parameter) {
throw new Error('undefined parameter');
throw new Error('missing parameter');
}
if (this.includesName(parameter.name)) {
throw new Error(`duplicate parameter name: "${parameter.name}"`);

View File

@@ -1,6 +1,6 @@
export function ensureValidParameterName(parameterName: string) {
if (!parameterName) {
throw new Error('undefined parameter name');
throw new Error('missing parameter name');
}
if (!parameterName.match(/^[0-9a-zA-Z]+$/)) {
throw new Error(`parameter name must be alphanumeric but it was "${parameterName}"`);

View File

@@ -9,11 +9,8 @@ export function createCallerFunction(
parameters: IReadOnlyFunctionParameterCollection,
callSequence: readonly IFunctionCall[],
): ISharedFunction {
if (!callSequence) {
throw new Error(`undefined call sequence in function "${name}"`);
}
if (!callSequence.length) {
throw new Error(`empty call sequence in function "${name}"`);
if (!callSequence || !callSequence.length) {
throw new Error(`missing call sequence in function "${name}"`);
}
return new SharedFunction(name, parameters, callSequence, FunctionBodyType.Calls);
}
@@ -43,8 +40,8 @@ class SharedFunction implements ISharedFunction {
content: IFunctionCode | readonly IFunctionCall[],
bodyType: FunctionBodyType,
) {
if (!name) { throw new Error('undefined function name'); }
if (!parameters) { throw new Error('undefined parameters'); }
if (!name) { throw new Error('missing function name'); }
if (!parameters) { throw new Error('missing parameters'); }
this.body = {
type: bodyType,
code: bodyType === FunctionBodyType.Code ? content as IFunctionCode : undefined,

View File

@@ -5,7 +5,7 @@ export class SharedFunctionCollection implements ISharedFunctionCollection {
private readonly functionsByName = new Map<string, ISharedFunction>();
public addFunction(func: ISharedFunction): void {
if (!func) { throw new Error('undefined function'); }
if (!func) { throw new Error('missing function'); }
if (this.has(func.name)) {
throw new Error(`function with name ${func.name} already exists`);
}
@@ -13,7 +13,7 @@ export class SharedFunctionCollection implements ISharedFunctionCollection {
}
public getFunctionByName(name: string): ISharedFunction {
if (!name) { throw Error('undefined function name'); }
if (!name) { throw Error('missing function name'); }
const func = this.functionsByName.get(name);
if (!func) {
throw new Error(`called function is not defined "${name}"`);

View File

@@ -1,4 +1,4 @@
import { FunctionData, InstructionHolder } from 'js-yaml-loader!@/*';
import type { FunctionData, InstructionHolder } from '@/application/collections/';
import { createFunctionWithInlineCode, createCallerFunction } from './SharedFunction';
import { SharedFunctionCollection } from './SharedFunctionCollection';
import { ISharedFunctionCollection } from './ISharedFunctionCollection';

View File

@@ -1,4 +1,4 @@
import { ScriptData } from 'js-yaml-loader!@/*';
import type { ScriptData } from '@/application/collections/';
import { IScriptCode } from '@/domain/IScriptCode';
export interface IScriptCompiler {

View File

@@ -1,4 +1,4 @@
import { FunctionData, ScriptData } from 'js-yaml-loader!@/*';
import type { FunctionData, ScriptData } from '@/application/collections/';
import { IScriptCode } from '@/domain/IScriptCode';
import { ScriptCode, ILanguageSyntax } from '@/domain/ScriptCode';
import { IScriptCompiler } from './IScriptCompiler';
@@ -18,12 +18,12 @@ export class ScriptCompiler implements IScriptCompiler {
private readonly callCompiler: IFunctionCallCompiler = FunctionCallCompiler.instance,
sharedFunctionsParser: ISharedFunctionsParser = SharedFunctionsParser.instance,
) {
if (!syntax) { throw new Error('undefined syntax'); }
if (!syntax) { throw new Error('missing syntax'); }
this.functions = sharedFunctionsParser.parseFunctions(functions);
}
public canCompile(script: ScriptData): boolean {
if (!script) { throw new Error('undefined script'); }
if (!script) { throw new Error('missing script'); }
if (!script.call) {
return false;
}
@@ -31,7 +31,7 @@ export class ScriptCompiler implements IScriptCompiler {
}
public compile(script: ScriptData): IScriptCode {
if (!script) { throw new Error('undefined script'); }
if (!script) { throw new Error('missing script'); }
try {
const calls = parseFunctionCalls(script.call);
const compiledCode = this.callCompiler.compileCall(calls, this.functions);

View File

@@ -1,4 +1,4 @@
import { ScriptData } from 'js-yaml-loader!@/*';
import type { ScriptData } from '@/application/collections/';
import { Script } from '@/domain/Script';
import { RecommendationLevel } from '@/domain/RecommendationLevel';
import { IScriptCode } from '@/domain/IScriptCode';
@@ -13,7 +13,7 @@ export function parseScript(
levelParser = createEnumParser(RecommendationLevel),
): Script {
validateScript(data);
if (!context) { throw new Error('undefined context'); }
if (!context) { throw new Error('missing context'); }
const script = new Script(
/* name: */ data.name,
/* code: */ parseCode(data, context),
@@ -51,7 +51,7 @@ function ensureNotBothCallAndCode(script: ScriptData) {
function validateScript(script: ScriptData) {
if (!script) {
throw new Error('undefined script');
throw new Error('missing script');
}
if (!script.code && !script.call) {
throw new Error('must define either "call" or "code"');

View File

@@ -16,13 +16,13 @@ export class CodeSubstituter implements ICodeSubstituter {
}
public substitute(code: string, info: IProjectInformation): string {
if (!code) { throw new Error('undefined code'); }
if (!info) { throw new Error('undefined info'); }
if (!code) { throw new Error('missing code'); }
if (!info) { throw new Error('missing info'); }
const args = new FunctionCallArgumentCollection();
const substitute = (name: string, value: string) => args
.addArgument(new FunctionCallArgument(name, value));
substitute('homepage', info.homepage);
substitute('version', info.version);
substitute('version', info.version.toString());
substitute('date', this.date.toUTCString());
const compiledCode = this.compiler.compileExpressions(code, args);
return compiledCode;

View File

@@ -1,4 +1,4 @@
import { ScriptingDefinitionData } from 'js-yaml-loader!@/*';
import type { ScriptingDefinitionData } from '@/application/collections/';
import { IScriptingDefinition } from '@/domain/IScriptingDefinition';
import { ScriptingDefinition } from '@/domain/ScriptingDefinition';
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
@@ -18,8 +18,8 @@ export class ScriptingDefinitionParser {
definition: ScriptingDefinitionData,
info: IProjectInformation,
): IScriptingDefinition {
if (!info) { throw new Error('undefined info'); }
if (!definition) { throw new Error('undefined definition'); }
if (!info) { throw new Error('missing info'); }
if (!definition) { throw new Error('missing definition'); }
const language = this.languageParser.parseEnum(definition.language, 'language');
const startCode = this.codeSubstituter.substitute(definition.startCode, info);
const endCode = this.codeSubstituter.substitute(definition.endCode, info);

View File

@@ -1,4 +1,4 @@
declare module 'js-yaml-loader!@/*' {
declare module '@/application/collections/*' {
export interface CollectionData {
readonly os: string;
readonly scripting: ScriptingDefinitionData;

View File

@@ -1745,20 +1745,31 @@ actions:
-
name: Opt out from NVIDIA telemetry
recommend: standard
code: |-
reg add "HKLM\SOFTWARE\NVIDIA Corporation\NvControlPanel2\Client" /v "OptInOrOutPreference" /t REG_DWORD /d 0 /f
reg add "HKLM\SOFTWARE\NVIDIA Corporation\Global\FTS" /v "EnableRID44231" /t REG_DWORD /d 0 /f
reg add "HKLM\SOFTWARE\NVIDIA Corporation\Global\FTS" /v "EnableRID64640" /t REG_DWORD /d 0 /f
reg add "HKLM\SOFTWARE\NVIDIA Corporation\Global\FTS" /v "EnableRID66610" /t REG_DWORD /d 0 /f
reg add "HKLM\SYSTEM\CurrentControlSet\Services\nvlddmkm\Global\Startup" /v "SendTelemetryData" /t REG_DWORD /d 0 /f
reg add "HKLM\SYSTEM\CurrentControlSet\services\NvTelemetryContainer" /v "Start" /t REG_DWORD /d 4 /f
revertCode: |-
reg delete "HKLM\SOFTWARE\NVIDIA Corporation\NvControlPanel2\Client" /v "OptInOrOutPreference" /f
reg delete "HKLM\SOFTWARE\NVIDIA Corporation\Global\FTS" /v "EnableRID44231" /f
reg delete "HKLM\SOFTWARE\NVIDIA Corporation\Global\FTS" /v "EnableRID64640" /f
reg delete "HKLM\SOFTWARE\NVIDIA Corporation\Global\FTS" /v "EnableRID66610" /f
reg delete "HKLM\SYSTEM\CurrentControlSet\Services\nvlddmkm\Global\Startup" /v "SendTelemetryData" /f
reg delete "HKLM\SYSTEM\CurrentControlSet\services\NvTelemetryContainer" /f
call:
function: RunInlineCode
parameters:
code: |-
reg add "HKLM\SOFTWARE\NVIDIA Corporation\NvControlPanel2\Client" /v "OptInOrOutPreference" /t REG_DWORD /d 0 /f
reg add "HKLM\SOFTWARE\NVIDIA Corporation\Global\FTS" /v "EnableRID44231" /t REG_DWORD /d 0 /f
reg add "HKLM\SOFTWARE\NVIDIA Corporation\Global\FTS" /v "EnableRID64640" /t REG_DWORD /d 0 /f
reg add "HKLM\SOFTWARE\NVIDIA Corporation\Global\FTS" /v "EnableRID66610" /t REG_DWORD /d 0 /f
reg add "HKLM\SYSTEM\CurrentControlSet\Services\nvlddmkm\Global\Startup" /v "SendTelemetryData" /t REG_DWORD /d 0 /f
revertCode: |-
reg delete "HKLM\SOFTWARE\NVIDIA Corporation\NvControlPanel2\Client" /v "OptInOrOutPreference" /f
reg delete "HKLM\SOFTWARE\NVIDIA Corporation\Global\FTS" /v "EnableRID44231" /f
reg delete "HKLM\SOFTWARE\NVIDIA Corporation\Global\FTS" /v "EnableRID64640" /f
reg delete "HKLM\SOFTWARE\NVIDIA Corporation\Global\FTS" /v "EnableRID66610" /f
reg delete "HKLM\SYSTEM\CurrentControlSet\Services\nvlddmkm\Global\Startup" /v "SendTelemetryData" /f
-
name: Disable Nvidia Telemetry Container service
docs: https://www.ghacks.net/2016/11/07/nvidia-telemetry-tracking/
call:
function: DisableService
parameters:
serviceName: NvTelemetryContainer
# Display name: "NVIDIA Telemetry Container"
# Description: "Container service for NVIDIA Telemetry"
defaultStartupMode: Automatic
-
name: Disable NVIDIA telemetry services
recommend: standard
@@ -4597,9 +4608,19 @@ actions:
-
name: Delivery Optimization (P2P Windows Updates)
recommend: standard
docs: http://batcmd.com/windows/10/services/dosvc/
docs:
# Delivery Optimization is a cloud-managed solution to offer Windows updates through
# other users' network (peer-to-peer).
- https://docs.microsoft.com/en-us/windows/deployment/update/waas-delivery-optimization
# Delivery Optimization service performs content delivery optimization tasks.
- http://batcmd.com/windows/10/services/dosvc/
# Connects to various Microsoft service endpoints to get metadata, policies, content, device information
# and information of other peers (Windows users).
- https://docs.microsoft.com/en-us/windows/deployment/update/delivery-optimization-workflow
call:
function: DisableService
function: DisableServiceInRegistry
# Using registry way because because other options such as "sc config" or
# "Set-Service" returns "Access is denied" since Windows 10 1809.
parameters:
serviceName: DoSvc # Check: (Get-Service -Name 'DoSvc').StartType
defaultStartupMode: Automatic # Allowed values: Automatic | Manual
@@ -4740,19 +4761,29 @@ actions:
serviceName: MessagingService
defaultStartupMode: Manual # Alowed values: Boot | System | Automatic | Manual
-
name: Windows Push Notification Service
# Hosts Windows notification platform, which provides support for local and push notifications.
# While connected to a VPN that disallows Split Tunneling, the WpnUserService_[unique ID] process bypasses the tunnel
# connecting directly to Microsoft. This behavior will reveal the real IP address of the host. This can be observed with
# the Windows Resource Monitor.
name: Windows Push Notification Service (breaks network settings view on Windows 10)
recommend: strict
docs:
# It enables third-party developers to send toast, tile, badge, and raw updates from their own cloud service.
# In the URL below you can read more about how it communicates with other sources.
- https://docs.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/windows-push-notification-services--wns--overview
# Hosts Windows notification platform, which provides support for local and push notifications.
# According the uncited Wikipedia article, it bypasses VPN and connects directly to Microsoft.
# It reveals real IP address of the host which circumvents the anonymity provided by VPN.
- https://en.wikipedia.org/w/index.php?title=Windows_Push_Notification_Service&oldid=1012335551#Privacy_Issue
# System-wide service:
- http://batcmd.com/windows/10/services/wpnservice/
# Per-user service:
- http://batcmd.com/windows/10/services/wpnuserservice/
# Disabling system-wide user service "WpnUserService" breaks accessing access network settings on Windows 10.
# It works fine on Windows 11.
- https://github.com/undergroundwires/privacy.sexy/issues/110
call:
-
function: ShowWarning
parameters:
message: Disabling Network settings on Windows 10 is known to break Network settings.
ignoreWindows11: true
- # Windows Push Notifications System Service
function: DisableService
parameters:
@@ -6844,15 +6875,18 @@ functions:
# - `setDefaultOnWindows11` parameter changes this behavior to set the default value using `Set-MpPreference`
# On Windows 10:
# - If `default` argument is is provided, it's set using `Set-MpPreference`
# - `default` argument should not be provided if `Remove-MpPreference` is suppored in Windows 10,
# - `default` argument should not be provided if `Remove-MpPreference` is supported in Windows 10.
revertCode: |-
$propertyName = '{{ $property }}'
{{ with $default }} $defaultValue = {{ . }} {{ end }}
$setDefaultOnWindows10 = {{ with $default }} $true # {{ end }} $false
$setDefaultOnWindows11 = {{ with $setDefaultOnWindows11 }} $true # {{ end }} $false
$osVersion = [System.Environment]::OSVersion.Version
function Test-IsWindows10 { ($osVersion.Major -eq 10) -and ($osVersion.Build -lt 22000) }
function Test-IsWindows11 { ($osVersion.Major -gt 10) -or (($osVersion.Major -eq 10) -and ($osVersion.Build -ge 22000)) }
# ------ Set-MpPreference ------
if(($setDefaultOnWindows10 -and [System.Environment]::OSVersion.Version.Major -lt 11) `
-or ($setDefaultOnWindows11 -and [System.Environment]::OSVersion.Version.Major -eq 11)) {
if(($setDefaultOnWindows10 -and (Test-IsWindows10)) -or ($setDefaultOnWindows11 -and (Test-IsWindows11))) {
if((Get-MpPreference -ErrorAction Ignore).$propertyName -eq $defaultValue) {
Write-Host "Skipping. `"$propertyName`" is already configured as desired `"$defaultValue`"."
exit 0
@@ -6900,9 +6934,10 @@ functions:
Write-Error "Failed to set using $($command.Name): $_"
}
exit 1
}
-
name: DisableService
parameters:
parameters:
- name: serviceName
- name: defaultStartupMode # Allowed values: Automatic | Manual
call:
@@ -7000,3 +7035,28 @@ functions:
Write-Host "`"$serviceName`" is already running, no need to start."
}
}
-
name: ShowWarning
parameters:
- name: message
- name: ignoreWindows11 # Ignores warning message on Windows 11, allowed values: true | false, default: false
- name: ignoreWindows10 # Ignores warning message on Windows 10, allowed values: true | false, default: false
call:
function: RunPowerShell
parameters:
code: |-
$warningMessage = '{{ $message }}'
$ignoreWindows10 = {{ with $ignoreWindows10 }} $true # {{ end }} $false
$ignoreWindows11 = {{ with $ignoreWindows11 }} $true # {{ end }} $false
$osVersion = [System.Environment]::OSVersion.Version
function Test-IsWindows10 { ($osVersion.Major -eq 10) -and ($osVersion.Build -lt 22000) }
function Test-IsWindows11 { ($osVersion.Major -gt 10) -or (($osVersion.Major -eq 10) -and ($osVersion.Build -ge 22000)) }
if (($ignoreWindows10 -and (Test-IsWindows10)) -or ($ignoreWindows11 -and (Test-IsWindows11))) {
exit 0 # Skip
}
Write-Warning "$warningMessage"
# revertCode: No warnings needed when reverting

View File

@@ -23,19 +23,16 @@ export class Application implements IApplication {
function validateInformation(info: IProjectInformation) {
if (!info) {
throw new Error('undefined project information');
throw new Error('missing project information');
}
}
function validateCollections(collections: readonly ICategoryCollection[]) {
if (!collections) {
throw new Error('undefined collections');
}
if (collections.length === 0) {
throw new Error('no collection in the list');
if (!collections || !collections.length) {
throw new Error('missing collections');
}
if (collections.filter((c) => !c).length > 0) {
throw new Error('undefined collection in the list');
throw new Error('missing collection in the list');
}
const osList = collections.map((c) => c.os);
const duplicates = getDuplicates(osList);

View File

@@ -37,7 +37,7 @@ function parseScriptsRecursively(category: ICategory): ReadonlyArray<IScript> {
function validateCategory(category: ICategory) {
if (!category.name) {
throw new Error('undefined or empty name');
throw new Error('missing name');
}
if (
(!category.subCategories || category.subCategories.length === 0)

View File

@@ -20,7 +20,7 @@ export class CategoryCollection implements ICategoryCollection {
public readonly scripting: IScriptingDefinition,
) {
if (!scripting) {
throw new Error('undefined scripting definition');
throw new Error('missing scripting definition');
}
this.queryable = makeQueryable(actions);
assertInRange(os, OperatingSystem);
@@ -34,12 +34,7 @@ export class CategoryCollection implements ICategoryCollection {
}
public getScriptsByLevel(level: RecommendationLevel): readonly IScript[] {
if (level === undefined) {
throw new Error('undefined level');
}
if (!(level in RecommendationLevel)) {
throw new Error(`invalid level: ${level}`);
}
assertInRange(level, RecommendationLevel);
return this.queryable.scriptsByLevel.get(level);
}

View File

@@ -1,8 +1,9 @@
import { OperatingSystem } from './OperatingSystem';
import { OperatingSystem } from '@/domain/OperatingSystem';
import { Version } from '@/domain/Version';
export interface IProjectInformation {
readonly name: string;
readonly version: string;
readonly version: Version;
readonly repositoryUrl: string;
readonly homepage: string;
readonly feedbackUrl: string;

View File

@@ -1,21 +1,22 @@
import { assertInRange } from '@/application/Common/Enum';
import { IProjectInformation } from './IProjectInformation';
import { OperatingSystem } from './OperatingSystem';
import { Version } from './Version';
export class ProjectInformation implements IProjectInformation {
public readonly repositoryWebUrl: string;
constructor(
public readonly name: string,
public readonly version: string,
public readonly version: Version,
public readonly repositoryUrl: string,
public readonly homepage: string,
) {
if (!name) {
throw new Error('name is undefined');
}
if (!version || +version <= 0) {
throw new Error('version should be higher than zero');
if (!version) {
throw new Error('undefined version');
}
if (!repositoryUrl) {
throw new Error('repositoryUrl is undefined');
@@ -27,7 +28,8 @@ export class ProjectInformation implements IProjectInformation {
}
public getDownloadUrl(os: OperatingSystem): string {
return `${this.repositoryWebUrl}/releases/download/${this.version}/${getFileName(os, this.version)}`;
const fileName = getFileName(os, this.version.toString());
return `${this.repositoryWebUrl}/releases/download/${this.version}/${fileName}`;
}
public get feedbackUrl(): string {

View File

@@ -12,7 +12,7 @@ export class Script extends BaseEntity<string> implements IScript {
) {
super(name);
if (!code) {
throw new Error(`undefined code (script: ${name})`);
throw new Error(`missing code (script: ${name})`);
}
validateLevel(level);
}

View File

@@ -6,7 +6,7 @@ export class ScriptCode implements IScriptCode {
public readonly revert: string,
syntax: ILanguageSyntax,
) {
if (!syntax) { throw new Error('undefined syntax'); }
if (!syntax) { throw new Error('missing syntax'); }
validateCode(execute, syntax);
validateRevertCode(revert, execute, syntax);
}
@@ -33,7 +33,7 @@ function validateRevertCode(revertCode: string, execute: string, syntax: ILangua
function validateCode(code: string, syntax: ILanguageSyntax): void {
if (!code || code.length === 0) {
throw new Error('code is empty or undefined');
throw new Error('missing code');
}
ensureNoEmptyLines(code);
ensureCodeHasUniqueLines(code, syntax);

View File

@@ -28,6 +28,6 @@ function findExtension(language: ScriptingLanguage): string {
function validateCode(code: string, name: string) {
if (!code) {
throw new Error(`undefined ${name}`);
throw new Error(`missing ${name}`);
}
}

24
src/domain/Version.ts Normal file
View File

@@ -0,0 +1,24 @@
export class Version {
public readonly major: number;
public readonly minor: number;
public readonly patch: number;
public constructor(semanticVersion: string) {
if (!semanticVersion) {
throw new Error('empty version');
}
if (!semanticVersion.match(/^\d+\.\d+\.\d+$/g)) {
throw new Error(`invalid version: ${semanticVersion}`);
}
const [major, minor, patch] = semanticVersion.split('.');
this.major = parseInt(major, 10);
this.minor = parseInt(minor, 10);
this.patch = parseInt(patch, 10);
}
public toString(): string {
return `${this.major}.${this.minor}.${this.patch}`;
}
}

View File

@@ -34,7 +34,7 @@ function getExecuteCommand(scriptPath: string, environment: Environment): string
case OperatingSystem.Windows:
return scriptPath;
default:
throw Error('undefined os');
throw Error(`unsupported os: ${OperatingSystem[environment.os]}`);
}
}

View File

@@ -27,7 +27,7 @@ implements IRepository<TKey, TEntity> {
public addItem(item: TEntity): void {
if (!item) {
throw new Error('item is null or undefined');
throw new Error('missing item');
}
if (this.exists(item.id)) {
throw new Error(`Cannot add (id: ${item.id}) as it is already exists`);
@@ -37,7 +37,7 @@ implements IRepository<TKey, TEntity> {
public addOrUpdateItem(item: TEntity): void {
if (!item) {
throw new Error('item is null or undefined');
throw new Error('missing item');
}
if (this.exists(item.id)) {
this.removeItem(item.id);

View File

@@ -14,7 +14,7 @@ export enum SelectionType {
export class SelectionTypeHandler {
constructor(private readonly state: ICategoryCollectionState) {
if (!state) { throw new Error('undefined state'); }
if (!state) { throw new Error('missing state'); }
}
public selectType(type: SelectionType) {

View File

@@ -67,7 +67,7 @@ export default class SelectableTree extends Vue { // Stateless to make it easier
@Watch('initialNodes', { immediate: true })
public async updateNodes(nodes: readonly INode[]) {
if (!nodes) {
throw new Error('undefined initial nodes');
throw new Error('missing initial nodes');
}
const initialNodes = nodes.map((node) => toNewLiquorTreeNode(node));
if (this.selectedNodeIds) {

View File

@@ -38,10 +38,10 @@ class Throttler implements IThrottler {
private readonly waitInMs: number,
private readonly callback: CallbackType,
) {
if (!timer) { throw new Error('undefined timer'); }
if (!waitInMs) { throw new Error('no delay to throttle'); }
if (!timer) { throw new Error('missing timer'); }
if (!waitInMs) { throw new Error('missing delay'); }
if (waitInMs < 0) { throw new Error('negative delay'); }
if (!callback) { throw new Error('undefined callback'); }
if (!callback) { throw new Error('missing callback'); }
}
public invoke(...args: unknown[]): void {

View File

@@ -77,7 +77,7 @@ export default class TheFooter extends Vue {
private initialize(app: IApplication) {
const { info } = app;
this.version = info.version;
this.version = info.version.toString();
this.homepageUrl = info.homepage;
this.repositoryUrl = info.repositoryWebUrl;
this.releaseUrl = info.releaseUrl;

View File

@@ -6,6 +6,8 @@ import log from 'electron-log';
import fetch from 'cross-fetch';
import { ProjectInformation } from '@/domain/ProjectInformation';
import { OperatingSystem } from '@/domain/OperatingSystem';
import { Version } from '@/domain/Version';
import { parseProjectInformation } from '@/application/Parser/ProjectInformationParser';
import { UpdateProgressBar } from './UpdateProgressBar';
export function requiresManualUpdate(): boolean {
@@ -17,12 +19,7 @@ export async function handleManualUpdate(info: UpdateInfo) {
if (result === ManualDownloadDialogResult.NoAction) {
return;
}
const project = new ProjectInformation(
process.env.VUE_APP_NAME,
info.version,
process.env.VUE_APP_REPOSITORY_URL,
process.env.VUE_APP_HOMEPAGE_URL,
);
const project = getTargetProject(info.version);
if (result === ManualDownloadDialogResult.VisitReleasesPage) {
await shell.openExternal(project.releaseUrl);
} else if (result === ManualDownloadDialogResult.UpdateNow) {
@@ -30,6 +27,17 @@ export async function handleManualUpdate(info: UpdateInfo) {
}
}
function getTargetProject(targetVersion: string) {
const existingProject = parseProjectInformation(process.env);
const targetProject = new ProjectInformation(
existingProject.name,
new Version(targetVersion),
existingProject.repositoryUrl,
existingProject.homepage,
);
return targetProject;
}
enum ManualDownloadDialogResult {
NoAction = 0,
UpdateNow = 1,

View File

@@ -14,7 +14,7 @@ import { setupAutoUpdater } from './Update/Updater';
const isDevelopment = process.env.NODE_ENV !== 'production';
// Path of static assets, magic variable populated by electron
// eslint-disable-next-line no-underscore-dangle
// eslint-disable-next-line @typescript-eslint/naming-convention, no-underscore-dangle
declare const __static: string; // https://github.com/electron-userland/electron-webpack/issues/172
// Keep a global reference of the window object, if you don't, the window will

View File

@@ -1,25 +1,28 @@
import 'mocha';
import { expect } from 'chai';
import { ApplicationFactory, ApplicationGetter } from '@/application/ApplicationFactory';
import { ApplicationStub } from '@tests/unit/stubs/ApplicationStub';
import { ApplicationFactory, ApplicationGetterType } from '@/application/ApplicationFactory';
import { ApplicationStub } from '@tests/unit/shared/Stubs/ApplicationStub';
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
describe('ApplicationFactory', () => {
describe('ctor', () => {
it('throws if getter is undefined', () => {
// arrange
const expectedError = 'undefined getter';
const getter = undefined;
// act
const act = () => new SystemUnderTest(getter);
// assert
expect(act).to.throw(expectedError);
describe('throws if getter is absent', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const expectedError = 'missing getter';
const getter: ApplicationGetterType = absentValue;
// act
const act = () => new SystemUnderTest(getter);
// assert
expect(act).to.throw(expectedError);
});
});
});
describe('getApp', () => {
it('returns result from the getter', async () => {
// arrange
const expected = new ApplicationStub();
const getter: ApplicationGetter = () => expected;
const getter: ApplicationGetterType = () => expected;
const sut = new SystemUnderTest(getter);
// act
const actual = await Promise.all([
@@ -35,7 +38,7 @@ describe('ApplicationFactory', () => {
// arrange
let totalExecution = 0;
const expected = new ApplicationStub();
const getter: ApplicationGetter = () => {
const getter: ApplicationGetterType = () => {
totalExecution++;
return expected;
};
@@ -54,7 +57,7 @@ describe('ApplicationFactory', () => {
});
class SystemUnderTest extends ApplicationFactory {
public constructor(costlyGetter: ApplicationGetter) {
public constructor(costlyGetter: ApplicationGetterType) {
super(costlyGetter);
}
}

View File

@@ -1,20 +1,35 @@
import 'mocha';
import { expect } from 'chai';
import { scrambledEqual, sequenceEqual } from '@/application/Common/Array';
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
import { ComparerTestScenario } from './Array.ComparerTestScenario';
describe('Array', () => {
describe('scrambledEqual', () => {
describe('throws if arguments are undefined', () => {
it('first argument is undefined', () => {
const expectedError = 'undefined first array';
const act = () => scrambledEqual(undefined, []);
expect(act).to.throw(expectedError);
describe('throws if arguments are absent', () => {
describe('first argument is absent', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const expectedError = 'missing first array';
const firstArray = absentValue;
const secondArray = [];
// act
const act = () => scrambledEqual(firstArray, secondArray);
// assert
expect(act).to.throw(expectedError);
});
});
it('second arguments is undefined', () => {
const expectedError = 'undefined second array';
const act = () => scrambledEqual([], undefined);
expect(act).to.throw(expectedError);
describe('second argument is absent', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const expectedError = 'missing second array';
const firstArray = [];
const secondArray = absentValue;
// act
const act = () => scrambledEqual(firstArray, secondArray);
// assert
expect(act).to.throw(expectedError);
});
});
});
describe('returns as expected', () => {
@@ -35,16 +50,30 @@ describe('Array', () => {
});
});
describe('sequenceEqual', () => {
describe('throws if arguments are undefined', () => {
it('first argument is undefined', () => {
const expectedError = 'undefined first array';
const act = () => sequenceEqual(undefined, []);
expect(act).to.throw(expectedError);
describe('throws if arguments are absent', () => {
describe('first argument is absent', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const expectedError = 'missing first array';
const firstArray = absentValue;
const secondArray = [];
// act
const act = () => sequenceEqual(firstArray, secondArray);
// assert
expect(act).to.throw(expectedError);
});
});
it('second arguments is undefined', () => {
const expectedError = 'undefined second array';
const act = () => sequenceEqual([], undefined);
expect(act).to.throw(expectedError);
describe('second argument is absent', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const expectedError = 'missing second array';
const firstArray = [];
const secondArray = absentValue;
// act
const act = () => sequenceEqual(firstArray, secondArray);
// assert
expect(act).to.throw(expectedError);
});
});
});
describe('returns as expected', () => {

View File

@@ -4,6 +4,7 @@ import {
getEnumNames, getEnumValues, createEnumParser, assertInRange,
} from '@/application/Common/Enum';
import { scrambledEqual } from '@/application/Common/Array';
import { AbsentStringTestCases } from '@tests/unit/shared/TestCases/AbsentTests';
import { EnumRangeTestRunner } from './EnumRangeTestRunner';
describe('Enum', () => {
@@ -37,16 +38,11 @@ describe('Enum', () => {
// arrange
const enumName = 'ParsableEnum';
const testCases = [
{
name: 'undefined',
value: undefined,
expectedError: `undefined ${enumName}`,
},
{
name: 'empty',
value: '',
expectedError: `undefined ${enumName}`,
},
...AbsentStringTestCases.map((test) => ({
name: test.valueName,
value: test.absentValue,
expectedError: `missing ${enumName}`,
})),
{
name: 'out of range',
value: 'value3',
@@ -105,7 +101,7 @@ describe('Enum', () => {
// assert
new EnumRangeTestRunner(act)
.testOutOfRangeThrows()
.testUndefinedValueThrows()
.testAbsentValueThrows()
.testValidValueDoesNotThrow(validValue);
});
});

View File

@@ -1,6 +1,7 @@
import 'mocha';
import { expect } from 'chai';
import { EnumType } from '@/application/Common/Enum';
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
export class EnumRangeTestRunner<TEnumValue extends EnumType> {
constructor(private readonly runner: (value: TEnumValue) => void) {
@@ -19,15 +20,17 @@ export class EnumRangeTestRunner<TEnumValue extends EnumType> {
return this;
}
public testUndefinedValueThrows() {
it('throws when value is undefined', () => {
// arrange
const value = undefined;
const expectedError = 'undefined enum value';
// act
const act = () => this.runner(value);
// assert
expect(act).to.throw(expectedError);
public testAbsentValueThrows() {
describe('throws when value is absent', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const value = absentValue;
const expectedError = 'absent enum value';
// act
const act = () => this.runner(value);
// assert
expect(act).to.throw(expectedError);
});
});
return this;
}
@@ -45,7 +48,7 @@ export class EnumRangeTestRunner<TEnumValue extends EnumType> {
}
public testValidValueDoesNotThrow(validValue: TEnumValue) {
it('throws when value is undefined', () => {
it('does not throw with valid value', () => {
// arrange
const value = validValue;
// act

View File

@@ -3,6 +3,7 @@ import { expect } from 'chai';
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
import { ScriptingLanguageFactory } from '@/application/Common/ScriptingLanguage/ScriptingLanguageFactory';
import { EnumRangeTestRunner } from '@tests/unit/application/Common/EnumRangeTestRunner';
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
import { ScriptingLanguageFactoryTestRunner } from './ScriptingLanguageFactoryTestRunner';
class ScriptingLanguageConcrete extends ScriptingLanguageFactory<number> {
@@ -16,32 +17,34 @@ describe('ScriptingLanguageFactory', () => {
describe('validates language', () => {
// arrange
const validValue = ScriptingLanguage.batchfile;
const getter = () => undefined;
const getter = () => 1;
const sut = new ScriptingLanguageConcrete();
// act
const act = (language: ScriptingLanguage) => sut.registerGetter(language, getter);
// assert
new EnumRangeTestRunner(act)
.testOutOfRangeThrows()
.testUndefinedValueThrows()
.testAbsentValueThrows()
.testValidValueDoesNotThrow(validValue);
});
it('throw when getter is undefined', () => {
// arrange
const expectedError = 'undefined getter';
const language = ScriptingLanguage.batchfile;
const getter = undefined;
const sut = new ScriptingLanguageConcrete();
// act
const act = () => sut.registerGetter(language, getter);
// assert
expect(act).to.throw(expectedError);
describe('describe when getter is absent', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const expectedError = 'missing getter';
const language = ScriptingLanguage.batchfile;
const getter = absentValue;
const sut = new ScriptingLanguageConcrete();
// act
const act = () => sut.registerGetter(language, getter);
// assert
expect(act).to.throw(expectedError);
});
});
it('throw when language is already registered', () => {
// arrange
const language = ScriptingLanguage.batchfile;
const expectedError = `${ScriptingLanguage[language]} is already registered`;
const getter = () => undefined;
const getter = () => 1;
const sut = new ScriptingLanguageConcrete();
// act
sut.registerGetter(language, getter);
@@ -51,9 +54,12 @@ describe('ScriptingLanguageFactory', () => {
});
});
describe('create', () => {
// arrange
const sut = new ScriptingLanguageConcrete();
sut.registerGetter(ScriptingLanguage.batchfile, () => undefined);
const runner = new ScriptingLanguageFactoryTestRunner();
// act
sut.registerGetter(ScriptingLanguage.batchfile, () => 1);
// assert
runner.testCreateMethod(sut);
});
});

View File

@@ -13,7 +13,7 @@ export class ScriptingLanguageFactoryTestRunner<T> {
}
public testCreateMethod(sut: IScriptingLanguageFactory<T>) {
if (!sut) { throw new Error('undefined sut'); }
if (!sut) { throw new Error('missing sut'); }
testLanguageValidation(sut);
testExpectedInstanceTypes(sut, this.expectedTypes);
}
@@ -46,7 +46,7 @@ function testLanguageValidation<T>(sut: IScriptingLanguageFactory<T>) {
// assert
new EnumRangeTestRunner(act)
.testOutOfRangeThrows()
.testUndefinedValueThrows()
.testAbsentValueThrows()
.testValidValueDoesNotThrow(validValue);
});
}

View File

@@ -5,9 +5,10 @@ import { OperatingSystem } from '@/domain/OperatingSystem';
import { ICategoryCollectionState } from '@/application/Context/State/ICategoryCollectionState';
import { IApplicationContext, IApplicationContextChangedEvent } from '@/application/Context/IApplicationContext';
import { IApplication } from '@/domain/IApplication';
import { ApplicationStub } from '@tests/unit/stubs/ApplicationStub';
import { CategoryCollectionStub } from '@tests/unit/stubs/CategoryCollectionStub';
import { ApplicationStub } from '@tests/unit/shared/Stubs/ApplicationStub';
import { CategoryCollectionStub } from '@tests/unit/shared/Stubs/CategoryCollectionStub';
import { EnumRangeTestRunner } from '@tests/unit/application/Common/EnumRangeTestRunner';
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
describe('ApplicationContext', () => {
describe('changeContext', () => {
@@ -125,18 +126,33 @@ describe('ApplicationContext', () => {
expect(duplicates.length).to.be.equal(0);
});
});
describe('throws with invalid os', () => {
new EnumRangeTestRunner((os: OperatingSystem) => {
// arrange
const sut = new ObservableApplicationContextFactory()
.construct();
// act
sut.changeContext(os);
})
// assert
.testOutOfRangeThrows()
.testAbsentValueThrows()
.testInvalidValueThrows(OperatingSystem.Android, 'os "Android" is not defined in application');
});
});
describe('ctor', () => {
describe('app', () => {
it('throw when app is undefined', () => {
// arrange
const expectedError = 'undefined app';
const app = undefined;
const os = OperatingSystem.Windows;
// act
const act = () => new ApplicationContext(app, os);
// assert
expect(act).to.throw(expectedError);
describe('throw when app is missing', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const expectedError = 'missing app';
const app = absentValue;
const os = OperatingSystem.Windows;
// act
const act = () => new ApplicationContext(app, os);
// assert
expect(act).to.throw(expectedError);
});
});
});
describe('collection', () => {
@@ -188,7 +204,7 @@ describe('ApplicationContext', () => {
// assert
new EnumRangeTestRunner(act)
.testOutOfRangeThrows()
.testUndefinedValueThrows()
.testAbsentValueThrows()
.testInvalidValueThrows(OperatingSystem.Android, 'os "Android" is not defined in application');
});
});

View File

@@ -5,9 +5,10 @@ import { ICategoryCollection } from '@/domain/ICategoryCollection';
import { buildContext } from '@/application/Context/ApplicationContextFactory';
import { IApplicationFactory } from '@/application/IApplicationFactory';
import { IApplication } from '@/domain/IApplication';
import { EnvironmentStub } from '@tests/unit/stubs/EnvironmentStub';
import { ApplicationStub } from '@tests/unit/stubs/ApplicationStub';
import { CategoryCollectionStub } from '@tests/unit/stubs/CategoryCollectionStub';
import { EnvironmentStub } from '@tests/unit/shared/Stubs/EnvironmentStub';
import { ApplicationStub } from '@tests/unit/shared/Stubs/ApplicationStub';
import { CategoryCollectionStub } from '@tests/unit/shared/Stubs/CategoryCollectionStub';
import { expectThrowsAsync } from '@tests/unit/shared/Assertions/ExpectThrowsAsync';
describe('ApplicationContextFactory', () => {
describe('buildContext', () => {
@@ -23,6 +24,15 @@ describe('ApplicationContextFactory', () => {
// assert
expect(expected).to.equal(context.app);
});
it('throws when null', async () => {
// arrange
const expectedError = 'missing factory';
const factory = null;
// act
const act = async () => { await buildContext(factory); };
// assert
expectThrowsAsync(act, expectedError);
});
});
describe('environment', () => {
describe('sets initial OS as expected', () => {
@@ -69,6 +79,16 @@ describe('ApplicationContextFactory', () => {
expect(expectedOs).to.equal(actual, `Expected: ${OperatingSystem[expectedOs]}, actual: ${OperatingSystem[actual]}`);
});
});
it('throws when null', async () => {
// arrange
const expectedError = 'missing environment';
const factory = mockFactoryWithApp(undefined);
const environment = null;
// act
const act = async () => { await buildContext(factory, environment); };
// assert
expectThrowsAsync(act, expectedError);
});
});
});
});

View File

@@ -5,9 +5,9 @@ import { ApplicationCode } from '@/application/Context/State/Code/ApplicationCod
import { CategoryCollectionState } from '@/application/Context/State/CategoryCollectionState';
import { OperatingSystem } from '@/domain/OperatingSystem';
import { IScript } from '@/domain/IScript';
import { ScriptStub } from '@tests/unit/stubs/ScriptStub';
import { CategoryStub } from '@tests/unit/stubs/CategoryStub';
import { CategoryCollectionStub } from '@tests/unit/stubs/CategoryCollectionStub';
import { ScriptStub } from '@tests/unit/shared/Stubs/ScriptStub';
import { CategoryStub } from '@tests/unit/shared/Stubs/CategoryStub';
import { CategoryCollectionStub } from '@tests/unit/shared/Stubs/CategoryCollectionStub';
describe('CategoryCollectionState', () => {
describe('code', () => {

View File

@@ -9,10 +9,12 @@ import { CodePosition } from '@/application/Context/State/Code/Position/CodePosi
import { ICodePosition } from '@/application/Context/State/Code/Position/ICodePosition';
import { IScriptingDefinition } from '@/domain/IScriptingDefinition';
import { IUserScript } from '@/application/Context/State/Code/Generation/IUserScript';
import { ScriptingDefinitionStub } from '@tests/unit/stubs/ScriptingDefinitionStub';
import { CategoryStub } from '@tests/unit/stubs/CategoryStub';
import { ScriptStub } from '@tests/unit/stubs/ScriptStub';
import { CategoryCollectionStub } from '@tests/unit/stubs/CategoryCollectionStub';
import { ScriptingDefinitionStub } from '@tests/unit/shared/Stubs/ScriptingDefinitionStub';
import { CategoryStub } from '@tests/unit/shared/Stubs/CategoryStub';
import { ScriptStub } from '@tests/unit/shared/Stubs/ScriptStub';
import { CategoryCollectionStub } from '@tests/unit/shared/Stubs/CategoryCollectionStub';
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
import { UserSelectionStub } from '@tests/unit/shared/Stubs/UserSelectionStub';
describe('ApplicationCode', () => {
describe('ctor', () => {
@@ -46,6 +48,41 @@ describe('ApplicationCode', () => {
// assert
expect(actual).to.equal(expected.code);
});
describe('throws when userSelection is missing', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const expectedError = 'missing userSelection';
const userSelection = absentValue;
const definition = new ScriptingDefinitionStub();
// act
const act = () => new ApplicationCode(userSelection, definition);
// assert
expect(act).to.throw(expectedError);
});
});
describe('throws when scriptingDefinition is missing', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const expectedError = 'missing scriptingDefinition';
const userSelection = new UserSelectionStub([]);
const definition = absentValue;
// act
const act = () => new ApplicationCode(userSelection, definition);
// assert
expect(act).to.throw(expectedError);
});
});
it('throws when generator is missing', () => {
// arrange
const expectedError = 'missing generator';
const userSelection = new UserSelectionStub([]);
const definition = new ScriptingDefinitionStub();
const generator = null;
// act
const act = () => new ApplicationCode(userSelection, definition, generator);
// assert
expect(act).to.throw(expectedError);
});
});
describe('changed event', () => {
describe('code', () => {

View File

@@ -4,8 +4,8 @@ import { CodeChangedEvent } from '@/application/Context/State/Code/Event/CodeCha
import { SelectedScript } from '@/application/Context/State/Selection/SelectedScript';
import { ICodePosition } from '@/application/Context/State/Code/Position/ICodePosition';
import { CodePosition } from '@/application/Context/State/Code/Position/CodePosition';
import { SelectedScriptStub } from '@tests/unit/stubs/SelectedScriptStub';
import { ScriptStub } from '@tests/unit/stubs/ScriptStub';
import { SelectedScriptStub } from '@tests/unit/shared/Stubs/SelectedScriptStub';
import { ScriptStub } from '@tests/unit/shared/Stubs/ScriptStub';
describe('CodeChangedEvent', () => {
describe('ctor', () => {

View File

@@ -4,8 +4,10 @@ import { UserScriptGenerator } from '@/application/Context/State/Code/Generation
import { SelectedScript } from '@/application/Context/State/Selection/SelectedScript';
import { ICodeBuilderFactory } from '@/application/Context/State/Code/Generation/ICodeBuilderFactory';
import { ICodeBuilder } from '@/application/Context/State/Code/Generation/ICodeBuilder';
import { ScriptStub } from '@tests/unit/stubs/ScriptStub';
import { ScriptingDefinitionStub } from '@tests/unit/stubs/ScriptingDefinitionStub';
import { ScriptStub } from '@tests/unit/shared/Stubs/ScriptStub';
import { ScriptingDefinitionStub } from '@tests/unit/shared/Stubs/ScriptingDefinitionStub';
import { itEachAbsentObjectValue, itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
import { SelectedScriptStub } from '@tests/unit/shared/Stubs/SelectedScriptStub';
describe('UserScriptGenerator', () => {
describe('scriptingDefinition', () => {
@@ -18,8 +20,7 @@ describe('UserScriptGenerator', () => {
.withCode('code\nmulti-lined')
.toSelectedScript();
const definition = new ScriptingDefinitionStub()
.withStartCode(startCode)
.withEndCode(undefined);
.withStartCode(startCode);
const expectedStart = `${startCode}\n`;
// act
const code = sut.buildCode([script], definition);
@@ -27,24 +28,25 @@ describe('UserScriptGenerator', () => {
const actual = code.code;
expect(actual.startsWith(expectedStart));
});
it('is not prepended if empty', () => {
// arrange
const codeBuilderStub = new CodeBuilderStub();
const sut = new UserScriptGenerator(mockCodeBuilderFactory(codeBuilderStub));
const script = new ScriptStub('id')
.withCode('code\nmulti-lined')
.toSelectedScript();
const definition = new ScriptingDefinitionStub()
.withStartCode(undefined)
.withEndCode(undefined);
const expectedStart = codeBuilderStub
.appendFunction(script.script.name, script.script.code.execute)
.toString();
// act
const code = sut.buildCode([script], definition);
// assert
const actual = code.code;
expect(actual.startsWith(expectedStart));
describe('is not prepended if empty', () => {
itEachAbsentStringValue((absentValue) => {
// arrange
const codeBuilderStub = new CodeBuilderStub();
const sut = new UserScriptGenerator(mockCodeBuilderFactory(codeBuilderStub));
const script = new ScriptStub('id')
.withCode('code\nmulti-lined')
.toSelectedScript();
const definition = new ScriptingDefinitionStub()
.withStartCode(absentValue);
const expectedStart = codeBuilderStub
.appendFunction(script.script.name, script.script.code.execute)
.toString();
// act
const code = sut.buildCode([script], definition);
// assert
const actual = code.code;
expect(actual.startsWith(expectedStart));
});
});
});
describe('endCode', () => {
@@ -64,23 +66,38 @@ describe('UserScriptGenerator', () => {
const actual = code.code;
expect(actual.endsWith(expectedEnd));
});
it('is not appended if empty', () => {
describe('is not appended if empty', () => {
itEachAbsentStringValue((absentValue) => {
// arrange
const codeBuilderStub = new CodeBuilderStub();
const sut = new UserScriptGenerator(mockCodeBuilderFactory(codeBuilderStub));
const script = new ScriptStub('id')
.withCode('code\nmulti-lined')
.toSelectedScript();
const expectedEnd = codeBuilderStub
.appendFunction(script.script.name, script.script.code.execute)
.toString();
const definition = new ScriptingDefinitionStub()
.withEndCode(absentValue);
// act
const code = sut.buildCode([script], definition);
// assert
const actual = code.code;
expect(actual.endsWith(expectedEnd));
});
});
});
describe('throws when absent', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const codeBuilderStub = new CodeBuilderStub();
const sut = new UserScriptGenerator(mockCodeBuilderFactory(codeBuilderStub));
const script = new ScriptStub('id')
.withCode('code\nmulti-lined')
.toSelectedScript();
const expectedEnd = codeBuilderStub
.appendFunction(script.script.name, script.script.code.execute)
.toString();
const definition = new ScriptingDefinitionStub()
.withEndCode(undefined);
const expectedError = 'missing definition';
const sut = new UserScriptGenerator();
const scriptingDefinition = absentValue;
const selectedScripts = [new SelectedScriptStub('a')];
// act
const code = sut.buildCode([script], definition);
const act = () => sut.buildCode(selectedScripts, scriptingDefinition);
// assert
const actual = code.code;
expect(actual.endsWith(expectedEnd));
expect(act).to.throw(expectedError);
});
});
});
@@ -200,6 +217,21 @@ describe('UserScriptGenerator', () => {
});
});
});
describe('selectedScripts', () => {
describe('throws when absent', () => {
itEachAbsentObjectValue((absentValue) => {
// arrange
const expectedError = 'missing scripts';
const sut = new UserScriptGenerator();
const scriptingDefinition = new ScriptingDefinitionStub();
const selectedScripts = absentValue;
// act
const act = () => sut.buildCode(selectedScripts, scriptingDefinition);
// assert
expect(act).to.throw(expectedError);
});
});
});
});
function mockCodeBuilderFactory(mock: ICodeBuilder): ICodeBuilderFactory {

View File

@@ -1,8 +1,8 @@
import 'mocha';
import { expect } from 'chai';
import { FilterResult } from '@/application/Context/State/Filter/FilterResult';
import { CategoryStub } from '@tests/unit/stubs/CategoryStub';
import { ScriptStub } from '@tests/unit/stubs/ScriptStub';
import { CategoryStub } from '@tests/unit/shared/Stubs/CategoryStub';
import { ScriptStub } from '@tests/unit/shared/Stubs/ScriptStub';
describe('FilterResult', () => {
describe('hasAnyMatches', () => {

Some files were not shown because too many files have changed in this diff Show More