From 73056d26490a05c57a0971bc4d6b1c66799ef33e Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Fri, 3 Dec 2021 16:01:49 -0500 Subject: [PATCH] Code cleanup, update eslint from webapp, add ts-prune (#1884) --- .eslintrc-webapp.json | 68 ++---- package-lock.json | 350 ++++++++++++++++++++++++++++- package.json | 4 +- src/common/communication.ts | 7 - src/common/permissions.ts | 5 - src/common/tabs/TabView.ts | 2 - src/main/CriticalErrorHandler.ts | 2 +- src/main/UserActivityMonitor.ts | 2 +- src/main/appState.ts | 29 +-- src/main/autoUpdater.ts | 201 ----------------- src/main/menus/app.ts | 2 +- src/main/menus/tray.ts | 2 +- src/main/notifications/Mention.ts | 2 +- src/main/utils.ts | 7 +- src/main/views/MattermostView.ts | 3 +- src/main/views/viewManager.ts | 2 +- src/main/views/webContentEvents.ts | 4 +- src/main/windows/windowManager.ts | 25 +-- src/renderer/notificationSounds.ts | 2 +- 19 files changed, 383 insertions(+), 336 deletions(-) delete mode 100644 src/main/autoUpdater.ts diff --git a/.eslintrc-webapp.json b/.eslintrc-webapp.json index 558fd372..0ff2f5a6 100644 --- a/.eslintrc-webapp.json +++ b/.eslintrc-webapp.json @@ -2,15 +2,13 @@ "root": true, "extends": [ "plugin:mattermost/react", - "plugin:cypress/recommended", - "plugin:jquery/deprecated" + "plugin:cypress/recommended" ], "plugins": [ "babel", "mattermost", "import", "cypress", - "jquery", "no-only-tests", "@typescript-eslint" ], @@ -27,6 +25,7 @@ } }, "rules": { + "max-nested-callbacks": ["error", 10], "no-unused-expressions": 0, "babel/no-unused-expressions": 2, "eol-last": ["error", "always"], @@ -64,6 +63,11 @@ "no-only-tests/no-only-tests": ["error", {"focus": ["only", "skip"]}], "react/style-prop-object": [2, { "allow": ["Timestamp"] + }], + "no-restricted-imports": ["error", { + "paths": [ + {"name": "react-bootstrap", "importNames": ["OverlayTrigger"], "message": "Please use OverlayTrigger from '/components/overlay_trigger' instead"} + ] }] }, "overrides": [ @@ -108,6 +112,7 @@ "@typescript-eslint/no-empty-function": 0, "@typescript-eslint/prefer-interface": 0, "@typescript-eslint/explicit-function-return-type": 0, + "@typescript-eslint/explicit-module-boundary-types": 0, "@typescript-eslint/indent": [ 2, 4, @@ -126,16 +131,18 @@ } }, { - "files": ["tests/**", "**/*.test.*"], + "files": ["tests/**", "**/*.test.*", "tests/*.js"], "env": { "jest": true }, "rules": { "func-names": 0, "global-require": 0, + "max-lines": 0, "new-cap": 0, - "prefer-arrow-callback": 0, - "no-import-assign": 0 + "no-import-assign": 0, + "no-process-env": 0, + "prefer-arrow-callback": 0 } }, { @@ -144,55 +151,6 @@ "babel/no-unused-expressions": 0, "func-names": 0, "import/no-unresolved": 0, - "jquery/no-ajax": 0, - "jquery/no-ajax-events": 0, - "jquery/no-animate": 0, - "jquery/no-attr": 0, - "jquery/no-bind": 0, - "jquery/no-class": 0, - "jquery/no-clone": 0, - "jquery/no-closest": 0, - "jquery/no-css": 0, - "jquery/no-data": 0, - "jquery/no-deferred": 0, - "jquery/no-delegate": 0, - "jquery/no-each": 0, - "jquery/no-extend": 0, - "jquery/no-fade": 0, - "jquery/no-filter": 0, - "jquery/no-find": 0, - "jquery/no-global-eval": 0, - "jquery/no-grep": 0, - "jquery/no-has": 0, - "jquery/no-hide": 0, - "jquery/no-html": 0, - "jquery/no-in-array": 0, - "jquery/no-is-array": 0, - "jquery/no-is-function": 0, - "jquery/no-is": 0, - "jquery/no-load": 0, - "jquery/no-map": 0, - "jquery/no-merge": 0, - "jquery/no-param": 0, - "jquery/no-parent": 0, - "jquery/no-parents": 0, - "jquery/no-parse-html": 0, - "jquery/no-prop": 0, - "jquery/no-proxy": 0, - "jquery/no-ready": 0, - "jquery/no-serialize": 0, - "jquery/no-show": 0, - "jquery/no-size": 0, - "jquery/no-sizzle": 0, - "jquery/no-slide": 0, - "jquery/no-submit": 0, - "jquery/no-text": 0, - "jquery/no-toggle": 0, - "jquery/no-trigger": 0, - "jquery/no-trim": 0, - "jquery/no-val": 0, - "jquery/no-when": 0, - "jquery/no-wrap": 0, "max-nested-callbacks": 0, "no-process-env": 0, "no-unused-expressions": 0 diff --git a/package-lock.json b/package-lock.json index 05e5066f..8aaeaa4a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -96,6 +96,7 @@ "sass-loader": "^10.2.0", "shebang-loader": "^0.0.1", "style-loader": "^2.0.0", + "ts-prune": "^0.10.2", "typescript": "^4.3.4", "url-loader": "^1.1.2", "webpack": "^4.44.2", @@ -5860,6 +5861,131 @@ "node": ">= 6" } }, + "node_modules/@ts-morph/common": { + "version": "0.12.2", + "resolved": "https://registry.npmjs.org/@ts-morph/common/-/common-0.12.2.tgz", + "integrity": "sha512-m5KjptpIf1K0t0QL38uE+ol1n+aNn9MgRq++G3Zym1FlqfN+rThsXlp3cAgib14pIeXF7jk3UtJQOviwawFyYg==", + "dev": true, + "dependencies": { + "fast-glob": "^3.2.7", + "minimatch": "^3.0.4", + "mkdirp": "^1.0.4", + "path-browserify": "^1.0.1" + } + }, + "node_modules/@ts-morph/common/node_modules/@nodelib/fs.stat": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", + "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", + "dev": true, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@ts-morph/common/node_modules/braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "dependencies": { + "fill-range": "^7.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@ts-morph/common/node_modules/fast-glob": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.7.tgz", + "integrity": "sha512-rYGMRwip6lUMvYD3BTScMwT1HtAs2d71SMv66Vrxs0IekGZEjhM0pcMfjQPnknBt2zeCwQMEupiN02ZP4DiT1Q==", + "dev": true, + "dependencies": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.4" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@ts-morph/common/node_modules/fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@ts-morph/common/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/@ts-morph/common/node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/@ts-morph/common/node_modules/micromatch": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.4.tgz", + "integrity": "sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==", + "dev": true, + "dependencies": { + "braces": "^3.0.1", + "picomatch": "^2.2.3" + }, + "engines": { + "node": ">=8.6" + } + }, + "node_modules/@ts-morph/common/node_modules/mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "dev": true, + "bin": { + "mkdirp": "bin/cmd.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@ts-morph/common/node_modules/path-browserify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", + "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==", + "dev": true + }, + "node_modules/@ts-morph/common/node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, "node_modules/@types/auto-launch": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/@types/auto-launch/-/auto-launch-5.0.1.tgz", @@ -10494,6 +10620,21 @@ "node": ">= 4.0" } }, + "node_modules/code-block-writer": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/code-block-writer/-/code-block-writer-11.0.0.tgz", + "integrity": "sha512-GEqWvEWWsOvER+g9keO4ohFoD3ymwyCnqY3hoTr7GZipYFwEhMHJw+TtV0rfgRhNImM6QWZGO2XYjlJVyYT62w==", + "dev": true, + "dependencies": { + "tslib": "2.3.1" + } + }, + "node_modules/code-block-writer/node_modules/tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==", + "dev": true + }, "node_modules/code-point-at": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", @@ -11276,9 +11417,9 @@ "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, "node_modules/cosmiconfig": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.0.0.tgz", - "integrity": "sha512-pondGvTuVYDk++upghXJabWzL6Kxu6f26ljFw64Swq9v6sQPUL3EUlVDV56diOjpCayKihL6hVe8exIACU4XcA==", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.0.1.tgz", + "integrity": "sha512-a1YWNUV2HwGimB7dU2s1wUMurNKjpx60HxBB6xUM8Re+2s1g1IIfJvFR0/iCF+XHdE0GMTKTuLR32UQff4TEyQ==", "dev": true, "dependencies": { "@types/parse-json": "^4.0.0", @@ -29471,6 +29612,15 @@ "node": ">=0.10.0" } }, + "node_modules/true-myth": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/true-myth/-/true-myth-4.1.1.tgz", + "integrity": "sha512-rqy30BSpxPznbbTcAcci90oZ1YR4DqvKcNXNerG5gQBU2v4jk0cygheiul5J6ExIMrgDVuanv/MkGfqZbKrNNg==", + "dev": true, + "engines": { + "node": "10.* || >= 12.*" + } + }, "node_modules/truncate-utf8-bytes": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz", @@ -29495,6 +29645,16 @@ "integrity": "sha512-3IVX4nI6B5cc31/GFFE+i8ey/N2eA0CZDbo6n0yrz0zDX8ZJ8djmU1p+XRz7G3is0F3bB3pu2pAroFdAWQKU3w==", "dev": true }, + "node_modules/ts-morph": { + "version": "13.0.2", + "resolved": "https://registry.npmjs.org/ts-morph/-/ts-morph-13.0.2.tgz", + "integrity": "sha512-SjeeHaRf/mFsNeR3KTJnx39JyEOzT4e+DX28gQx5zjzEOuFs2eGrqeN2PLKs/+AibSxPmzV7RD8nJVKmFJqtLA==", + "dev": true, + "dependencies": { + "@ts-morph/common": "~0.12.2", + "code-block-writer": "^11.0.0" + } + }, "node_modules/ts-pnp": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/ts-pnp/-/ts-pnp-1.2.0.tgz", @@ -29509,6 +29669,32 @@ } } }, + "node_modules/ts-prune": { + "version": "0.10.2", + "resolved": "https://registry.npmjs.org/ts-prune/-/ts-prune-0.10.2.tgz", + "integrity": "sha512-TXc77vO1JCtt8UKurqsZsDLPHWH0NqoEvglhA/p1Fv+r9KICCTigZSSdScDOzw7UXfZ0mLBj1GnKoWR6CNs8pQ==", + "dev": true, + "dependencies": { + "commander": "^6.2.1", + "cosmiconfig": "^7.0.1", + "json5": "^2.1.3", + "lodash": "^4.17.21", + "true-myth": "^4.1.0", + "ts-morph": "^13.0.1" + }, + "bin": { + "ts-prune": "lib/index.js" + } + }, + "node_modules/ts-prune/node_modules/commander": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-6.2.1.tgz", + "integrity": "sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==", + "dev": true, + "engines": { + "node": ">= 6" + } + }, "node_modules/tsconfig-paths": { "version": "3.9.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz", @@ -36028,6 +36214,103 @@ "integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==", "dev": true }, + "@ts-morph/common": { + "version": "0.12.2", + "resolved": "https://registry.npmjs.org/@ts-morph/common/-/common-0.12.2.tgz", + "integrity": "sha512-m5KjptpIf1K0t0QL38uE+ol1n+aNn9MgRq++G3Zym1FlqfN+rThsXlp3cAgib14pIeXF7jk3UtJQOviwawFyYg==", + "dev": true, + "requires": { + "fast-glob": "^3.2.7", + "minimatch": "^3.0.4", + "mkdirp": "^1.0.4", + "path-browserify": "^1.0.1" + }, + "dependencies": { + "@nodelib/fs.stat": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", + "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", + "dev": true + }, + "braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "requires": { + "fill-range": "^7.0.1" + } + }, + "fast-glob": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.7.tgz", + "integrity": "sha512-rYGMRwip6lUMvYD3BTScMwT1HtAs2d71SMv66Vrxs0IekGZEjhM0pcMfjQPnknBt2zeCwQMEupiN02ZP4DiT1Q==", + "dev": true, + "requires": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.4" + } + }, + "fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "requires": { + "to-regex-range": "^5.0.1" + } + }, + "glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true + }, + "micromatch": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.4.tgz", + "integrity": "sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==", + "dev": true, + "requires": { + "braces": "^3.0.1", + "picomatch": "^2.2.3" + } + }, + "mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "dev": true + }, + "path-browserify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", + "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==", + "dev": true + }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "requires": { + "is-number": "^7.0.0" + } + } + } + }, "@types/auto-launch": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/@types/auto-launch/-/auto-launch-5.0.1.tgz", @@ -39852,6 +40135,23 @@ "q": "^1.1.2" } }, + "code-block-writer": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/code-block-writer/-/code-block-writer-11.0.0.tgz", + "integrity": "sha512-GEqWvEWWsOvER+g9keO4ohFoD3ymwyCnqY3hoTr7GZipYFwEhMHJw+TtV0rfgRhNImM6QWZGO2XYjlJVyYT62w==", + "dev": true, + "requires": { + "tslib": "2.3.1" + }, + "dependencies": { + "tslib": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", + "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==", + "dev": true + } + } + }, "code-point-at": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", @@ -40470,9 +40770,9 @@ "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, "cosmiconfig": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.0.0.tgz", - "integrity": "sha512-pondGvTuVYDk++upghXJabWzL6Kxu6f26ljFw64Swq9v6sQPUL3EUlVDV56diOjpCayKihL6hVe8exIACU4XcA==", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-7.0.1.tgz", + "integrity": "sha512-a1YWNUV2HwGimB7dU2s1wUMurNKjpx60HxBB6xUM8Re+2s1g1IIfJvFR0/iCF+XHdE0GMTKTuLR32UQff4TEyQ==", "dev": true, "requires": { "@types/parse-json": "^4.0.0", @@ -54950,6 +55250,12 @@ "escape-string-regexp": "^1.0.2" } }, + "true-myth": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/true-myth/-/true-myth-4.1.1.tgz", + "integrity": "sha512-rqy30BSpxPznbbTcAcci90oZ1YR4DqvKcNXNerG5gQBU2v4jk0cygheiul5J6ExIMrgDVuanv/MkGfqZbKrNNg==", + "dev": true + }, "truncate-utf8-bytes": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz", @@ -54971,12 +55277,44 @@ "integrity": "sha512-3IVX4nI6B5cc31/GFFE+i8ey/N2eA0CZDbo6n0yrz0zDX8ZJ8djmU1p+XRz7G3is0F3bB3pu2pAroFdAWQKU3w==", "dev": true }, + "ts-morph": { + "version": "13.0.2", + "resolved": "https://registry.npmjs.org/ts-morph/-/ts-morph-13.0.2.tgz", + "integrity": "sha512-SjeeHaRf/mFsNeR3KTJnx39JyEOzT4e+DX28gQx5zjzEOuFs2eGrqeN2PLKs/+AibSxPmzV7RD8nJVKmFJqtLA==", + "dev": true, + "requires": { + "@ts-morph/common": "~0.12.2", + "code-block-writer": "^11.0.0" + } + }, "ts-pnp": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/ts-pnp/-/ts-pnp-1.2.0.tgz", "integrity": "sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw==", "dev": true }, + "ts-prune": { + "version": "0.10.2", + "resolved": "https://registry.npmjs.org/ts-prune/-/ts-prune-0.10.2.tgz", + "integrity": "sha512-TXc77vO1JCtt8UKurqsZsDLPHWH0NqoEvglhA/p1Fv+r9KICCTigZSSdScDOzw7UXfZ0mLBj1GnKoWR6CNs8pQ==", + "dev": true, + "requires": { + "commander": "^6.2.1", + "cosmiconfig": "^7.0.1", + "json5": "^2.1.3", + "lodash": "^4.17.21", + "true-myth": "^4.1.0", + "ts-morph": "^13.0.1" + }, + "dependencies": { + "commander": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-6.2.1.tgz", + "integrity": "sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==", + "dev": true + } + } + }, "tsconfig-paths": { "version": "3.9.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz", diff --git a/package.json b/package.json index f6cf28b3..3278264f 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,8 @@ "check-build-config": "npm-run-all check-build-config:build check-build-config:run", "check-build-config:build": "babel ./src/common/config/buildConfig.ts -o ./dist/buildConfig.js", "check-build-config:run": "node -r @babel/register scripts/check_build_config.js", - "check-types": "tsc" + "check-types": "tsc", + "prune": "ts-prune" }, "jest": { "clearMocks": true, @@ -137,6 +138,7 @@ "sass-loader": "^10.2.0", "shebang-loader": "^0.0.1", "style-loader": "^2.0.0", + "ts-prune": "^0.10.2", "typescript": "^4.3.4", "url-loader": "^1.1.2", "webpack": "^4.44.2", diff --git a/src/common/communication.ts b/src/common/communication.ts index a990298d..45c25e9e 100644 --- a/src/common/communication.ts +++ b/src/common/communication.ts @@ -7,11 +7,7 @@ export const CLOSE_TAB = 'close-tab'; export const OPEN_TAB = 'open-tab'; export const SET_ACTIVE_VIEW = 'set-active-view'; export const UPDATE_LAST_ACTIVE = 'update-last-active'; -export const MARK_READ = 'mark-read'; export const FOCUS_BROWSERVIEW = 'focus-browserview'; -export const ZOOM = 'zoom'; -export const UNDO = 'undo'; -export const REDO = 'redo'; export const HISTORY = 'history'; export const QUIT = 'quit'; @@ -34,8 +30,6 @@ export const LOAD_FAILED = 'load_fail'; export const MAXIMIZE_CHANGE = 'maximized_change'; -export const OPEN_EXTERNAL = 'open_external'; - export const DOUBLE_CLICK_ON_WINDOW = 'double_click'; export const SHOW_NEW_SERVER_MODAL = 'show_new_server_modal'; @@ -83,7 +77,6 @@ export const TOGGLE_LOADING_SCREEN_VISIBILITY = 'toggle-loading-screen-visibilit export const SELECT_NEXT_TAB = 'select-next-tab'; export const SELECT_PREVIOUS_TAB = 'select-previous-tab'; -export const ADD_SERVER = 'add-server'; export const FOCUS_THREE_DOT_MENU = 'focus-three-dot-menu'; export const LOADSCREEN_END = 'loadscreen-end'; diff --git a/src/common/permissions.ts b/src/common/permissions.ts index 3eb5ffea..c95a2ec0 100644 --- a/src/common/permissions.ts +++ b/src/common/permissions.ts @@ -1,11 +1,6 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -// channel types for managing permissions -export const REQUEST_PERMISSION_CHANNEL = 'request-permission'; -export const GRANT_PERMISSION_CHANNEL = 'grant-permission'; -export const DENY_PERMISSION_CHANNEL = 'deny-permission'; - // Permission types that can be requested export const BASIC_AUTH_PERMISSION = 'canBasicAuth'; diff --git a/src/common/tabs/TabView.ts b/src/common/tabs/TabView.ts index 58fc7ce2..33ff0b4d 100644 --- a/src/common/tabs/TabView.ts +++ b/src/common/tabs/TabView.ts @@ -44,7 +44,6 @@ export function getDefaultTeamWithTabsFromTeam(team: Team) { }; } -// TODO: Might need to move this out export function getServerView(srv: MattermostServer, tab: Tab) { switch (tab.name) { case TAB_MESSAGING: @@ -76,6 +75,5 @@ export function getTabDisplayName(tabType: TabType) { } export function canCloseTab(tabType: TabType) { - // TODO: maybe rework to make the property belong to the class somehow return tabType !== TAB_MESSAGING; } diff --git a/src/main/CriticalErrorHandler.ts b/src/main/CriticalErrorHandler.ts index 44f3eba5..1a372038 100644 --- a/src/main/CriticalErrorHandler.ts +++ b/src/main/CriticalErrorHandler.ts @@ -25,7 +25,7 @@ function createErrorReport(err: Error) { } function openDetachedExternal(url: string) { - const spawnOption = {detached: true, stdio: 'ignore' as any}; + const spawnOption = {detached: true, stdio: 'ignore' as const}; switch (process.platform) { case 'win32': return spawn('cmd', ['/C', 'start', url], spawnOption); diff --git a/src/main/UserActivityMonitor.ts b/src/main/UserActivityMonitor.ts index 24fcfd3f..2bfcda60 100644 --- a/src/main/UserActivityMonitor.ts +++ b/src/main/UserActivityMonitor.ts @@ -67,7 +67,7 @@ export default class UserActivityMonitor extends EventEmitter { this.config = Object.assign({}, this.config, config); - // TODO: Node typings don't map Timeout to number, but then clearInterval requires a number? + // Node typings don't map Timeout to number, but then clearInterval requires a number? this.systemIdleTimeIntervalID = setInterval(() => { try { this.updateIdleTime(electron.powerMonitor.getSystemIdleTime()); diff --git a/src/main/appState.ts b/src/main/appState.ts index b7a76708..8432f216 100644 --- a/src/main/appState.ts +++ b/src/main/appState.ts @@ -36,7 +36,7 @@ const emitDropdown = (expired?: Map, mentions?: Map { +const emitStatus = () => { const expired = anyExpired(); const mentions = totalMentions(); const unreads = anyUnreads(); @@ -65,28 +65,19 @@ export const updateBadge = () => { emitBadge(expired, mentions, unreads); }; -export const getUnreads = (serverName: string) => { +const getUnreads = (serverName: string) => { return status.unreads.get(serverName) || false; }; -export const getMentions = (serverName: string) => { +const getMentions = (serverName: string) => { return status.mentions.get(serverName) || 0; // this might be undefined as a way to tell that we don't know as it might need to login still. }; -export const getIsExpired = (serverName: string) => { +const getIsExpired = (serverName: string) => { return status.expired.get(serverName) || false; }; -export const anyMentions = () => { - for (const v of status.mentions.values()) { - if (v > 0) { - return v; - } - } - return false; -}; - -export const totalMentions = () => { +const totalMentions = () => { let total = 0; for (const v of status.mentions.values()) { total += v; @@ -94,7 +85,7 @@ export const totalMentions = () => { return total; }; -export const anyUnreads = () => { +const anyUnreads = () => { for (const v of status.unreads.values()) { if (v) { return v; @@ -103,7 +94,7 @@ export const anyUnreads = () => { return false; }; -export const anyExpired = () => { +const anyExpired = () => { for (const v of status.expired.values()) { if (v) { return v; @@ -113,11 +104,9 @@ export const anyExpired = () => { }; // add any other event emitter methods if needed -export const on = (event: string, listener: (...args: any[]) => void) => { - status.emitter.on(event, listener); -}; +export const on = status.emitter.on; -export const setSessionExpired = (serverName: string, expired: boolean) => { +const setSessionExpired = (serverName: string, expired: boolean) => { const isExpired = Boolean(expired); const old = status.expired.get(serverName); status.expired.set(serverName, isExpired); diff --git a/src/main/autoUpdater.ts b/src/main/autoUpdater.ts deleted file mode 100644 index cc35108c..00000000 --- a/src/main/autoUpdater.ts +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright (c) 2015-2016 Yuya Ochiai -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See LICENSE.txt for license information. - -// TODO: This needs to be rebuilt anyways, skipping TS migration for now -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -//@ts-nocheck - -import path from 'path'; - -import {app, BrowserWindow, BrowserWindowConstructorOptions, dialog, ipcMain, IpcMainEvent, shell} from 'electron'; - -import log from 'electron-log'; -import {autoUpdater, CancellationToken} from 'electron-updater'; -import semver from 'semver'; - -// eslint-disable-next-line no-magic-numbers -const UPDATER_INTERVAL_IN_MS = 48 * 60 * 60 * 1000; // 48 hours - -autoUpdater.log = log; -autoUpdater.log.transports.file.level = 'info'; - -let updaterModal = null; - -function createEventListener(win: BrowserWindow, eventName: string) { - return (event: IpcMainEvent) => { - if (event.sender === win.webContents) { - win.emit(eventName); - } - }; -} - -function createUpdaterModal(parentWindow: BrowserWindow, options: {linuxAppIcon: string; notifyOnly: boolean}) { - const windowWidth = 480; - const windowHeight = 280; - const windowOptions: BrowserWindowConstructorOptions = { - title: `${app.name} Updater`, - parent: parentWindow, - modal: true, - maximizable: false, - show: false, - width: windowWidth, - height: windowHeight, - resizable: false, - autoHideMenuBar: true, - backgroundColor: '#fff', // prevents blurry text: https://electronjs.org/docs/faq#the-font-looks-blurry-what-is-this-and-what-can-i-do - }; - if (process.platform === 'linux') { - windowOptions.icon = options.linuxAppIcon; - } - - const modal = new BrowserWindow(windowOptions); - modal.once('ready-to-show', () => { - modal.show(); - }); - let updaterURL = (global.isDev ? 'http://localhost:8080' : `file://${app.getAppPath()}`) + '/browser/updater.html'; - - if (options.notifyOnly) { - updaterURL += '?notifyOnly=true'; - } - modal.loadURL(updaterURL); - - for (const eventName of ['click-release-notes', 'click-skip', 'click-remind', 'click-install', 'click-download', 'click-cancel']) { - const listener = createEventListener(modal, eventName); - ipcMain.on(eventName, listener); - modal.on('closed', () => { - ipcMain.removeListener(eventName, listener); - }); - } - - return modal; -} - -function isUpdateApplicable(now: Date, skippedVersion, updateInfo) { - const releaseTime = new Date(updateInfo.releaseDate).getTime(); - - // 48 hours after a new version is added to releases.mattermost.com, user receives a “New update is available” dialog - if (now.getTime() - releaseTime < UPDATER_INTERVAL_IN_MS) { - return false; - } - - // If a version was skipped, compare version. - if (skippedVersion) { - return semver.gt(updateInfo.version, skippedVersion); - } - - return true; -} - -function downloadAndInstall(cancellationToken?: CancellationToken) { - autoUpdater.on('update-downloaded', () => { - global.willAppQuit = true; - autoUpdater.quitAndInstall(); - }); - autoUpdater.downloadUpdate(cancellationToken); -} - -function initialize(appState, mainWindow, notifyOnly = false) { - autoUpdater.autoDownload = false; // To prevent upgrading on quit - const assetsDir = path.resolve(app.getAppPath(), 'assets'); - autoUpdater.on('error', (err) => { - log.error('Error in autoUpdater:', err.message); - }).on('update-available', (info) => { - let cancellationToken = null; - if (isUpdateApplicable(new Date(), appState.skippedVersion, info)) { - updaterModal = createUpdaterModal(mainWindow, { - linuxAppIcon: path.join(assetsDir, 'appicon.png'), - notifyOnly, - }); - updaterModal.on('closed', () => { - updaterModal = null; - }); - updaterModal.on('click-skip', () => { - appState.skippedVersion = info.version; - updaterModal.close(); - }).on('click-remind', () => { - appState.updateCheckedDate = new Date(); - setTimeout(() => { // eslint-disable-line max-nested-callbacks - autoUpdater.checkForUpdates(); - }, UPDATER_INTERVAL_IN_MS); - updaterModal.close(); - }).on('click-install', () => { - updaterModal.webContents.send('start-download'); - autoUpdater.signals.progress((data) => { // eslint-disable-line max-nested-callbacks - updaterModal.send('progress', Math.floor(data.percent)); - log.info('progress:', data); - }); - cancellationToken = new CancellationToken(); - downloadAndInstall(cancellationToken); - }).on('click-download', () => { - shell.openExternal('https://about.mattermost.com/download/#mattermostApps'); - }).on('click-release-notes', () => { - shell.openExternal(`https://github.com/mattermost/desktop/releases/v${info.version}`); - }).on('click-cancel', () => { - cancellationToken.cancel(); - updaterModal.close(); - }); - updaterModal.focus(); - } else if (autoUpdater.isManual) { - autoUpdater.emit('update-not-available'); - } - }).on('update-not-available', () => { - if (autoUpdater.isManual) { - dialog.showMessageBox(mainWindow, { - type: 'info', - buttons: ['Close'], - title: 'Your Desktop App is up to date', - message: 'You have the latest version of the Mattermost Desktop App.', - }); - } - setTimeout(() => { - autoUpdater.checkForUpdates(); - }, UPDATER_INTERVAL_IN_MS); - }); -} - -function shouldCheckForUpdatesOnStart(updateCheckedDate: Date) { - if (updateCheckedDate) { - if (Date.now() - updateCheckedDate.getTime() < UPDATER_INTERVAL_IN_MS) { - return false; - } - } - return true; -} - -function checkForUpdates(isManual = false) { - autoUpdater.isManual = isManual; - if (!updaterModal) { - autoUpdater.checkForUpdates(); - } -} - -class AutoUpdaterConfig { - data: {notifyOnly?: boolean}; - - constructor() { - this.data = {}; - } - - isNotifyOnly() { - if (process.platform === 'win32') { - return true; - } - if (this.data.notifyOnly === true) { - return true; - } - return false; - } -} - -function loadConfig() { - return new AutoUpdaterConfig(); -} - -export default { - UPDATER_INTERVAL_IN_MS, - checkForUpdates, - shouldCheckForUpdatesOnStart, - initialize, - loadConfig, -}; diff --git a/src/main/menus/app.ts b/src/main/menus/app.ts index 70e570e9..6a1038aa 100644 --- a/src/main/menus/app.ts +++ b/src/main/menus/app.ts @@ -274,6 +274,6 @@ export function createTemplate(config: Config) { } export function createMenu(config: Config) { - // TODO: Electron is enforcing certain variables that it doesn't need + // Electron is enforcing certain variables that it doesn't need return Menu.buildFromTemplate(createTemplate(config) as Array); } diff --git a/src/main/menus/tray.ts b/src/main/menus/tray.ts index 6fb47575..6ecd1524 100644 --- a/src/main/menus/tray.ts +++ b/src/main/menus/tray.ts @@ -35,6 +35,6 @@ export function createTemplate(config: CombinedConfig) { } export function createMenu(config: CombinedConfig) { - // TODO: Electron is enforcing certain variables that it doesn't need + // Electron is enforcing certain variables that it doesn't need return Menu.buildFromTemplate(createTemplate(config) as Array); } diff --git a/src/main/notifications/Mention.ts b/src/main/notifications/Mention.ts index 1659e08b..f8636ef2 100644 --- a/src/main/notifications/Mention.ts +++ b/src/main/notifications/Mention.ts @@ -19,7 +19,7 @@ const defaultOptions = { icon: appIconURL, urgency: 'normal' as Notification['urgency'], }; -export const DEFAULT_WIN7 = 'Ding'; +const DEFAULT_WIN7 = 'Ding'; export class Mention extends Notification { customSound: string; diff --git a/src/main/utils.ts b/src/main/utils.ts index 487793b5..af13b062 100644 --- a/src/main/utils.ts +++ b/src/main/utils.ts @@ -37,11 +37,6 @@ export function getAdjustedWindowBoundaries(width: number, height: number, hasBa } export function getLocalURLString(urlPath: string, query?: Map, isMain?: boolean) { - const localURL = getLocalURL(urlPath, query, isMain); - return localURL.href; -} - -export function getLocalURL(urlPath: string, query?: Map, isMain?: boolean) { let pathname; const processPath = isMain ? '' : '/renderer'; const mode = Utils.runMode(); @@ -61,7 +56,7 @@ export function getLocalURL(urlPath: string, query?: Map, isMain }); } - return localUrl; + return localUrl.href; } export function getLocalPreload(file: string) { diff --git a/src/main/views/MattermostView.ts b/src/main/views/MattermostView.ts index 5effebcd..cab693dc 100644 --- a/src/main/views/MattermostView.ts +++ b/src/main/views/MattermostView.ts @@ -165,7 +165,7 @@ export class MattermostView extends EventEmitter { }; } - loadRetry = (loadURL: string, err: any) => { + loadRetry = (loadURL: string, err: Error) => { this.retryLoad = setTimeout(this.retry(loadURL), RELOAD_INTERVAL); WindowManager.sendToRenderer(LOAD_RETRY, this.tab.name, Date.now() + RELOAD_INTERVAL, err.toString(), loadURL.toString()); log.info(`[${Util.shorten(this.tab.name)}] failed loading ${loadURL}: ${err}, retrying in ${RELOAD_INTERVAL / SECOND} seconds`); @@ -211,7 +211,6 @@ export class MattermostView extends EventEmitter { hide = () => this.show(false); setBounds = (boundaries: Electron.Rectangle) => { - // todo: review this, as it might not work properly with devtools/minimizing/resizing this.view.setBounds(boundaries); } diff --git a/src/main/views/viewManager.ts b/src/main/views/viewManager.ts index a532a520..2ae3e800 100644 --- a/src/main/views/viewManager.ts +++ b/src/main/views/viewManager.ts @@ -446,7 +446,7 @@ export class ViewManager { } }; - sendToAllViews = (channel: string, ...args: any[]) => { + sendToAllViews = (channel: string, ...args: unknown[]) => { this.views.forEach((view) => view.view.webContents.send(channel, ...args)); } } diff --git a/src/main/views/webContentEvents.ts b/src/main/views/webContentEvents.ts index 06c7f208..2c601120 100644 --- a/src/main/views/webContentEvents.ts +++ b/src/main/views/webContentEvents.ts @@ -126,7 +126,7 @@ const generateNewWindowListener = (getServersFunction: () => TeamWithTabs[], spe } // Public download links case - // TODO: We might be handling different types differently in the future, for now + // We might be handling different types differently in the future, for now // we are going to mimic the browser and just pop a new browser window for public links if (parsedURL.pathname.match(/^(\/api\/v[3-4]\/public)*\/files\//)) { shell.openExternal(details.url); @@ -218,7 +218,7 @@ export const addWebContentsEventListeners = (mmview: MattermostView, getServersF } const willNavigate = generateWillNavigate(getServersFunction); - contents.on('will-navigate', willNavigate as (e: Event, u: string) => void); // TODO: Electron types don't include sender for some reason + contents.on('will-navigate', willNavigate as (e: Event, u: string) => void); // Electron types don't include sender for some reason // handle custom login requests (oath, saml): // 1. are we navigating to a supported local custom login path from the `/login` page? diff --git a/src/main/windows/windowManager.ts b/src/main/windows/windowManager.ts index 5b417644..de86a709 100644 --- a/src/main/windows/windowManager.ts +++ b/src/main/windows/windowManager.ts @@ -150,8 +150,6 @@ export function getMainWindow(ensureCreated?: boolean) { return status.mainWindow; } -export const on = status.mainWindow?.on; - function handleMaximizeMainWindow() { sendToRenderer(MAXIMIZE_CHANGE, true); } @@ -204,15 +202,6 @@ export function sendToRenderer(channel: string, ...args: any[]) { } } -export function sendToAll(channel: string, ...args: any[]) { - sendToRenderer(channel, ...args); - if (status.settingsWindow) { - status.settingsWindow.webContents.send(channel, ...args); - } - - // TODO: should we include popups? -} - export function sendToMattermostViews(channel: string, ...args: any[]) { if (status.viewManager) { status.viewManager.sendToAllViews(channel, ...args); @@ -321,10 +310,6 @@ export async function setOverlayIcon(badgeText: string | undefined, description: } } -export function isMainWindow(window: BrowserWindow) { - return status.mainWindow && status.mainWindow === window; -} - export function handleDoubleClick(e: IpcMainEvent, windowType?: string) { let action = 'Maximize'; if (process.platform === 'darwin') { @@ -446,11 +431,6 @@ export function updateLoadingScreenDarkMode(darkMode: boolean) { } } -export function getViewNameByWebContentsId(webContentsId: number) { - const view = status.viewManager?.findViewByWebContent(webContentsId); - return view?.name; -} - export function getServerNameByWebContentsId(webContentsId: number) { const view = status.viewManager?.findViewByWebContent(webContentsId); return view?.tab.server.name; @@ -497,7 +477,7 @@ export function sendToFind() { } } -export function handleHistory(event: IpcMainEvent, offset: number) { +function handleHistory(event: IpcMainEvent, offset: number) { if (status.viewManager) { const activeView = status.viewManager.getCurrentView(); if (activeView && activeView.view.webContents.canGoToOffset(offset)) { @@ -606,7 +586,8 @@ function handleAppLoggedOut(event: IpcMainEvent, viewName: string) { } function handleGetViewName(event: IpcMainInvokeEvent) { - return getViewNameByWebContentsId(event.sender.id); + const view = status.viewManager?.findViewByWebContent(event.sender.id); + return view?.name; } function handleGetWebContentsId(event: IpcMainInvokeEvent) { return event.sender.id; diff --git a/src/renderer/notificationSounds.ts b/src/renderer/notificationSounds.ts index e1832285..10928b78 100644 --- a/src/renderer/notificationSounds.ts +++ b/src/renderer/notificationSounds.ts @@ -11,7 +11,7 @@ import hello from 'static/sounds/hello.mp3'; import ripple from 'static/sounds/ripple.mp3'; import upstairs from 'static/sounds/upstairs.mp3'; -export const DEFAULT_WIN7 = 'Ding'; +const DEFAULT_WIN7 = 'Ding'; const notificationSounds = new Map([ [DEFAULT_WIN7, ding], ['Bing', bing],