From d22be3faf87826e583a7696e253e914afc50d297 Mon Sep 17 00:00:00 2001 From: DemoPark <106856363@qq.com> Date: Wed, 21 Jun 2017 13:06:05 +0800 Subject: [PATCH 01/91] Change em markup In accordance with established practice, the important word is Notifications. so the em markup should be used for Notifications. --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 2669926c..1d8ba42b 100644 --- a/index.html +++ b/index.html @@ -59,7 +59,7 @@ - + From 9cf201a07cf5240a1992585312569549ebbc731f Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Tue, 25 Jul 2017 15:42:29 -0700 Subject: [PATCH 02/91] avoid publishing secrets to github and npm (#315) --- package-lock.json | 497 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 8 +- 2 files changed, 503 insertions(+), 2 deletions(-) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..596f4c87 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,497 @@ +{ + "name": "ElectronAPIDemos", + "version": "1.3.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "anymatch": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-1.3.0.tgz", + "integrity": "sha1-o+Uvo5FoyCX/V7AkgSbOWo/5VQc=", + "dev": true, + "requires": { + "arrify": "1.0.1", + "micromatch": "2.3.11" + } + }, + "arr-diff": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-2.0.0.tgz", + "integrity": "sha1-jzuCf5Vai9ZpaX5KQlasPOrjVs8=", + "dev": true, + "requires": { + "arr-flatten": "1.1.0" + } + }, + "arr-flatten": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/arr-flatten/-/arr-flatten-1.1.0.tgz", + "integrity": "sha512-L3hKV5R/p5o81R7O02IGnwpDmkp6E982XhtbuwSe3O4qOtMMMtodicASA1Cny2U+aCXcNpml+m4dPsvsJ3jatg==", + "dev": true + }, + "array-unique": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/array-unique/-/array-unique-0.2.1.tgz", + "integrity": "sha1-odl8yvy8JiXMcPrc6zalDFiwGlM=", + "dev": true + }, + "arrify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", + "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", + "dev": true + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "brace-expansion": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", + "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", + "dev": true, + "requires": { + "balanced-match": "1.0.0", + "concat-map": "0.0.1" + } + }, + "braces": { + "version": "1.8.5", + "resolved": "https://registry.npmjs.org/braces/-/braces-1.8.5.tgz", + "integrity": "sha1-uneWLhLf+WnWt2cR6RS3N4V79qc=", + "dev": true, + "requires": { + "expand-range": "1.8.2", + "preserve": "0.2.0", + "repeat-element": "1.1.2" + } + }, + "check-for-leaks": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/check-for-leaks/-/check-for-leaks-1.2.0.tgz", + "integrity": "sha512-bJ2Bzo6RtsYqamMnsjtVzowGvBNVrR5IPK8Bd+lx5W1TNgOKMsF+AyNHVkqFqO7cpDZNfny5SaqH6gEovpV5Gw==", + "dev": true, + "requires": { + "anymatch": "1.3.0", + "minimist": "1.2.0", + "parse-gitignore": "0.4.0", + "walk-sync": "0.3.2" + } + }, + "ci-info": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-1.0.0.tgz", + "integrity": "sha1-3FKF8rTiUYIWg2gcOBwziPRuxTQ=", + "dev": true + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "ensure-posix-path": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/ensure-posix-path/-/ensure-posix-path-1.0.2.tgz", + "integrity": "sha1-pls+QtC3HPxYXrd0+ZQ8jZuRsMI=", + "dev": true + }, + "expand-brackets": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/expand-brackets/-/expand-brackets-0.1.5.tgz", + "integrity": "sha1-3wcoTjQqgHzXM6xa9yQR5YHRF3s=", + "dev": true, + "requires": { + "is-posix-bracket": "0.1.1" + } + }, + "expand-range": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/expand-range/-/expand-range-1.8.2.tgz", + "integrity": "sha1-opnv/TNf4nIeuujiV+x5ZE/IUzc=", + "dev": true, + "requires": { + "fill-range": "2.2.3" + } + }, + "extglob": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/extglob/-/extglob-0.3.2.tgz", + "integrity": "sha1-Lhj/PS9JqydlzskCPwEdqo2DSaE=", + "dev": true, + "requires": { + "is-extglob": "1.0.0" + } + }, + "filename-regex": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz", + "integrity": "sha1-wcS5vuPglyXdsQa3XB4wH+LxiyY=", + "dev": true + }, + "fill-range": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-2.2.3.tgz", + "integrity": "sha1-ULd9/X5Gm8dJJHCWNpn+eoSFpyM=", + "dev": true, + "requires": { + "is-number": "2.1.0", + "isobject": "2.1.0", + "randomatic": "1.1.7", + "repeat-element": "1.1.2", + "repeat-string": "1.6.1" + } + }, + "for-in": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", + "integrity": "sha1-gQaNKVqBQuwKxybG4iAMMPttXoA=", + "dev": true + }, + "for-own": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/for-own/-/for-own-0.1.5.tgz", + "integrity": "sha1-UmXGgaTylNq78XyVCbZ2OqhFEM4=", + "dev": true, + "requires": { + "for-in": "1.0.2" + } + }, + "glob-base": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/glob-base/-/glob-base-0.3.0.tgz", + "integrity": "sha1-27Fk9iIbHAscz4Kuoyi0l98Oo8Q=", + "dev": true, + "requires": { + "glob-parent": "2.0.0", + "is-glob": "2.0.1" + } + }, + "glob-parent": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-2.0.0.tgz", + "integrity": "sha1-gTg9ctsFT8zPUzbaqQLxgvbtuyg=", + "dev": true, + "requires": { + "is-glob": "2.0.1" + } + }, + "husky": { + "version": "0.14.3", + "resolved": "https://registry.npmjs.org/husky/-/husky-0.14.3.tgz", + "integrity": "sha512-e21wivqHpstpoiWA/Yi8eFti8E+sQDSS53cpJsPptPs295QTOQR0ZwnHo2TXy1XOpZFD9rPOd3NpmqTK6uMLJA==", + "dev": true, + "requires": { + "is-ci": "1.0.10", + "normalize-path": "1.0.0", + "strip-indent": "2.0.0" + }, + "dependencies": { + "normalize-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-1.0.0.tgz", + "integrity": "sha1-MtDkcvkf80VwHBWoMRAY07CpA3k=", + "dev": true + } + } + }, + "is-buffer": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.5.tgz", + "integrity": "sha1-Hzsm72E7IUuIy8ojzGwB2Hlh7sw=", + "dev": true + }, + "is-ci": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-1.0.10.tgz", + "integrity": "sha1-9zkzayYyNlBhqdSCcM1WrjNpMY4=", + "dev": true, + "requires": { + "ci-info": "1.0.0" + } + }, + "is-dotfile": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/is-dotfile/-/is-dotfile-1.0.3.tgz", + "integrity": "sha1-pqLzL/0t+wT1yiXs0Pa4PPeYoeE=", + "dev": true + }, + "is-equal-shallow": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/is-equal-shallow/-/is-equal-shallow-0.1.3.tgz", + "integrity": "sha1-IjgJj8Ih3gvPpdnqxMRdY4qhxTQ=", + "dev": true, + "requires": { + "is-primitive": "2.0.0" + } + }, + "is-extendable": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-0.1.1.tgz", + "integrity": "sha1-YrEQ4omkcUGOPsNqYX1HLjAd/Ik=", + "dev": true + }, + "is-extglob": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-1.0.0.tgz", + "integrity": "sha1-rEaBd8SUNAWgkvyPKXYMb/xiBsA=", + "dev": true + }, + "is-glob": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-2.0.1.tgz", + "integrity": "sha1-0Jb5JqPe1WAPP9/ZEZjLCIjC2GM=", + "dev": true, + "requires": { + "is-extglob": "1.0.0" + } + }, + "is-number": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-2.1.0.tgz", + "integrity": "sha1-Afy7s5NGOlSPL0ZszhbezknbkI8=", + "dev": true, + "requires": { + "kind-of": "3.2.2" + } + }, + "is-posix-bracket": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/is-posix-bracket/-/is-posix-bracket-0.1.1.tgz", + "integrity": "sha1-MzTceXdDaOkvAW5vvAqI9c1ua8Q=", + "dev": true + }, + "is-primitive": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-primitive/-/is-primitive-2.0.0.tgz", + "integrity": "sha1-IHurkWOEmcB7Kt8kCkGochADRXU=", + "dev": true + }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", + "dev": true + }, + "isobject": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-2.1.0.tgz", + "integrity": "sha1-8GVWEJaj8dou9GJy+BXIQNh+DIk=", + "dev": true, + "requires": { + "isarray": "1.0.0" + } + }, + "kind-of": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", + "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", + "dev": true, + "requires": { + "is-buffer": "1.1.5" + } + }, + "matcher-collection": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/matcher-collection/-/matcher-collection-1.0.4.tgz", + "integrity": "sha1-L2auCGmZbynkPQtiyD3R1D5YF1U=", + "dev": true, + "requires": { + "minimatch": "3.0.4" + } + }, + "micromatch": { + "version": "2.3.11", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-2.3.11.tgz", + "integrity": "sha1-hmd8l9FyCzY0MdBNDRUpO9OMFWU=", + "dev": true, + "requires": { + "arr-diff": "2.0.0", + "array-unique": "0.2.1", + "braces": "1.8.5", + "expand-brackets": "0.1.5", + "extglob": "0.3.2", + "filename-regex": "2.0.1", + "is-extglob": "1.0.0", + "is-glob": "2.0.1", + "kind-of": "3.2.2", + "normalize-path": "2.1.1", + "object.omit": "2.0.1", + "parse-glob": "3.0.4", + "regex-cache": "0.4.3" + } + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dev": true, + "requires": { + "brace-expansion": "1.1.8" + } + }, + "minimist": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "dev": true + }, + "normalize-path": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz", + "integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=", + "dev": true, + "requires": { + "remove-trailing-separator": "1.0.2" + } + }, + "object.omit": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/object.omit/-/object.omit-2.0.1.tgz", + "integrity": "sha1-Gpx0SCnznbuFjHbKNXmuKlTr0fo=", + "dev": true, + "requires": { + "for-own": "0.1.5", + "is-extendable": "0.1.1" + } + }, + "parse-gitignore": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/parse-gitignore/-/parse-gitignore-0.4.0.tgz", + "integrity": "sha1-q/cC5LkAUk//eQK2g4YoV7Y/k/4=", + "dev": true, + "requires": { + "array-unique": "0.3.2", + "is-glob": "3.1.0" + }, + "dependencies": { + "array-unique": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/array-unique/-/array-unique-0.3.2.tgz", + "integrity": "sha1-qJS3XUvE9s1nnvMkSp/Y9Gri1Cg=", + "dev": true + }, + "is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", + "dev": true + }, + "is-glob": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-3.1.0.tgz", + "integrity": "sha1-e6WuJCF4BKxwcHuWkiVnSGzD6Eo=", + "dev": true, + "requires": { + "is-extglob": "2.1.1" + } + } + } + }, + "parse-glob": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/parse-glob/-/parse-glob-3.0.4.tgz", + "integrity": "sha1-ssN2z7EfNVE7rdFz7wu246OIORw=", + "dev": true, + "requires": { + "glob-base": "0.3.0", + "is-dotfile": "1.0.3", + "is-extglob": "1.0.0", + "is-glob": "2.0.1" + } + }, + "preserve": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/preserve/-/preserve-0.2.0.tgz", + "integrity": "sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks=", + "dev": true + }, + "randomatic": { + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/randomatic/-/randomatic-1.1.7.tgz", + "integrity": "sha512-D5JUjPyJbaJDkuAazpVnSfVkLlpeO3wDlPROTMLGKG1zMFNFRgrciKo1ltz/AzNTkqE0HzDx655QOL51N06how==", + "dev": true, + "requires": { + "is-number": "3.0.0", + "kind-of": "4.0.0" + }, + "dependencies": { + "is-number": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz", + "integrity": "sha1-JP1iAaR4LPUFYcgQJ2r8fRLXEZU=", + "dev": true, + "requires": { + "kind-of": "3.2.2" + }, + "dependencies": { + "kind-of": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", + "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", + "dev": true, + "requires": { + "is-buffer": "1.1.5" + } + } + } + }, + "kind-of": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-4.0.0.tgz", + "integrity": "sha1-IIE989cSkosgc3hpGkUGb65y3Vc=", + "dev": true, + "requires": { + "is-buffer": "1.1.5" + } + } + } + }, + "regex-cache": { + "version": "0.4.3", + "resolved": "https://registry.npmjs.org/regex-cache/-/regex-cache-0.4.3.tgz", + "integrity": "sha1-mxpsNdTQ3871cRrmUejp09cRQUU=", + "dev": true, + "requires": { + "is-equal-shallow": "0.1.3", + "is-primitive": "2.0.0" + } + }, + "remove-trailing-separator": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.0.2.tgz", + "integrity": "sha1-abBi2XhyetFNxrVrpKt3L9jXBRE=", + "dev": true + }, + "repeat-element": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/repeat-element/-/repeat-element-1.1.2.tgz", + "integrity": "sha1-7wiaF40Ug7quTZPrmLT55OEdmQo=", + "dev": true + }, + "repeat-string": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", + "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=", + "dev": true + }, + "strip-indent": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-2.0.0.tgz", + "integrity": "sha1-XvjbKV0B5u1sv3qrlpmNeCJSe2g=", + "dev": true + }, + "walk-sync": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/walk-sync/-/walk-sync-0.3.2.tgz", + "integrity": "sha512-FMB5VqpLqOCcqrzA9okZFc0wq0Qbmdm396qJxvQZhDpyu0W95G9JCmp74tx7iyYnyOcBtUuKJsgIKAqjozvmmQ==", + "dev": true, + "requires": { + "ensure-posix-path": "1.0.2", + "matcher-collection": "1.0.4" + } + } + } +} diff --git a/package.json b/package.json index 61eb90ee..0e338591 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,9 @@ "package:sign-installer": "signcode './out/windows-installer/ElectronAPIDemosSetup.exe' --cert ~/electron-api-demos.p12 --prompt --name 'Electron API Demos' --url 'http://electron.atom.io/'", "package:mas": "./script/mas.sh", "windows-store": "node ./script/windows-store.js", - "release": "node ./script/release.js" + "release": "node ./script/release.js", + "prepack": "check-for-leaks", + "prepush": "check-for-leaks" }, "repository": "https://github.com/electron/electron-api-demos", "keywords": [ @@ -31,10 +33,12 @@ "devDependencies": { "chai": "^3.4.1", "chai-as-promised": "^6.0.0", + "check-for-leaks": "^1.2.0", "devtron": "^1.3.0", "electron": "~1.6.2", "electron-packager": "^8.6.0", "electron-winstaller": "^2.2.0", + "husky": "^0.14.3", "mocha": "^3.1.0", "npm-run-all": "^4.0.2", "request": "^2.70.0", @@ -54,4 +58,4 @@ "mocha": true } } -} +} \ No newline at end of file From ce9e2f783f44bc8559e6fa39bf6352b77b1cdf4a Mon Sep 17 00:00:00 2001 From: Jan Hecht Date: Wed, 26 Jul 2017 06:03:30 +0200 Subject: [PATCH 03/91] fix two typos (#311) * fixed typo (one 'to' too much) * fixed small typo --- sections/communication/ipc.html | 2 +- sections/windows/crash-hang.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sections/communication/ipc.html b/sections/communication/ipc.html index f06aef5b..4dd9e383 100644 --- a/sections/communication/ipc.html +++ b/sections/communication/ipc.html @@ -66,7 +66,7 @@
Main Process

It is common practice to create a new invisible browser window (renderer process) in order to run tasks without impacting performance in the main app's window.

In this example we use the remote module to create a new invisible browser window from this renderer process. When the new page is loaded we send a message with ipc that the new window is listening for.

-

The new window then computes the factorial and sends the result to be recieved by this, the original, window and added to the page above.

+

The new window then computes the factorial and sends the result to be received by this, the original, window and added to the page above.

Renderer Process
Invisible Window Page HTML
diff --git a/sections/windows/crash-hang.html b/sections/windows/crash-hang.html index b19ad082..602b7f9b 100644 --- a/sections/windows/crash-hang.html +++ b/sections/windows/crash-hang.html @@ -48,7 +48,7 @@
Renderer Process

ProTip

Wait for the process to become responsive again. -

A third option in the case of a process that is hanging is to wait and see if the problem resolves, allowing the process to become responsive again. To to do this, use the BrowserWindow event 'responsive' as shown below.

+

A third option in the case of a process that is hanging is to wait and see if the problem resolves, allowing the process to become responsive again. To do this, use the BrowserWindow event 'responsive' as shown below.

win.on('responsive', function () {
   // Do something when the window is responsive again
 })
From a76cdcc754e53b00cf84c6557f60c3ba684517e2 Mon Sep 17 00:00:00 2001 From: Justin Mai <9123665+justinTM@users.noreply.github.com> Date: Fri, 28 Jul 2017 16:18:36 -0700 Subject: [PATCH 04/91] Fix typo in docs.md you section --> your section --- docs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs.md b/docs.md index ee9d16e1..75edf33b 100644 --- a/docs.md +++ b/docs.md @@ -109,4 +109,4 @@ The renderer process code you add will be read and displayed within the demo and #### Try it out -At this point you should be able to run the app, `npm start`, and see you section and/or demo. :tada: +At this point you should be able to run the app, `npm start`, and see your section and/or demo. :tada: From ce68cbe07a76644a577a9c8df423e4561bd800bf Mon Sep 17 00:00:00 2001 From: Daniel Bird Date: Tue, 8 Aug 2017 04:35:01 +1200 Subject: [PATCH 05/91] Fixed typo. (#312) --- sections/windows/crash-hang.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sections/windows/crash-hang.html b/sections/windows/crash-hang.html index 602b7f9b..1a8424f0 100644 --- a/sections/windows/crash-hang.html +++ b/sections/windows/crash-hang.html @@ -40,7 +40,7 @@
Renderer Process

In this demo we create a new window (via the remote module) and provide a link that will force the process to hang using process.hang().

-

The window is listening for the process to become offcially unresponsive (this can take up to 30 seconds). When this event occurs it prompts the user with two options: reload or close.

+

The window is listening for the process to become officially unresponsive (this can take up to 30 seconds). When this event occurs it prompts the user with two options: reload or close.

Renderer Process
From 91ef20ca4a3314eee937e80af7b10640c881d18b Mon Sep 17 00:00:00 2001 From: Tomoyuki Aota Date: Fri, 27 Oct 2017 01:27:57 +0900 Subject: [PATCH 06/91] Fix typo (from interupting to interrupting). --- sections/native-ui/dialogs.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sections/native-ui/dialogs.html b/sections/native-ui/dialogs.html index a945749f..dcba6218 100644 --- a/sections/native-ui/dialogs.html +++ b/sections/native-ui/dialogs.html @@ -8,7 +8,7 @@

The dialog module in Electron allows you to use native system dialogs for opening files or directories, saving a file or displaying informational messages.

-

This is a main process module because this process is more efficient with native utilities and it allows the call to happen without interupting the visible elements in your page's renderer process.

+

This is a main process module because this process is more efficient with native utilities and it allows the call to happen without interrupting the visible elements in your page's renderer process.

Open the full API documentation(opens in new window) in your browser.

From 379763dbad9e501a7b8eb11ecb8a74975b53caed Mon Sep 17 00:00:00 2001 From: Jonas Zhang <106856363@qq.com> Date: Thu, 23 Nov 2017 10:44:27 +0800 Subject: [PATCH 07/91] Update new Chinese version of this app the old linked version is too old. update this new Chinese version. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2048ddea..86a57684 100644 --- a/README.md +++ b/README.md @@ -47,4 +47,4 @@ $ npm run dev ## Translations -A Chinese translation of this app is available at [`fuchao2012/zh-cn-Electron-API-Demos`](https://github.com/fuchao2012/zh-cn-Electron-API-Demos). Note: this version is maintained by outside contributors and may not always be in sync with this version. +A Chinese version of this app is available at [`demopark/electron-api-demos-Zh_CN`](https://github.com/demopark/electron-api-demos-Zh_CN). Note: this version is maintained by outside contributors and may not always be in sync with this version. From 144cd92d0c8f9a4230982a4b38d11f880e8c5795 Mon Sep 17 00:00:00 2001 From: pjchender Date: Thu, 25 Jan 2018 15:20:44 +0800 Subject: [PATCH 08/91] Add a Traditional Chinese version (zh-Hant) --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2048ddea..5b3368bf 100644 --- a/README.md +++ b/README.md @@ -47,4 +47,7 @@ $ npm run dev ## Translations -A Chinese translation of this app is available at [`fuchao2012/zh-cn-Electron-API-Demos`](https://github.com/fuchao2012/zh-cn-Electron-API-Demos). Note: this version is maintained by outside contributors and may not always be in sync with this version. +* Simplified Chinese translation of this app is available at [`fuchao2012/zh-cn-Electron-API-Demos`](https://github.com/fuchao2012/zh-cn-Electron-API-Demos). +* Tradition Chinese translation of this app is available at [`CalvertYang/electron-api-demos-zh-Hant`](https://github.com/CalvertYang/electron-api-demos-zh-Hant). + +Note: these versions are maintained by outside contributors and may not always be in sync with this version. From 09ac976f9ad0b448f19ca1ff128cf233b8665f6c Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 31 Jan 2018 09:08:10 -0500 Subject: [PATCH 09/91] update node version to v8.9.3 --- .node-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.node-version b/.node-version index db6ecdd8..b4de8e49 100644 --- a/.node-version +++ b/.node-version @@ -1 +1 @@ -v4.3.2 +v8.9.3 From 357c598ed6d0f2ee886fe4b5b848c9efba7bae1f Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 31 Jan 2018 09:28:49 -0500 Subject: [PATCH 10/91] update MacOS keyboard shortcut link --- sections/menus/menus.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sections/menus/menus.html b/sections/menus/menus.html index 7d2f55ef..ccaf85ba 100644 --- a/sections/menus/menus.html +++ b/sections/menus/menus.html @@ -32,7 +32,7 @@

ProTip

When designing an app for multiple operating systems it's important to be mindful of the ways application menu conventions differ on each operating system.

For instance, on Windows, accelerators are set with an &. Naming conventions also vary, like between "Settings" or "Preferences". Below are resources for learning operating system specific standards.

From e4c2cb35dc1b9adaaf92dd508c65937231496444 Mon Sep 17 00:00:00 2001 From: shelley vohr Date: Wed, 31 Jan 2018 11:29:31 -0500 Subject: [PATCH 11/91] Split tests into setup.js and index.js (#342) * first steps towards splitting tests * finish splitting tests * appease the linter * strict mode and return * remove extension --- test/index.js | 98 ++++++++------------------------------------------- test/setup.js | 83 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 83 deletions(-) create mode 100644 test/setup.js diff --git a/test/index.js b/test/index.js index 2437b4e5..8577ed68 100644 --- a/test/index.js +++ b/test/index.js @@ -5,7 +5,7 @@ const electron = require('electron') const chai = require('chai') const chaiAsPromised = require('chai-as-promised') const path = require('path') -const fs = require('fs') +const setup = require('./setup') chai.should() chai.use(chaiAsPromised) @@ -17,79 +17,7 @@ describe('demo app', function () { let app - const getUserDataPath = function () { - const productName = require('../package').productName - switch (process.platform) { - case 'darwin': - return path.join(process.env.HOME, 'Library', 'Application Support', productName) - case 'win32': - return path.join(process.env.APPDATA, productName) - case 'freebsd': - case 'linux': - case 'sunos': - return path.join(process.env.HOME, '.config', productName) - default: - throw new Error(`Unknown userDataPath path for platform ${process.platform}`) - } - } - - const removeStoredPreferences = function () { - const userDataPath = getUserDataPath() - try { - fs.unlinkSync(path.join(userDataPath, 'Settings')) - } catch (error) { - if (error.code !== 'ENOENT') throw error - } - } - - const setupApp = function (app) { - app.client.addCommand('dismissAboutPage', function () { - return this.isVisible('.js-nav').then(function (navVisible) { - if (!navVisible) { - return this.click('button[id="get-started"]').pause(500) - } - }) - }) - - app.client.addCommand('selectSection', function (section) { - return this.click('button[data-section="' + section + '"]').pause(100) - .waitForVisible('#' + section + '-section') - }) - - app.client.addCommand('expandDemos', function () { - return this.execute(function () { - for (let demo of document.querySelectorAll('.demo-wrapper')) { - demo.classList.add('is-open') - } - }) - }) - - app.client.addCommand('collapseDemos', function () { - return this.execute(function () { - for (let demo of document.querySelectorAll('.demo-wrapper')) { - demo.classList.remove('is-open') - } - }) - }) - - app.client.addCommand('auditSectionAccessibility', function (section) { - const options = { - ignoreRules: ['AX_COLOR_01', 'AX_TITLE_01'] - } - return this.selectSection(section) - .expandDemos() - .auditAccessibility(options).then(function (audit) { - if (audit.failed) { - throw Error(section + ' section failed accessibility audit\n' + audit.message) - } - }) - }) - - chaiAsPromised.transferPromiseness = app.transferPromiseness - return app.client.waitUntilWindowLoaded() - } - - const startApp = function () { + const startApp = () => { app = new Application({ path: electron, args: [ @@ -98,30 +26,34 @@ describe('demo app', function () { waitTimeout: timeout }) - return app.start().then(setupApp) + return app.start().then((ret) => { + setup.setupApp(ret) + }) } - const restartApp = function () { - return app.restart().then(setupApp) + const restartApp = () => { + return app.restart().then((ret) => { + setup.setupApp(ret) + }) } - before(function () { - removeStoredPreferences() + before(() => { + setup.removeStoredPreferences() return startApp() }) - after(function () { + after(() => { if (app && app.isRunning()) { return app.stop() } }) it('checks hardcoded path for userData is correct', function () { - return app.client.execute(function () { + return app.client.execute(() => { return require('electron').remote.app.getPath('userData') - }).then(function (result) { + }).then((result) => { return result.value - }).should.eventually.equal(getUserDataPath()) + }).should.eventually.equal(setup.getUserDataPath()) }) it('opens a window displaying the about page', function () { diff --git a/test/setup.js b/test/setup.js new file mode 100644 index 00000000..c9fb645a --- /dev/null +++ b/test/setup.js @@ -0,0 +1,83 @@ +'use strict' + +const path = require('path') +const fs = require('fs') +const chaiAsPromised = require('chai-as-promised') + +const getUserDataPath = function () { + const productName = require('../package').productName + switch (process.platform) { + case 'darwin': + return path.join(process.env.HOME, 'Library', 'Application Support', productName) + case 'win32': + return path.join(process.env.APPDATA, productName) + case 'freebsd': + case 'linux': + case 'sunos': + return path.join(process.env.HOME, '.config', productName) + default: + throw new Error(`Unknown userDataPath path for platform ${process.platform}`) + } +} + +const removeStoredPreferences = () => { + const userDataPath = getUserDataPath() + try { + fs.unlinkSync(path.join(userDataPath, 'Settings')) + } catch (error) { + if (error.code !== 'ENOENT') throw error + } +} + +const setupApp = function (app) { + app.client.addCommand('dismissAboutPage', function () { + return this.isVisible('.js-nav').then(function (navVisible) { + if (!navVisible) { + return this.click('button[id="get-started"]').pause(500) + } + }) + }) + + app.client.addCommand('selectSection', function (section) { + return this.click('button[data-section="' + section + '"]').pause(100) + .waitForVisible('#' + section + '-section') + }) + + app.client.addCommand('expandDemos', function () { + return this.execute(function () { + for (let demo of document.querySelectorAll('.demo-wrapper')) { + demo.classList.add('is-open') + } + }) + }) + + app.client.addCommand('collapseDemos', function () { + return this.execute(function () { + for (let demo of document.querySelectorAll('.demo-wrapper')) { + demo.classList.remove('is-open') + } + }) + }) + + app.client.addCommand('auditSectionAccessibility', function (section) { + const options = { + ignoreRules: ['AX_COLOR_01', 'AX_TITLE_01'] + } + return this.selectSection(section) + .expandDemos() + .auditAccessibility(options).then(function (audit) { + if (audit.failed) { + throw Error(section + ' section failed accessibility audit\n' + audit.message) + } + }) + }) + + chaiAsPromised.transferPromiseness = app.transferPromiseness + return app.client.waitUntilWindowLoaded() +} + +module.exports = { + removeStoredPreferences, + getUserDataPath, + setupApp +} From 83195719a7fffe1378a6f2cf65e549b7b2b44ab4 Mon Sep 17 00:00:00 2001 From: Johan Date: Tue, 6 Feb 2018 14:38:48 +0100 Subject: [PATCH 12/91] replaces keyboard link with menu link (#346) --- sections/menus/menus.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sections/menus/menus.html b/sections/menus/menus.html index ccaf85ba..5b3cfa08 100644 --- a/sections/menus/menus.html +++ b/sections/menus/menus.html @@ -32,7 +32,7 @@

ProTip

When designing an app for multiple operating systems it's important to be mindful of the ways application menu conventions differ on each operating system.

For instance, on Windows, accelerators are set with an &. Naming conventions also vary, like between "Settings" or "Preferences". Below are resources for learning operating system specific standards.

From ef613b34cd8bf8af59219ca0de9cf2ede9befeef Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 15 Feb 2018 18:43:08 -0500 Subject: [PATCH 13/91] update year to 2018 --- license.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/license.md b/license.md index 84256b36..9317777c 100644 --- a/license.md +++ b/license.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2016 GitHub Inc. +Copyright (c) 2018 GitHub Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From edcb23f0da0ba11b157bc316e379bc3024312da0 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 15 Feb 2018 18:54:30 -0500 Subject: [PATCH 14/91] make year a range --- license.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/license.md b/license.md index 9317777c..cadb6004 100644 --- a/license.md +++ b/license.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 GitHub Inc. +Copyright (c) 2016-2018 GitHub Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 4bfa59ef08d11b682b48b8f96a477788373b4754 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 15 Feb 2018 18:58:33 -0500 Subject: [PATCH 15/91] update main.js to es6 --- main.js | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/main.js b/main.js index 7d6cdc2f..c3028273 100644 --- a/main.js +++ b/main.js @@ -1,25 +1,22 @@ const path = require('path') const glob = require('glob') -const electron = require('electron') +const {app, BrowserWindow} = require('electron') const autoUpdater = require('./auto-updater') -const BrowserWindow = electron.BrowserWindow -const app = electron.app - const debug = /--debug/.test(process.argv[2]) if (process.mas) app.setName('Electron APIs') -var mainWindow = null +let mainWindow = null function initialize () { - var shouldQuit = makeSingleInstance() + const shouldQuit = makeSingleInstance() if (shouldQuit) return app.quit() loadDemos() function createWindow () { - var windowOptions = { + const windowOptions = { width: 1080, minWidth: 680, height: 840, @@ -40,23 +37,23 @@ function initialize () { require('devtron').install() } - mainWindow.on('closed', function () { + mainWindow.on('closed', () => { mainWindow = null }) } - app.on('ready', function () { + app.on('ready', () => { createWindow() autoUpdater.initialize() }) - app.on('window-all-closed', function () { + app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit() } }) - app.on('activate', function () { + app.on('activate', () => { if (mainWindow === null) { createWindow() } @@ -73,7 +70,7 @@ function initialize () { function makeSingleInstance () { if (process.mas) return false - return app.makeSingleInstance(function () { + return app.makeSingleInstance(() => { if (mainWindow) { if (mainWindow.isMinimized()) mainWindow.restore() mainWindow.focus() @@ -83,20 +80,18 @@ function makeSingleInstance () { // Require each JS file in the main-process dir function loadDemos () { - var files = glob.sync(path.join(__dirname, 'main-process/**/*.js')) - files.forEach(function (file) { - require(file) - }) + const files = glob.sync(path.join(__dirname, 'main-process/**/*.js')) + files.forEach((file) => { require(file) }) autoUpdater.updateMenu() } // Handle Squirrel on Windows startup events switch (process.argv[1]) { case '--squirrel-install': - autoUpdater.createShortcut(function () { app.quit() }) + autoUpdater.createShortcut(() => { app.quit() }) break case '--squirrel-uninstall': - autoUpdater.removeShortcut(function () { app.quit() }) + autoUpdater.removeShortcut(() => { app.quit() }) break case '--squirrel-obsolete': case '--squirrel-updated': From 730f1594df4b5544620a2ee339aa9758f4626483 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 15 Feb 2018 19:04:10 -0500 Subject: [PATCH 16/91] update auto-updater.js to es6 --- auto-updater.js | 52 +++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/auto-updater.js b/auto-updater.js index 4c30a246..69accbb0 100644 --- a/auto-updater.js +++ b/auto-updater.js @@ -1,35 +1,33 @@ -const app = require('electron').app -const autoUpdater = require('electron').autoUpdater +const {app, autoUpdater, Menu} = require('electron') const ChildProcess = require('child_process') -const Menu = require('electron').Menu const path = require('path') -var state = 'checking' +let state = 'checking' -exports.initialize = function () { +exports.initialize = () => { if (process.mas) return - autoUpdater.on('checking-for-update', function () { + autoUpdater.on('checking-for-update', () => { state = 'checking' exports.updateMenu() }) - autoUpdater.on('update-available', function () { + autoUpdater.on('update-available', () => { state = 'checking' exports.updateMenu() }) - autoUpdater.on('update-downloaded', function () { + autoUpdater.on('update-downloaded', () => { state = 'installed' exports.updateMenu() }) - autoUpdater.on('update-not-available', function () { + autoUpdater.on('update-not-available', () => { state = 'no-update' exports.updateMenu() }) - autoUpdater.on('error', function () { + autoUpdater.on('error', () => { state = 'no-update' exports.updateMenu() }) @@ -38,15 +36,15 @@ exports.initialize = function () { autoUpdater.checkForUpdates() } -exports.updateMenu = function () { +exports.updateMenu = () => { if (process.mas) return - var menu = Menu.getApplicationMenu() + const menu = Menu.getApplicationMenu() if (!menu) return - menu.items.forEach(function (item) { + menu.items.forEach(item => { if (item.submenu) { - item.submenu.items.forEach(function (item) { + item.submenu.items.forEach(item => { switch (item.key) { case 'checkForUpdate': item.visible = state === 'no-update' @@ -63,7 +61,7 @@ exports.updateMenu = function () { }) } -exports.createShortcut = function (callback) { +exports.createShortcut = callback => { spawnUpdate([ '--createShortcut', path.basename(process.execPath), @@ -72,7 +70,7 @@ exports.createShortcut = function (callback) { ], callback) } -exports.removeShortcut = function (callback) { +exports.removeShortcut = callback => { spawnUpdate([ '--removeShortcut', path.basename(process.execPath) @@ -80,29 +78,33 @@ exports.removeShortcut = function (callback) { } function spawnUpdate (args, callback) { - var updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe') - var stdout = '' - var spawned = null + const updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe') + let stdout = '' + let spawned = null try { spawned = ChildProcess.spawn(updateExe, args) } catch (error) { - if (error && error.stdout == null) error.stdout = stdout - process.nextTick(function () { callback(error) }) + if (error && error.stdout == null) { + error.stdout = stdout + } + process.nextTick(() => { callback(error) }) return } var error = null - spawned.stdout.on('data', function (data) { stdout += data }) + spawned.stdout.on('data', data => { + stdout += data + }) - spawned.on('error', function (processError) { + spawned.on('error', processError => { if (!error) error = processError }) - spawned.on('close', function (code, signal) { + spawned.on('close', (code, signal) => { if (!error && code !== 0) { - error = new Error('Command failed: ' + code + ' ' + signal) + error = new Error(`Command failed: ${code} ${signal}`) } if (error && error.code == null) error.code = code if (error && error.stdout == null) error.stdout = stdout From 6fdf863320080422d4a2ecb241a3e358c184217c Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 15 Feb 2018 19:25:44 -0500 Subject: [PATCH 17/91] update main process files to es6 --- main-process/communication/async-msg.js | 4 +- main-process/communication/sync-msg.js | 4 +- main-process/media/pdf.js | 17 +++------ main-process/menus/application-menu.js | 49 +++++++++++-------------- main-process/menus/context-menu.js | 19 +++++----- 5 files changed, 42 insertions(+), 51 deletions(-) diff --git a/main-process/communication/async-msg.js b/main-process/communication/async-msg.js index bbd929ce..50b2b3ee 100644 --- a/main-process/communication/async-msg.js +++ b/main-process/communication/async-msg.js @@ -1,5 +1,5 @@ -const ipc = require('electron').ipcMain +const {ipcMain} = require('electron') -ipc.on('asynchronous-message', function (event, arg) { +ipcMain.on('asynchronous-message', (event, arg) => { event.sender.send('asynchronous-reply', 'pong') }) diff --git a/main-process/communication/sync-msg.js b/main-process/communication/sync-msg.js index ba596df9..fcdd6809 100644 --- a/main-process/communication/sync-msg.js +++ b/main-process/communication/sync-msg.js @@ -1,5 +1,5 @@ -const ipc = require('electron').ipcMain +const {ipcMain} = require('electron') -ipc.on('synchronous-message', function (event, arg) { +ipcMain.on('synchronous-message', (event, arg) => { event.returnValue = 'pong' }) diff --git a/main-process/media/pdf.js b/main-process/media/pdf.js index 24077a8d..c6549ed0 100644 --- a/main-process/media/pdf.js +++ b/main-process/media/pdf.js @@ -1,22 +1,17 @@ const fs = require('fs') const os = require('os') const path = require('path') -const electron = require('electron') -const BrowserWindow = electron.BrowserWindow -const ipc = electron.ipcMain -const shell = electron.shell +const {BrowserWindow, ipcMain, shell} = require('electron') -ipc.on('print-to-pdf', function (event) { +ipcMain.on('print-to-pdf', (event) => { const pdfPath = path.join(os.tmpdir(), 'print.pdf') const win = BrowserWindow.fromWebContents(event.sender) // Use default printing options - win.webContents.printToPDF({}, function (error, data) { + win.webContents.printToPDF({}, (error, data) => { if (error) throw error - fs.writeFile(pdfPath, data, function (error) { - if (error) { - throw error - } - shell.openExternal('file://' + pdfPath) + fs.writeFile(pdfPath, data, (error) => { + if (error) throw error + shell.openExternal(`file://${pdfPath}`) event.sender.send('wrote-pdf', pdfPath) }) }) diff --git a/main-process/menus/application-menu.js b/main-process/menus/application-menu.js index 5107a0da..b543889c 100644 --- a/main-process/menus/application-menu.js +++ b/main-process/menus/application-menu.js @@ -1,7 +1,4 @@ -const electron = require('electron') -const BrowserWindow = electron.BrowserWindow -const Menu = electron.Menu -const app = electron.app +const {BrowserWindow, Menu, app, shell, dialog} = require('electron') let template = [{ label: 'Edit', @@ -37,15 +34,13 @@ let template = [{ submenu: [{ label: 'Reload', accelerator: 'CmdOrCtrl+R', - click: function (item, focusedWindow) { + click: (item, focusedWindow) => { if (focusedWindow) { // on reload, start fresh and close any old // open secondary windows if (focusedWindow.id === 1) { - BrowserWindow.getAllWindows().forEach(function (win) { - if (win.id > 1) { - win.close() - } + BrowserWindow.getAllWindows().forEach(win => { + if (win.id > 1) win.close() }) } focusedWindow.reload() @@ -53,28 +48,28 @@ let template = [{ } }, { label: 'Toggle Full Screen', - accelerator: (function () { + accelerator: (() => { if (process.platform === 'darwin') { return 'Ctrl+Command+F' } else { return 'F11' } })(), - click: function (item, focusedWindow) { + click: (item, focusedWindow) => { if (focusedWindow) { focusedWindow.setFullScreen(!focusedWindow.isFullScreen()) } } }, { label: 'Toggle Developer Tools', - accelerator: (function () { + accelerator: (() => { if (process.platform === 'darwin') { return 'Alt+Command+I' } else { return 'Ctrl+Shift+I' } })(), - click: function (item, focusedWindow) { + click: (item, focusedWindow) => { if (focusedWindow) { focusedWindow.toggleDevTools() } @@ -91,7 +86,7 @@ let template = [{ buttons: ['Ok'], message: 'This demo is for the Menu section, showing how to create a clickable menu item in the application menu.' } - electron.dialog.showMessageBox(focusedWindow, options, function () {}) + dialog.showMessageBox(focusedWindow, options, function () {}) } } }] @@ -113,7 +108,7 @@ let template = [{ accelerator: 'CmdOrCtrl+Shift+T', enabled: false, key: 'reopenMenuItem', - click: function () { + click: () => { app.emit('activate') } }] @@ -122,8 +117,8 @@ let template = [{ role: 'help', submenu: [{ label: 'Learn More', - click: function () { - electron.shell.openExternal('http://electron.atom.io/') + click: () => { + shell.openExternal('http://electron.atom.io/') } }] }] @@ -131,7 +126,7 @@ let template = [{ function addUpdateMenuItems (items, position) { if (process.mas) return - const version = electron.app.getVersion() + const version = app.getVersion() let updateItems = [{ label: `Version ${version}`, enabled: false @@ -143,7 +138,7 @@ function addUpdateMenuItems (items, position) { label: 'Check for Update', visible: false, key: 'checkForUpdate', - click: function () { + click: () => { require('electron').autoUpdater.checkForUpdates() } }, { @@ -151,7 +146,7 @@ function addUpdateMenuItems (items, position) { enabled: true, visible: false, key: 'restartToUpdate', - click: function () { + click: () => { require('electron').autoUpdater.quitAndInstall() } }] @@ -164,9 +159,9 @@ function findReopenMenuItem () { if (!menu) return let reopenMenuItem - menu.items.forEach(function (item) { + menu.items.forEach(item => { if (item.submenu) { - item.submenu.items.forEach(function (item) { + item.submenu.items.forEach(item => { if (item.key === 'reopenMenuItem') { reopenMenuItem = item } @@ -177,7 +172,7 @@ function findReopenMenuItem () { } if (process.platform === 'darwin') { - const name = electron.app.getName() + const name = app.getName() template.unshift({ label: name, submenu: [{ @@ -207,7 +202,7 @@ if (process.platform === 'darwin') { }, { label: 'Quit', accelerator: 'Command+Q', - click: function () { + click: () => { app.quit() } }] @@ -229,17 +224,17 @@ if (process.platform === 'win32') { addUpdateMenuItems(helpMenu, 0) } -app.on('ready', function () { +app.on('ready', () => { const menu = Menu.buildFromTemplate(template) Menu.setApplicationMenu(menu) }) -app.on('browser-window-created', function () { +app.on('browser-window-created', () => { let reopenMenuItem = findReopenMenuItem() if (reopenMenuItem) reopenMenuItem.enabled = false }) -app.on('window-all-closed', function () { +app.on('window-all-closed', () => { let reopenMenuItem = findReopenMenuItem() if (reopenMenuItem) reopenMenuItem.enabled = true }) diff --git a/main-process/menus/context-menu.js b/main-process/menus/context-menu.js index d75f863a..ebb321c0 100644 --- a/main-process/menus/context-menu.js +++ b/main-process/menus/context-menu.js @@ -1,22 +1,23 @@ -const electron = require('electron') -const BrowserWindow = electron.BrowserWindow -const Menu = electron.Menu -const MenuItem = electron.MenuItem -const ipc = electron.ipcMain -const app = electron.app +const { + BrowserWindow, + Menu, + MenuItem, + ipcMain, + app +} = require('electron') const menu = new Menu() menu.append(new MenuItem({ label: 'Hello' })) menu.append(new MenuItem({ type: 'separator' })) menu.append(new MenuItem({ label: 'Electron', type: 'checkbox', checked: true })) -app.on('browser-window-created', function (event, win) { - win.webContents.on('context-menu', function (e, params) { +app.on('browser-window-created', (event, win) => { + win.webContents.on('context-menu', (e, params) => { menu.popup(win, params.x, params.y) }) }) -ipc.on('show-context-menu', function (event) { +ipcMain.on('show-context-menu', (event) => { const win = BrowserWindow.fromWebContents(event.sender) menu.popup(win) }) From 6b56b8da2033381e4c5c7c3c831c51f4453786f0 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 15 Feb 2018 19:25:56 -0500 Subject: [PATCH 18/91] update asset files to es6 --- assets/code-blocks.js | 8 ++++---- assets/demo-btns.js | 4 ++-- assets/ex-links.js | 4 ++-- assets/imports.js | 2 +- assets/nav.js | 12 ++++++------ assets/normalize-shortcuts.js | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/assets/code-blocks.js b/assets/code-blocks.js index 07cf8831..f607800d 100644 --- a/assets/code-blocks.js +++ b/assets/code-blocks.js @@ -3,17 +3,17 @@ const path = require('path') const codeBlocksWithPaths = document.querySelectorAll('code[data-path]') -Array.prototype.forEach.call(codeBlocksWithPaths, function (code) { +Array.prototype.forEach.call(codeBlocksWithPaths, (code) => { const codePath = path.join(__dirname, '..', code.dataset.path) const extension = path.extname(codePath) - code.classList.add('language-' + extension.substring(1)) + code.classList.add(`language-${extension.substring(1)}`) code.textContent = fs.readFileSync(codePath) }) -document.addEventListener('DOMContentLoaded', function () { +document.addEventListener('DOMContentLoaded', () => { const highlight = require('highlight.js') const codeBlocks = document.querySelectorAll('pre code') - Array.prototype.forEach.call(codeBlocks, function (code) { + Array.prototype.forEach.call(codeBlocks, (code) => { highlight.highlightBlock(code) }) }) diff --git a/assets/demo-btns.js b/assets/demo-btns.js index b9b73ce3..b00c781f 100644 --- a/assets/demo-btns.js +++ b/assets/demo-btns.js @@ -2,8 +2,8 @@ const settings = require('electron-settings') const demoBtns = document.querySelectorAll('.js-container-target') // Listen for demo button clicks -Array.prototype.forEach.call(demoBtns, function (btn) { - btn.addEventListener('click', function (event) { +Array.prototype.forEach.call(demoBtns, (btn) => { + btn.addEventListener('click', (event) => { const parent = event.target.parentElement // Toggles the "is-open" class on the demo's parent element. diff --git a/assets/ex-links.js b/assets/ex-links.js index 33d7e0f7..4319f8cb 100644 --- a/assets/ex-links.js +++ b/assets/ex-links.js @@ -2,10 +2,10 @@ const shell = require('electron').shell const links = document.querySelectorAll('a[href]') -Array.prototype.forEach.call(links, function (link) { +Array.prototype.forEach.call(links, (link) => { const url = link.getAttribute('href') if (url.indexOf('http') === 0) { - link.addEventListener('click', function (e) { + link.addEventListener('click', (e) => { e.preventDefault() shell.openExternal(url) }) diff --git a/assets/imports.js b/assets/imports.js index 1c5a7032..e5533445 100644 --- a/assets/imports.js +++ b/assets/imports.js @@ -1,7 +1,7 @@ const links = document.querySelectorAll('link[rel="import"]') // Import and add each page to the DOM -Array.prototype.forEach.call(links, function (link) { +Array.prototype.forEach.call(links, (link) => { let template = link.import.querySelector('.task-template') let clone = document.importNode(template.content, true) if (link.href.match('about.html')) { diff --git a/assets/nav.js b/assets/nav.js index 0df792d4..08b4a705 100644 --- a/assets/nav.js +++ b/assets/nav.js @@ -1,6 +1,6 @@ const settings = require('electron-settings') -document.body.addEventListener('click', function (event) { +document.body.addEventListener('click', (event) => { if (event.target.dataset.section) { handleSectionTrigger(event) } else if (event.target.dataset.modal) { @@ -17,7 +17,7 @@ function handleSectionTrigger (event) { event.target.classList.add('is-selected') // Display the current section - const sectionId = event.target.dataset.section + '-section' + const sectionId = `${event.target.dataset.section}-section` document.getElementById(sectionId).classList.add('is-shown') // Save currently active button in localStorage @@ -36,13 +36,13 @@ function showMainContent () { function handleModalTrigger (event) { hideAllModals() - const modalId = event.target.dataset.modal + '-modal' + const modalId = `${event.target.dataset.modal}-modal` document.getElementById(modalId).classList.add('is-shown') } function hideAllModals () { const modals = document.querySelectorAll('.modal.is-shown') - Array.prototype.forEach.call(modals, function (modal) { + Array.prototype.forEach.call(modals, (modal) => { modal.classList.remove('is-shown') }) showMainContent() @@ -50,12 +50,12 @@ function hideAllModals () { function hideAllSectionsAndDeselectButtons () { const sections = document.querySelectorAll('.js-section.is-shown') - Array.prototype.forEach.call(sections, function (section) { + Array.prototype.forEach.call(sections, (section) => { section.classList.remove('is-shown') }) const buttons = document.querySelectorAll('.nav-button.is-selected') - Array.prototype.forEach.call(buttons, function (button) { + Array.prototype.forEach.call(buttons, (button) => { button.classList.remove('is-selected') }) } diff --git a/assets/normalize-shortcuts.js b/assets/normalize-shortcuts.js index f26c6349..bb29a480 100644 --- a/assets/normalize-shortcuts.js +++ b/assets/normalize-shortcuts.js @@ -1,6 +1,6 @@ -let normalize = require('electron-shortcut-normalizer') +const normalize = require('electron-shortcut-normalizer') let shortcuts = document.querySelectorAll('kbd.normalize-to-platform') -Array.prototype.forEach.call(shortcuts, function (shortcut) { +Array.prototype.forEach.call(shortcuts, (shortcut) => { shortcut.innerText = normalize(shortcut.innerText, process.platform) }) From 6e5e1a96daf3ceeca21bd6f31fbcc8e41ed387e4 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 15 Feb 2018 19:31:12 -0500 Subject: [PATCH 19/91] finish updating main process files to es6 --- main-process/menus/shortcuts.js | 11 ++++------- main-process/native-ui/dialogs/error.js | 5 ++--- main-process/native-ui/dialogs/information.js | 7 +++---- main-process/native-ui/dialogs/open-file.js | 11 ++++++----- main-process/native-ui/dialogs/save.js | 7 +++---- main-process/native-ui/tray/tray.js | 16 +++++++--------- main-process/system/app-information.js | 5 ++--- main-process/system/protocol-handler.js | 5 ++--- 8 files changed, 29 insertions(+), 38 deletions(-) diff --git a/main-process/menus/shortcuts.js b/main-process/menus/shortcuts.js index 43b4fee5..656da465 100644 --- a/main-process/menus/shortcuts.js +++ b/main-process/menus/shortcuts.js @@ -1,10 +1,7 @@ -const electron = require('electron') -const app = electron.app -const dialog = electron.dialog -const globalShortcut = electron.globalShortcut +const {app, dialog, globalShortcut} = require('electron') -app.on('ready', function () { - globalShortcut.register('CommandOrControl+Alt+K', function () { +app.on('ready', () => { + globalShortcut.register('CommandOrControl+Alt+K', () => { dialog.showMessageBox({ type: 'info', message: 'Success!', @@ -14,6 +11,6 @@ app.on('ready', function () { }) }) -app.on('will-quit', function () { +app.on('will-quit', () => { globalShortcut.unregisterAll() }) diff --git a/main-process/native-ui/dialogs/error.js b/main-process/native-ui/dialogs/error.js index 3f8f2c08..4ed08432 100644 --- a/main-process/native-ui/dialogs/error.js +++ b/main-process/native-ui/dialogs/error.js @@ -1,6 +1,5 @@ -const ipc = require('electron').ipcMain -const dialog = require('electron').dialog +const {ipcMain, dialog} = require('electron') -ipc.on('open-error-dialog', function (event) { +ipcMain.on('open-error-dialog', (event) => { dialog.showErrorBox('An Error Message', 'Demonstrating an error message.') }) diff --git a/main-process/native-ui/dialogs/information.js b/main-process/native-ui/dialogs/information.js index 4b1c2359..5054a1d7 100644 --- a/main-process/native-ui/dialogs/information.js +++ b/main-process/native-ui/dialogs/information.js @@ -1,14 +1,13 @@ -const ipc = require('electron').ipcMain -const dialog = require('electron').dialog +const {ipcMain, dialog} = require('electron') -ipc.on('open-information-dialog', function (event) { +ipcMain.on('open-information-dialog', (event) => { const options = { type: 'info', title: 'Information', message: "This is an information dialog. Isn't it nice?", buttons: ['Yes', 'No'] } - dialog.showMessageBox(options, function (index) { + dialog.showMessageBox(options, (index) => { event.sender.send('information-dialog-selection', index) }) }) diff --git a/main-process/native-ui/dialogs/open-file.js b/main-process/native-ui/dialogs/open-file.js index 4af47ba3..1aaf375a 100644 --- a/main-process/native-ui/dialogs/open-file.js +++ b/main-process/native-ui/dialogs/open-file.js @@ -1,10 +1,11 @@ -const ipc = require('electron').ipcMain -const dialog = require('electron').dialog +const {ipcMain, dialog} = require('electron') -ipc.on('open-file-dialog', function (event) { +ipcMain.on('open-file-dialog', (event) => { dialog.showOpenDialog({ properties: ['openFile', 'openDirectory'] - }, function (files) { - if (files) event.sender.send('selected-directory', files) + }, (files) => { + if (files) { + event.sender.send('selected-directory', files) + } }) }) diff --git a/main-process/native-ui/dialogs/save.js b/main-process/native-ui/dialogs/save.js index bba2b5bc..b10ed3f9 100644 --- a/main-process/native-ui/dialogs/save.js +++ b/main-process/native-ui/dialogs/save.js @@ -1,14 +1,13 @@ -const ipc = require('electron').ipcMain -const dialog = require('electron').dialog +const {ipcMain, dialog} = require('electron') -ipc.on('save-dialog', function (event) { +ipcMain.on('save-dialog', (event) => { const options = { title: 'Save an Image', filters: [ { name: 'Images', extensions: ['jpg', 'png', 'gif'] } ] } - dialog.showSaveDialog(options, function (filename) { + dialog.showSaveDialog(options, (filename) => { event.sender.send('saved-file', filename) }) }) diff --git a/main-process/native-ui/tray/tray.js b/main-process/native-ui/tray/tray.js index 1a040f55..f43dff2e 100644 --- a/main-process/native-ui/tray/tray.js +++ b/main-process/native-ui/tray/tray.js @@ -1,30 +1,28 @@ const path = require('path') -const electron = require('electron') -const ipc = electron.ipcMain -const app = electron.app -const Menu = electron.Menu -const Tray = electron.Tray +const {ipcMain, app, Menu, Tray} = require('electron') let appIcon = null -ipc.on('put-in-tray', function (event) { +ipcMain.on('put-in-tray', (event) => { const iconName = process.platform === 'win32' ? 'windows-icon.png' : 'iconTemplate.png' const iconPath = path.join(__dirname, iconName) appIcon = new Tray(iconPath) + const contextMenu = Menu.buildFromTemplate([{ label: 'Remove', - click: function () { + click: () => { event.sender.send('tray-removed') } }]) + appIcon.setToolTip('Electron Demo in the tray.') appIcon.setContextMenu(contextMenu) }) -ipc.on('remove-tray', function () { +ipcMain.on('remove-tray', () => { appIcon.destroy() }) -app.on('window-all-closed', function () { +app.on('window-all-closed', () => { if (appIcon) appIcon.destroy() }) diff --git a/main-process/system/app-information.js b/main-process/system/app-information.js index a40318bf..6b3290d6 100644 --- a/main-process/system/app-information.js +++ b/main-process/system/app-information.js @@ -1,6 +1,5 @@ -const app = require('electron').app -const ipc = require('electron').ipcMain +const {app, ipcMain} = require('electron') -ipc.on('get-app-path', function (event) { +ipcMain.on('get-app-path', (event) => { event.sender.send('got-app-path', app.getAppPath()) }) diff --git a/main-process/system/protocol-handler.js b/main-process/system/protocol-handler.js index daae5851..77226856 100644 --- a/main-process/system/protocol-handler.js +++ b/main-process/system/protocol-handler.js @@ -1,8 +1,7 @@ -const app = require('electron').app -const dialog = require('electron').dialog +const {app, dialog} = require('electron') app.setAsDefaultProtocolClient('electron-api-demos') -app.on('open-url', function (event, url) { +app.on('open-url', (event, url) => { dialog.showErrorBox('Welcome Back', `You arrived from: ${url}`) }) From 5f6e99f1b93e848f0ebb3b3bb8480a10b5fb8412 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 15 Feb 2018 20:03:42 -0500 Subject: [PATCH 20/91] update renderer process files --- renderer-process/communication/async-msg.js | 8 ++++---- .../communication/invisible-msg.js | 16 ++++++++++------ renderer-process/communication/sync-msg.js | 6 +++--- renderer-process/media/desktop-capturer.js | 18 ++++++++---------- renderer-process/media/pdf.js | 8 ++++---- renderer-process/menus/context-menu.js | 7 ++++--- renderer-process/native-ui/dialogs/error.js | 6 +++--- .../native-ui/dialogs/information.js | 8 ++++---- .../native-ui/dialogs/open-file.js | 8 ++++---- renderer-process/native-ui/dialogs/save.js | 8 ++++---- .../ex-links-file-manager/ex-links.js | 4 ++-- .../ex-links-file-manager/file-manager.js | 5 ++--- .../notifications/advanced-notification.js | 2 +- .../notifications/basic-notification.js | 3 ++- renderer-process/system/app-information.js | 8 ++++---- renderer-process/system/copy.js | 4 ++-- renderer-process/system/paste.js | 4 ++-- renderer-process/system/protocol-handler.js | 5 ++--- renderer-process/system/screen-information.js | 6 +++--- renderer-process/system/sys-information.js | 2 +- renderer-process/system/version-information.js | 2 +- renderer-process/windows/create-window.js | 7 ++++--- renderer-process/windows/frameless-window.js | 7 ++++--- renderer-process/windows/manage-window.js | 8 +++++--- renderer-process/windows/process-crash.js | 13 ++++++------- renderer-process/windows/process-hang.js | 13 ++++++------- .../windows/using-window-events.js | 18 ++++++++++-------- 27 files changed, 105 insertions(+), 99 deletions(-) diff --git a/renderer-process/communication/async-msg.js b/renderer-process/communication/async-msg.js index e5628eed..86c56dea 100644 --- a/renderer-process/communication/async-msg.js +++ b/renderer-process/communication/async-msg.js @@ -1,12 +1,12 @@ -const ipc = require('electron').ipcRenderer +const {ipcRenderer} = require('electron') const asyncMsgBtn = document.getElementById('async-msg') -asyncMsgBtn.addEventListener('click', function () { - ipc.send('asynchronous-message', 'ping') +asyncMsgBtn.addEventListener('click', () => { + ipcRenderer.send('asynchronous-message', 'ping') }) -ipc.on('asynchronous-reply', function (event, arg) { +ipcRenderer.on('asynchronous-reply', (event, arg) => { const message = `Asynchronous message reply: ${arg}` document.getElementById('async-reply').innerHTML = message }) diff --git a/renderer-process/communication/invisible-msg.js b/renderer-process/communication/invisible-msg.js index 4078101b..e2e91972 100644 --- a/renderer-process/communication/invisible-msg.js +++ b/renderer-process/communication/invisible-msg.js @@ -1,23 +1,27 @@ -const BrowserWindow = require('electron').remote.BrowserWindow +const {BrowserWindow} = require('electron').remote const ipcRenderer = require('electron').ipcRenderer const path = require('path') const invisMsgBtn = document.getElementById('invis-msg') const invisReply = document.getElementById('invis-reply') -invisMsgBtn.addEventListener('click', function (clickEvent) { +invisMsgBtn.addEventListener('click', (clickEvent) => { const windowID = BrowserWindow.getFocusedWindow().id - const invisPath = 'file://' + path.join(__dirname, '../../sections/communication/invisible.html') - let win = new BrowserWindow({ width: 400, height: 400, show: false }) + const invisPath = `file://${path.join(__dirname, '../../sections/communication/invisible.html')}` + let win = new BrowserWindow({ + width: 400, + height: 400, + show: false + }) win.loadURL(invisPath) - win.webContents.on('did-finish-load', function () { + win.webContents.on('did-finish-load', () => { const input = 100 win.webContents.send('compute-factorial', input, windowID) }) }) -ipcRenderer.on('factorial-computed', function (event, input, output) { +ipcRenderer.on('factorial-computed', (event, input, output) => { const message = `The factorial of ${input} is ${output}` invisReply.textContent = message }) diff --git a/renderer-process/communication/sync-msg.js b/renderer-process/communication/sync-msg.js index 8c665d82..137784c6 100644 --- a/renderer-process/communication/sync-msg.js +++ b/renderer-process/communication/sync-msg.js @@ -1,9 +1,9 @@ -const ipc = require('electron').ipcRenderer +const {ipcRenderer} = require('electron') const syncMsgBtn = document.getElementById('sync-msg') -syncMsgBtn.addEventListener('click', function () { - const reply = ipc.sendSync('synchronous-message', 'ping') +syncMsgBtn.addEventListener('click', () => { + const reply = ipcRenderer.sendSync('synchronous-message', 'ping') const message = `Synchronous message reply: ${reply}` document.getElementById('sync-reply').innerHTML = message }) diff --git a/renderer-process/media/desktop-capturer.js b/renderer-process/media/desktop-capturer.js index b0873209..f157f7f0 100644 --- a/renderer-process/media/desktop-capturer.js +++ b/renderer-process/media/desktop-capturer.js @@ -1,7 +1,4 @@ -const electron = require('electron') -const desktopCapturer = electron.desktopCapturer -const electronScreen = electron.screen -const shell = electron.shell +const {desktopCapturer, screen, shell} = require('electron') const fs = require('fs') const os = require('os') @@ -10,21 +7,22 @@ const path = require('path') const screenshot = document.getElementById('screen-shot') const screenshotMsg = document.getElementById('screenshot-path') -screenshot.addEventListener('click', function (event) { +screenshot.addEventListener('click', (event) => { screenshotMsg.textContent = 'Gathering screens...' const thumbSize = determineScreenShotSize() let options = { types: ['screen'], thumbnailSize: thumbSize } - desktopCapturer.getSources(options, function (error, sources) { + desktopCapturer.getSources(options, (error, sources) => { if (error) return console.log(error) - sources.forEach(function (source) { + sources.forEach((source) => { if (source.name === 'Entire screen' || source.name === 'Screen 1') { const screenshotPath = path.join(os.tmpdir(), 'screenshot.png') - fs.writeFile(screenshotPath, source.thumbnail.toPng(), function (error) { + fs.writeFile(screenshotPath, source.thumbnail.toPng(), (error) => { if (error) return console.log(error) - shell.openExternal('file://' + screenshotPath) + shell.openExternal(`file://${screenshotPath}`) + const message = `Saved screenshot to: ${screenshotPath}` screenshotMsg.textContent = message }) @@ -34,7 +32,7 @@ screenshot.addEventListener('click', function (event) { }) function determineScreenShotSize () { - const screenSize = electronScreen.getPrimaryDisplay().workAreaSize + const screenSize = screen.getPrimaryDisplay().workAreaSize const maxDimension = Math.max(screenSize.width, screenSize.height) return { width: maxDimension * window.devicePixelRatio, diff --git a/renderer-process/media/pdf.js b/renderer-process/media/pdf.js index ed4c143a..a3f32715 100644 --- a/renderer-process/media/pdf.js +++ b/renderer-process/media/pdf.js @@ -1,12 +1,12 @@ -const ipc = require('electron').ipcRenderer +const {ipcRenderer} = require('electron') const printPDFBtn = document.getElementById('print-pdf') -printPDFBtn.addEventListener('click', function (event) { - ipc.send('print-to-pdf') +printPDFBtn.addEventListener('click', (event) => { + ipcRenderer.send('print-to-pdf') }) -ipc.on('wrote-pdf', function (event, path) { +ipcRenderer.on('wrote-pdf', (event, path) => { const message = `Wrote PDF to: ${path}` document.getElementById('pdf-path').innerHTML = message }) diff --git a/renderer-process/menus/context-menu.js b/renderer-process/menus/context-menu.js index ff05fc1b..66a22f31 100644 --- a/renderer-process/menus/context-menu.js +++ b/renderer-process/menus/context-menu.js @@ -1,7 +1,8 @@ -const ipc = require('electron').ipcRenderer +const {ipcRenderer} = require('electron') // Tell main process to show the menu when demo button is clicked const contextMenuBtn = document.getElementById('context-menu') -contextMenuBtn.addEventListener('click', function () { - ipc.send('show-context-menu') + +contextMenuBtn.addEventListener('click', () => { + ipcRenderer.send('show-context-menu') }) diff --git a/renderer-process/native-ui/dialogs/error.js b/renderer-process/native-ui/dialogs/error.js index 3f3a87dd..7af45af4 100644 --- a/renderer-process/native-ui/dialogs/error.js +++ b/renderer-process/native-ui/dialogs/error.js @@ -1,7 +1,7 @@ -const ipc = require('electron').ipcRenderer +const {ipcRenderer} = require('electron') const errorBtn = document.getElementById('error-dialog') -errorBtn.addEventListener('click', function (event) { - ipc.send('open-error-dialog') +errorBtn.addEventListener('click', (event) => { + ipcRenderer.send('open-error-dialog') }) diff --git a/renderer-process/native-ui/dialogs/information.js b/renderer-process/native-ui/dialogs/information.js index a180bb4f..270f71cc 100644 --- a/renderer-process/native-ui/dialogs/information.js +++ b/renderer-process/native-ui/dialogs/information.js @@ -1,12 +1,12 @@ -const ipc = require('electron').ipcRenderer +const {ipcRenderer} = require('electron') const informationBtn = document.getElementById('information-dialog') -informationBtn.addEventListener('click', function (event) { - ipc.send('open-information-dialog') +informationBtn.addEventListener('click', (event) => { + ipcRenderer.send('open-information-dialog') }) -ipc.on('information-dialog-selection', function (event, index) { +ipcRenderer.on('information-dialog-selection', (event, index) => { let message = 'You selected ' if (index === 0) message += 'yes.' else message += 'no.' diff --git a/renderer-process/native-ui/dialogs/open-file.js b/renderer-process/native-ui/dialogs/open-file.js index 89ebecfc..e152093f 100644 --- a/renderer-process/native-ui/dialogs/open-file.js +++ b/renderer-process/native-ui/dialogs/open-file.js @@ -1,11 +1,11 @@ -const ipc = require('electron').ipcRenderer +const {ipcRenderer} = require('electron') const selectDirBtn = document.getElementById('select-directory') -selectDirBtn.addEventListener('click', function (event) { - ipc.send('open-file-dialog') +selectDirBtn.addEventListener('click', (event) => { + ipcRenderer.send('open-file-dialog') }) -ipc.on('selected-directory', function (event, path) { +ipcRenderer.on('selected-directory', (event, path) => { document.getElementById('selected-file').innerHTML = `You selected: ${path}` }) diff --git a/renderer-process/native-ui/dialogs/save.js b/renderer-process/native-ui/dialogs/save.js index 2600ba3c..fb79553f 100644 --- a/renderer-process/native-ui/dialogs/save.js +++ b/renderer-process/native-ui/dialogs/save.js @@ -1,12 +1,12 @@ -const ipc = require('electron').ipcRenderer +const {ipcRenderer} = require('electron') const saveBtn = document.getElementById('save-dialog') -saveBtn.addEventListener('click', function (event) { - ipc.send('save-dialog') +saveBtn.addEventListener('click', (event) => { + ipcRenderer.send('save-dialog') }) -ipc.on('saved-file', function (event, path) { +ipcRenderer.on('saved-file', (event, path) => { if (!path) path = 'No path' document.getElementById('file-saved').innerHTML = `Path selected: ${path}` }) diff --git a/renderer-process/native-ui/ex-links-file-manager/ex-links.js b/renderer-process/native-ui/ex-links-file-manager/ex-links.js index d9185daf..74d9fdf1 100644 --- a/renderer-process/native-ui/ex-links-file-manager/ex-links.js +++ b/renderer-process/native-ui/ex-links-file-manager/ex-links.js @@ -1,7 +1,7 @@ -const shell = require('electron').shell +const {shell} = require('electron') const exLinksBtn = document.getElementById('open-ex-links') -exLinksBtn.addEventListener('click', function (event) { +exLinksBtn.addEventListener('click', (event) => { shell.openExternal('http://electron.atom.io/') }) diff --git a/renderer-process/native-ui/ex-links-file-manager/file-manager.js b/renderer-process/native-ui/ex-links-file-manager/file-manager.js index 9371de0b..b97e7631 100644 --- a/renderer-process/native-ui/ex-links-file-manager/file-manager.js +++ b/renderer-process/native-ui/ex-links-file-manager/file-manager.js @@ -1,9 +1,8 @@ -const shell = require('electron').shell - +const {shell} = require('electron') const os = require('os') const fileManagerBtn = document.getElementById('open-file-manager') -fileManagerBtn.addEventListener('click', function (event) { +fileManagerBtn.addEventListener('click', (event) => { shell.showItemInFolder(os.homedir()) }) diff --git a/renderer-process/native-ui/notifications/advanced-notification.js b/renderer-process/native-ui/notifications/advanced-notification.js index 7485a4c4..7bed362d 100644 --- a/renderer-process/native-ui/notifications/advanced-notification.js +++ b/renderer-process/native-ui/notifications/advanced-notification.js @@ -7,7 +7,7 @@ const notification = { } const notificationButton = document.getElementById('advanced-noti') -notificationButton.addEventListener('click', function () { +notificationButton.addEventListener('click', () => { const myNotification = new window.Notification(notification.title, notification) myNotification.onclick = () => { diff --git a/renderer-process/native-ui/notifications/basic-notification.js b/renderer-process/native-ui/notifications/basic-notification.js index a2358363..a46583c6 100644 --- a/renderer-process/native-ui/notifications/basic-notification.js +++ b/renderer-process/native-ui/notifications/basic-notification.js @@ -2,9 +2,10 @@ const notification = { title: 'Basic Notification', body: 'Short message part' } + const notificationButton = document.getElementById('basic-noti') -notificationButton.addEventListener('click', function () { +notificationButton.addEventListener('click', () => { const myNotification = new window.Notification(notification.title, notification) myNotification.onclick = () => { diff --git a/renderer-process/system/app-information.js b/renderer-process/system/app-information.js index 47689906..9e402e9c 100644 --- a/renderer-process/system/app-information.js +++ b/renderer-process/system/app-information.js @@ -1,12 +1,12 @@ -const ipc = require('electron').ipcRenderer +const {ipcRenderer} = require('electron') const appInfoBtn = document.getElementById('app-info') -appInfoBtn.addEventListener('click', function () { - ipc.send('get-app-path') +appInfoBtn.addEventListener('click', () => { + ipcRenderer.send('get-app-path') }) -ipc.on('got-app-path', function (event, path) { +ipcRenderer.on('got-app-path', (event, path) => { const message = `This app is located at: ${path}` document.getElementById('got-app-info').innerHTML = message }) diff --git a/renderer-process/system/copy.js b/renderer-process/system/copy.js index aa20a86a..1ee1a335 100644 --- a/renderer-process/system/copy.js +++ b/renderer-process/system/copy.js @@ -1,9 +1,9 @@ -const clipboard = require('electron').clipboard +const {clipboard} = require('electron') const copyBtn = document.getElementById('copy-to') const copyInput = document.getElementById('copy-to-input') -copyBtn.addEventListener('click', function () { +copyBtn.addEventListener('click', () => { if (copyInput.value !== '') copyInput.value = '' copyInput.placeholder = 'Copied! Paste here to see.' clipboard.writeText('Electron Demo!') diff --git a/renderer-process/system/paste.js b/renderer-process/system/paste.js index 4be12485..9725e2c0 100644 --- a/renderer-process/system/paste.js +++ b/renderer-process/system/paste.js @@ -1,8 +1,8 @@ -const clipboard = require('electron').clipboard +const {clipboard} = require('electron') const pasteBtn = document.getElementById('paste-to') -pasteBtn.addEventListener('click', function () { +pasteBtn.addEventListener('click', () => { clipboard.writeText('What a demo!') const message = `Clipboard contents: ${clipboard.readText()}` document.getElementById('paste-from').innerHTML = message diff --git a/renderer-process/system/protocol-handler.js b/renderer-process/system/protocol-handler.js index b59f9fe0..2d831db7 100644 --- a/renderer-process/system/protocol-handler.js +++ b/renderer-process/system/protocol-handler.js @@ -1,10 +1,9 @@ -const shell = require('electron').shell - +const {shell} = require('electron') const path = require('path') const protocolHandlerBtn = document.getElementById('protocol-handler') -protocolHandlerBtn.addEventListener('click', function () { +protocolHandlerBtn.addEventListener('click', () => { const pageDirectory = __dirname.replace('app.asar', 'app.asar.unpacked') const pagePath = path.join('file://', pageDirectory, '../../sections/system/protocol-link.html') shell.openExternal(pagePath) diff --git a/renderer-process/system/screen-information.js b/renderer-process/system/screen-information.js index b7d38d27..08de1b9a 100644 --- a/renderer-process/system/screen-information.js +++ b/renderer-process/system/screen-information.js @@ -1,9 +1,9 @@ -const electronScreen = require('electron').screen +const {screen} = require('electron') const screenInfoBtn = document.getElementById('screen-info') -const size = electronScreen.getPrimaryDisplay().size +const size = screen.getPrimaryDisplay().size -screenInfoBtn.addEventListener('click', function () { +screenInfoBtn.addEventListener('click', () => { const message = `Your screen is: ${size.width}px x ${size.height}px` document.getElementById('got-screen-info').innerHTML = message }) diff --git a/renderer-process/system/sys-information.js b/renderer-process/system/sys-information.js index bfe96884..1da9f46a 100644 --- a/renderer-process/system/sys-information.js +++ b/renderer-process/system/sys-information.js @@ -3,7 +3,7 @@ const homeDir = os.homedir() const sysInfoBtn = document.getElementById('sys-info') -sysInfoBtn.addEventListener('click', function () { +sysInfoBtn.addEventListener('click', () => { const message = `Your system home directory is: ${homeDir}` document.getElementById('got-sys-info').innerHTML = message }) diff --git a/renderer-process/system/version-information.js b/renderer-process/system/version-information.js index 378eae27..40f7f2cf 100644 --- a/renderer-process/system/version-information.js +++ b/renderer-process/system/version-information.js @@ -2,7 +2,7 @@ const versionInfoBtn = document.getElementById('version-info') const electronVersion = process.versions.electron -versionInfoBtn.addEventListener('click', function () { +versionInfoBtn.addEventListener('click', () => { const message = `This app is using Electron version: ${electronVersion}` document.getElementById('got-version-info').innerHTML = message }) diff --git a/renderer-process/windows/create-window.js b/renderer-process/windows/create-window.js index 0572b443..105a1993 100644 --- a/renderer-process/windows/create-window.js +++ b/renderer-process/windows/create-window.js @@ -1,12 +1,13 @@ -const BrowserWindow = require('electron').remote.BrowserWindow +const {BrowserWindow} = require('electron').remote const path = require('path') const newWindowBtn = document.getElementById('new-window') -newWindowBtn.addEventListener('click', function (event) { +newWindowBtn.addEventListener('click', (event) => { const modalPath = path.join('file://', __dirname, '../../sections/windows/modal.html') let win = new BrowserWindow({ width: 400, height: 320 }) - win.on('close', function () { win = null }) + + win.on('close', () => { win = null }) win.loadURL(modalPath) win.show() }) diff --git a/renderer-process/windows/frameless-window.js b/renderer-process/windows/frameless-window.js index 70ee8be0..4c67e33a 100644 --- a/renderer-process/windows/frameless-window.js +++ b/renderer-process/windows/frameless-window.js @@ -1,12 +1,13 @@ -const BrowserWindow = require('electron').remote.BrowserWindow +const {BrowserWindow} = require('electron').remote const newWindowBtn = document.getElementById('frameless-window') const path = require('path') -newWindowBtn.addEventListener('click', function (event) { +newWindowBtn.addEventListener('click', (event) => { const modalPath = path.join('file://', __dirname, '../../sections/windows/modal.html') let win = new BrowserWindow({ frame: false }) - win.on('close', function () { win = null }) + + win.on('close', () => { win = null }) win.loadURL(modalPath) win.show() }) diff --git a/renderer-process/windows/manage-window.js b/renderer-process/windows/manage-window.js index 30252afa..06b8c97e 100644 --- a/renderer-process/windows/manage-window.js +++ b/renderer-process/windows/manage-window.js @@ -1,17 +1,19 @@ -const BrowserWindow = require('electron').remote.BrowserWindow +const {BrowserWindow} = require('electron').remote const path = require('path') const manageWindowBtn = document.getElementById('manage-window') let win -manageWindowBtn.addEventListener('click', function (event) { +manageWindowBtn.addEventListener('click', (event) => { const modalPath = path.join('file://', __dirname, '../../sections/windows/manage-modal.html') win = new BrowserWindow({ width: 400, height: 275 }) + win.on('resize', updateReply) win.on('move', updateReply) - win.on('close', function () { win = null }) + win.on('close', () => { win = null }) win.loadURL(modalPath) win.show() + function updateReply () { const manageWindowReply = document.getElementById('manage-window-reply') const message = `Size: ${win.getSize()} Position: ${win.getPosition()}` diff --git a/renderer-process/windows/process-crash.js b/renderer-process/windows/process-crash.js index 88866ca2..b5dcdcbc 100644 --- a/renderer-process/windows/process-crash.js +++ b/renderer-process/windows/process-crash.js @@ -1,28 +1,27 @@ -const BrowserWindow = require('electron').remote.BrowserWindow -const dialog = require('electron').remote.dialog - +const {BrowserWindow, dialog} = require('electron').remote const path = require('path') const processCrashBtn = document.getElementById('process-crash') -processCrashBtn.addEventListener('click', function (event) { +processCrashBtn.addEventListener('click', (event) => { const crashWinPath = path.join('file://', __dirname, '../../sections/windows/process-crash.html') let win = new BrowserWindow({ width: 400, height: 320 }) - win.webContents.on('crashed', function () { + win.webContents.on('crashed', () => { const options = { type: 'info', title: 'Renderer Process Crashed', message: 'This process has crashed.', buttons: ['Reload', 'Close'] } - dialog.showMessageBox(options, function (index) { + + dialog.showMessageBox(options, (index) => { if (index === 0) win.reload() else win.close() }) }) - win.on('close', function () { win = null }) + win.on('close', () => { win = null }) win.loadURL(crashWinPath) win.show() }) diff --git a/renderer-process/windows/process-hang.js b/renderer-process/windows/process-hang.js index 609d17c0..9078d010 100644 --- a/renderer-process/windows/process-hang.js +++ b/renderer-process/windows/process-hang.js @@ -1,28 +1,27 @@ -const BrowserWindow = require('electron').remote.BrowserWindow -const dialog = require('electron').remote.dialog - +const {BrowserWindow, dialog} = require('electron').remote const path = require('path') const processHangBtn = document.getElementById('process-hang') -processHangBtn.addEventListener('click', function (event) { +processHangBtn.addEventListener('click', (event) => { const hangWinPath = path.join('file://', __dirname, '../../sections/windows/process-hang.html') let win = new BrowserWindow({ width: 400, height: 320 }) - win.on('unresponsive', function () { + win.on('unresponsive', () => { const options = { type: 'info', title: 'Renderer Process Hanging', message: 'This process is hanging.', buttons: ['Reload', 'Close'] } - dialog.showMessageBox(options, function (index) { + + dialog.showMessageBox(options, (index) => { if (index === 0) win.reload() else win.close() }) }) - win.on('close', function () { win = null }) + win.on('close', () => { win = null }) win.loadURL(hangWinPath) win.show() }) diff --git a/renderer-process/windows/using-window-events.js b/renderer-process/windows/using-window-events.js index 9cfb9971..a98c50b0 100644 --- a/renderer-process/windows/using-window-events.js +++ b/renderer-process/windows/using-window-events.js @@ -1,33 +1,35 @@ -const BrowserWindow = require('electron').remote.BrowserWindow +const {BrowserWindow} = require('electron').remote const path = require('path') const manageWindowBtn = document.getElementById('listen-to-window') const focusModalBtn = document.getElementById('focus-on-modal-window') let win -manageWindowBtn.addEventListener('click', function () { +manageWindowBtn.addEventListener('click', () => { const modalPath = path.join('file://', __dirname, '../../sections/windows/modal-toggle-visibility.html') win = new BrowserWindow({ width: 600, height: 400 }) + win.on('focus', hideFocusBtn) win.on('blur', showFocusBtn) - win.on('close', function () { + win.on('close', () => { hideFocusBtn() win = null }) win.loadURL(modalPath) win.show() - function showFocusBtn (btn) { + + const showFocusBtn = (btn) => { if (!win) return focusModalBtn.classList.add('smooth-appear') focusModalBtn.classList.remove('disappear') focusModalBtn.addEventListener('click', clickHandler) } - function hideFocusBtn () { + + const hideFocusBtn = () => { focusModalBtn.classList.add('disappear') focusModalBtn.classList.remove('smooth-appear') focusModalBtn.removeEventListener('click', clickHandler) } - function clickHandler () { - win.focus() - } + + const clickHandler = () => { win.focus() } }) From 5a9277309c0b1f79824463c136fa2b6ddb475ce7 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 19 Feb 2018 08:05:11 -0600 Subject: [PATCH 21/91] bump electron devDependencies to 1.8.2 (#349) now that we have a stable 1.8.x version in npm, bump our dependency from to 1.8.x --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0e338591..a10c4970 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "chai-as-promised": "^6.0.0", "check-for-leaks": "^1.2.0", "devtron": "^1.3.0", - "electron": "~1.6.2", + "electron": "~1.8.2", "electron-packager": "^8.6.0", "electron-winstaller": "^2.2.0", "husky": "^0.14.3", @@ -58,4 +58,4 @@ "mocha": true } } -} \ No newline at end of file +} From deb18c4ad601791f7ab784aaeec07d4f611b3275 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 16 Mar 2018 21:17:08 +0900 Subject: [PATCH 22/91] Fix screenshot demo It was crashing on undefined 'NativeImage.toPng()', was deprecated (new version is NativeImage.toPNG()) in 1.7 and removed in 2.0. --- renderer-process/media/desktop-capturer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/renderer-process/media/desktop-capturer.js b/renderer-process/media/desktop-capturer.js index f157f7f0..4b5faff7 100644 --- a/renderer-process/media/desktop-capturer.js +++ b/renderer-process/media/desktop-capturer.js @@ -19,7 +19,7 @@ screenshot.addEventListener('click', (event) => { if (source.name === 'Entire screen' || source.name === 'Screen 1') { const screenshotPath = path.join(os.tmpdir(), 'screenshot.png') - fs.writeFile(screenshotPath, source.thumbnail.toPng(), (error) => { + fs.writeFile(screenshotPath, source.thumbnail.toPNG(), (error) => { if (error) return console.log(error) shell.openExternal(`file://${screenshotPath}`) From bd618080fb54dd67102041b0ad03e0d4f36c15f9 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 21 Mar 2018 10:08:13 -0400 Subject: [PATCH 23/91] move function declaration to fix Focus on Demo button error --- .../windows/using-window-events.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/renderer-process/windows/using-window-events.js b/renderer-process/windows/using-window-events.js index a98c50b0..34a1991c 100644 --- a/renderer-process/windows/using-window-events.js +++ b/renderer-process/windows/using-window-events.js @@ -9,14 +9,11 @@ manageWindowBtn.addEventListener('click', () => { const modalPath = path.join('file://', __dirname, '../../sections/windows/modal-toggle-visibility.html') win = new BrowserWindow({ width: 600, height: 400 }) - win.on('focus', hideFocusBtn) - win.on('blur', showFocusBtn) - win.on('close', () => { - hideFocusBtn() - win = null - }) - win.loadURL(modalPath) - win.show() + const hideFocusBtn = () => { + focusModalBtn.classList.add('disappear') + focusModalBtn.classList.remove('smooth-appear') + focusModalBtn.removeEventListener('click', clickHandler) + } const showFocusBtn = (btn) => { if (!win) return @@ -25,11 +22,14 @@ manageWindowBtn.addEventListener('click', () => { focusModalBtn.addEventListener('click', clickHandler) } - const hideFocusBtn = () => { - focusModalBtn.classList.add('disappear') - focusModalBtn.classList.remove('smooth-appear') - focusModalBtn.removeEventListener('click', clickHandler) - } + win.on('focus', hideFocusBtn) + win.on('blur', showFocusBtn) + win.on('close', () => { + hideFocusBtn() + win = null + }) + win.loadURL(modalPath) + win.show() const clickHandler = () => { win.focus() } }) From d9005b34890686577bb81ee22d994e360f969dc1 Mon Sep 17 00:00:00 2001 From: ME!!!!!!!! Date: Tue, 17 Apr 2018 21:36:44 +1000 Subject: [PATCH 24/91] =?UTF-8?q?Heart=20=E2=99=A5=20(#360)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Chang the heart in icons.svg to make it look nicer --- assets/img/icons.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/img/icons.svg b/assets/img/icons.svg index d1a2c5f6..e41b557c 100644 --- a/assets/img/icons.svg +++ b/assets/img/icons.svg @@ -12,7 +12,7 @@ - + From f0b0b38aa72201569c311b2901cac26601cf53f6 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 7 May 2018 13:36:18 -0700 Subject: [PATCH 25/91] update package.json for 2.0.0 (#365) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a10c4970..8db3e42a 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "chai-as-promised": "^6.0.0", "check-for-leaks": "^1.2.0", "devtron": "^1.3.0", - "electron": "~1.8.2", + "electron": "^2.0.0", "electron-packager": "^8.6.0", "electron-winstaller": "^2.2.0", "husky": "^0.14.3", From b09a3ebf1b1485a431045ec36634b6fd30348c24 Mon Sep 17 00:00:00 2001 From: Celeste Date: Thu, 10 May 2018 15:34:49 -0700 Subject: [PATCH 26/91] Add dragging files demo (#356) * Add main and renderer process drag js in native-ui * Add drag html file & drag section to index.html * Add icon file extension * Update number of demos in tests --- index.html | 2 ++ main-process/native-ui/drag/codeIcon.png | Bin 0 -> 6339 bytes main-process/native-ui/drag/drag.js | 10 ++++++ renderer-process/native-ui/drag/drag.js | 8 +++++ sections/native-ui/drag.html | 42 +++++++++++++++++++++++ test/index.js | 4 +-- 6 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 main-process/native-ui/drag/codeIcon.png create mode 100644 main-process/native-ui/drag/drag.js create mode 100644 renderer-process/native-ui/drag/drag.js create mode 100644 sections/native-ui/drag.html diff --git a/index.html b/index.html index 1d8ba42b..7d76cb85 100644 --- a/index.html +++ b/index.html @@ -21,6 +21,7 @@ + @@ -62,6 +63,7 @@