From aa02f272e3a3c8b17fef48c683f4c4ac878bcd51 Mon Sep 17 00:00:00 2001 From: Daniel Andrei Date: Wed, 13 Feb 2019 15:51:03 +0200 Subject: [PATCH 01/19] Handle initial network connectivity --- package-lock.json | 405 ++++++++++++++++++++++++++++++++++++++++------ package.json | 4 +- source/index.ts | 14 ++ 3 files changed, 372 insertions(+), 51 deletions(-) diff --git a/package-lock.json b/package-lock.json index ef74c0a48..1b5635fb8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -226,8 +226,7 @@ "@sindresorhus/is": { "version": "0.14.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz", - "integrity": "sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ==", - "dev": true + "integrity": "sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ==" }, "@sindresorhus/tsconfig": { "version": "0.2.0", @@ -239,7 +238,6 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-1.1.2.tgz", "integrity": "sha512-XIB2XbzHTN6ieIjfIMV9hlVcfPU26s2vafYWQcZHWXHOxiaRZYEDKEwdl129Zyg50+foYV2jCgtrqSA6qNuNSA==", - "dev": true, "requires": { "defer-to-connect": "^1.0.1" } @@ -268,6 +266,11 @@ "@types/p-cancelable": "*" } }, + "@types/is-online": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@types/is-online/-/is-online-8.0.0.tgz", + "integrity": "sha512-XMGpwXeIoASU3W9Gr5buzA4iFKZ/uJCf0M2M+s9N5WchvGbHfQO8Qw4qF4MwmUaa+Kj/xQShxRkj8GOq6ivLCg==" + }, "@types/node": { "version": "10.12.18", "resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.18.tgz", @@ -358,6 +361,22 @@ "integrity": "sha512-HJ7CfNHrfJLlNTzIEUTj43LNWGkqpRLxm3YjAlcD0ACydk9XynzYsCBHxut+iqt+1aBXkx9UP/w/ZqMr13XIzg==", "dev": true }, + "aggregate-error": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-1.0.0.tgz", + "integrity": "sha1-iINE2tAiCnLjr1CQYRf0h3GSX6w=", + "requires": { + "clean-stack": "^1.0.0", + "indent-string": "^3.0.0" + }, + "dependencies": { + "indent-string": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-3.2.0.tgz", + "integrity": "sha1-Sl/W0nzDMvN+VBmlBNu4NxBckok=" + } + } + }, "ajv": { "version": "6.6.1", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.6.1.tgz", @@ -1021,7 +1040,6 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.0.0.tgz", "integrity": "sha512-2N7AmszH/WPPpl5Z3XMw1HAP+8d+xugnKQAeKvxFZ/04dbT/CAznqwbl+7eSr3HkwdepNwtb2yx3CAMQWvG01Q==", - "dev": true, "requires": { "clone-response": "^1.0.2", "get-stream": "^4.0.0", @@ -1036,7 +1054,6 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", - "dev": true, "requires": { "pump": "^3.0.0" } @@ -1204,6 +1221,11 @@ "escape-string-regexp": "^1.0.5" } }, + "clean-stack": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-1.3.0.tgz", + "integrity": "sha1-noIVAa6XmYbEax1m0tQy2y/UrjE=" + }, "cli-boxes": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/cli-boxes/-/cli-boxes-1.0.0.tgz", @@ -1308,7 +1330,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz", "integrity": "sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws=", - "dev": true, "requires": { "mimic-response": "^1.0.0" } @@ -1503,8 +1524,7 @@ "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", - "dev": true + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, "cosmiconfig": { "version": "5.0.7", @@ -1607,14 +1627,12 @@ "decode-uri-component": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz", - "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=", - "dev": true + "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=" }, "decompress-response": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz", "integrity": "sha1-gKTdMjdIOEv6JICDYirt7Jgq3/M=", - "dev": true, "requires": { "mimic-response": "^1.0.0" } @@ -1643,8 +1661,7 @@ "defer-to-connect": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-1.0.2.tgz", - "integrity": "sha512-k09hcQcTDY+cwgiwa6PYKLm3jlagNzQ+RSvhjzESOGOx+MNOuXkxTfEvPrO1IOQ81tArCFYQgi631clB70RpQw==", - "dev": true + "integrity": "sha512-k09hcQcTDY+cwgiwa6PYKLm3jlagNzQ+RSvhjzESOGOx+MNOuXkxTfEvPrO1IOQ81tArCFYQgi631clB70RpQw==" }, "define-property": { "version": "2.0.2", @@ -1777,6 +1794,23 @@ } } }, + "dns-packet": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-1.3.1.tgz", + "integrity": "sha512-0UxfQkMhYAUaZI+xrNZOz/as5KgDU0M/fQ9b6SpkyLbk3GEswDi6PADJVaYJradtRVsRIlF1zLyOodbcTCDzUg==", + "requires": { + "ip": "^1.1.0", + "safe-buffer": "^5.0.1" + } + }, + "dns-socket": { + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/dns-socket/-/dns-socket-1.6.3.tgz", + "integrity": "sha512-/mUy3VGqIP69dAZjh2xxHXcpK9wk2Len1Dxz8mWAdrIgFC8tnR/aQAyU4a+UTXzOcTvEvGBdp1zFiwnpWKaXng==", + "requires": { + "dns-packet": "^1.1.0" + } + }, "doctrine": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", @@ -1852,8 +1886,7 @@ "duplexer3": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz", - "integrity": "sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI=", - "dev": true + "integrity": "sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI=" }, "ecc-jsbn": { "version": "0.1.2", @@ -2191,7 +2224,6 @@ "version": "1.4.1", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz", "integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==", - "dev": true, "requires": { "once": "^1.4.0" } @@ -3246,6 +3278,44 @@ "map-cache": "^0.2.2" } }, + "from2": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/from2/-/from2-2.3.0.tgz", + "integrity": "sha1-i/tVAr3kpNNs/e6gB/zKIdfjgq8=", + "requires": { + "inherits": "^2.0.1", + "readable-stream": "^2.0.0" + }, + "dependencies": { + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + }, + "readable-stream": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "requires": { + "safe-buffer": "~5.1.0" + } + } + } + }, "fs-extra": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", @@ -3303,8 +3373,7 @@ "get-stream": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", - "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=", - "dev": true + "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=" }, "get-value": { "version": "2.0.6", @@ -3522,6 +3591,19 @@ "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" }, + "has-symbol-support-x": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/has-symbol-support-x/-/has-symbol-support-x-1.4.2.tgz", + "integrity": "sha512-3ToOva++HaW+eCpgqZrCfN51IPB+7bJNVT6CUATzueB5Heb8o6Nam0V3HG5dlDvZU1Gn5QLcbahiKw/XVk5JJw==" + }, + "has-to-string-tag-x": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/has-to-string-tag-x/-/has-to-string-tag-x-1.4.1.tgz", + "integrity": "sha512-vdbKfmw+3LoOYVr+mtxHaX5a96+0f3DljYd8JOqvOLsf5mw2Otda2qCDT9qRqLAhrjyQ0h7ual5nOiASpsGNFw==", + "requires": { + "has-symbol-support-x": "^1.4.1" + } + }, "has-value": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/has-value/-/has-value-1.0.0.tgz", @@ -3616,8 +3698,7 @@ "http-cache-semantics": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.0.2.tgz", - "integrity": "sha512-laeSTWIkuFa6lUgZAt+ic9RwOSEwbi9VDQNcCvMFO4sZiDc2Ha8DaZVCJnfpLLQCcS8rvCnIWYmz0POLxt7Dew==", - "dev": true + "integrity": "sha512-laeSTWIkuFa6lUgZAt+ic9RwOSEwbi9VDQNcCvMFO4sZiDc2Ha8DaZVCJnfpLLQCcS8rvCnIWYmz0POLxt7Dew==" }, "http-signature": { "version": "1.2.0", @@ -3904,12 +3985,31 @@ } } }, + "into-stream": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/into-stream/-/into-stream-3.1.0.tgz", + "integrity": "sha1-lvsKk2wSur1v8XUqF9BWFqvQlMY=", + "requires": { + "from2": "^2.1.1", + "p-is-promise": "^1.1.0" + } + }, "invert-kv": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", "integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA==", "dev": true }, + "ip": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz", + "integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo=" + }, + "ip-regex": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-2.1.0.tgz", + "integrity": "sha1-+ni/XS5pE8kRzp+BnuUUa7bYROk=" + }, "irregular-plurals": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/irregular-plurals/-/irregular-plurals-2.0.0.tgz", @@ -4107,6 +4207,14 @@ "is-path-inside": "^1.0.0" } }, + "is-ip": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-ip/-/is-ip-2.0.0.tgz", + "integrity": "sha1-aO6gfooKCpTC0IDdZ0xzGrKkYas=", + "requires": { + "ip-regex": "^2.0.0" + } + }, "is-js-type": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-js-type/-/is-js-type-2.0.0.tgz", @@ -4157,6 +4265,11 @@ "obj-props": "^1.0.0" } }, + "is-object": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-object/-/is-object-1.0.1.tgz", + "integrity": "sha1-iVJojF7C/9awPsyF52ngKQMINHA=" + }, "is-observable": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-observable/-/is-observable-1.1.0.tgz", @@ -4166,6 +4279,63 @@ "symbol-observable": "^1.1.0" } }, + "is-online": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/is-online/-/is-online-8.0.0.tgz", + "integrity": "sha512-SdDnDowk2Z/73ECJ8svSXuqJ2CJ6odoTV2whZ314SI5LM2ZE+g++ef9oxxNHr5D919tyKPaDFOdPMZmDupqiDA==", + "requires": { + "got": "^9.3.2", + "p-any": "^1.1.0", + "p-timeout": "^2.0.1", + "public-ip": "^2.4.0" + }, + "dependencies": { + "get-stream": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", + "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", + "requires": { + "pump": "^3.0.0" + } + }, + "got": { + "version": "9.6.0", + "resolved": "https://registry.npmjs.org/got/-/got-9.6.0.tgz", + "integrity": "sha512-R7eWptXuGYxwijs0eV+v3o6+XH1IqVK8dJOEecQfTmkncw9AV4dcw/Dhxi8MdlqPthxxpZyizMzyg8RTmEsG+Q==", + "requires": { + "@sindresorhus/is": "^0.14.0", + "@szmarczak/http-timer": "^1.1.2", + "cacheable-request": "^6.0.0", + "decompress-response": "^3.3.0", + "duplexer3": "^0.1.4", + "get-stream": "^4.1.0", + "lowercase-keys": "^1.0.1", + "mimic-response": "^1.0.1", + "p-cancelable": "^1.0.0", + "to-readable-stream": "^1.0.0", + "url-parse-lax": "^3.0.0" + } + }, + "p-cancelable": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.0.0.tgz", + "integrity": "sha512-USgPoaC6tkTGlS831CxsVdmZmyb8tR1D+hStI84MyckLOzfJlYQUweomrwE3D8T7u5u5GVuW064LT501wHTYYA==" + }, + "prepend-http": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz", + "integrity": "sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=" + }, + "url-parse-lax": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-3.0.0.tgz", + "integrity": "sha1-FrXK/Afb42dsGxmZF3gj1lA6yww=", + "requires": { + "prepend-http": "^2.0.0" + } + } + } + }, "is-path-cwd": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-1.0.0.tgz", @@ -4235,8 +4405,7 @@ "is-retry-allowed": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-retry-allowed/-/is-retry-allowed-1.1.0.tgz", - "integrity": "sha1-EaBgVotnM5REAz0BJaYaINVk+zQ=", - "dev": true + "integrity": "sha1-EaBgVotnM5REAz0BJaYaINVk+zQ=" }, "is-scoped": { "version": "1.0.0", @@ -4331,6 +4500,15 @@ "integrity": "sha512-flaQ/45dMqCYSMzBQI/h3bcto6T70uN7kjNnI8n3gQU6no5p+QcnMWBNXkraED0YvbUymxKaqdvgPa09RZQM5A==", "dev": true }, + "isurl": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isurl/-/isurl-1.0.0.tgz", + "integrity": "sha512-1P/yWsxPlDtn7QeRD+ULKQPaIaN6yF368GZ2vDfv0AL0NwpStafjWCDDdn0k8wgFMWpVAqG7oJhxHnlud42i9w==", + "requires": { + "has-to-string-tag-x": "^1.2.0", + "is-object": "^1.0.1" + } + }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -4367,8 +4545,7 @@ "json-buffer": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz", - "integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=", - "dev": true + "integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=" }, "json-parse-better-errors": { "version": "1.0.2", @@ -4451,7 +4628,6 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/keyv/-/keyv-3.1.0.tgz", "integrity": "sha512-9ykJ/46SN/9KPM/sichzQ7OvXyGDYKGTaDlKMGCAlg2UK8KRy4jb0d8sFc+0Tt0YYnThq8X2RZgCg74RPxgcVA==", - "dev": true, "requires": { "json-buffer": "3.0.0" } @@ -4845,8 +5021,7 @@ "lowercase-keys": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz", - "integrity": "sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==", - "dev": true + "integrity": "sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==" }, "lru-cache": { "version": "4.1.5", @@ -5016,8 +5191,7 @@ "mimic-response": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", - "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==", - "dev": true + "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==" }, "minimatch": { "version": "3.0.4", @@ -5215,8 +5389,7 @@ "normalize-url": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-3.3.0.tgz", - "integrity": "sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg==", - "dev": true + "integrity": "sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg==" }, "np": { "version": "4.0.2", @@ -5637,8 +5810,7 @@ "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", - "dev": true + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" }, "object-copy": { "version": "0.1.0", @@ -5807,6 +5979,14 @@ "integrity": "sha512-bBc51JQ7LM8HXhihEQZyhs+ZWTIdm20riI6y3gLAdPkzEyAHH6tuGV7rAQvfxDjqWqj7Z/slv0AEL2Gi3lkN0Q==", "dev": true }, + "p-any": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/p-any/-/p-any-1.1.0.tgz", + "integrity": "sha512-Ef0tVa4CZ5pTAmKn+Cg3w8ABBXh+hHO1aV8281dKOoUHfX+3tjG2EaFcC+aZyagg9b4EYGsHEjz21DnEE8Og2g==", + "requires": { + "p-some": "^2.0.0" + } + }, "p-cancelable": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-0.4.1.tgz", @@ -5821,14 +6001,12 @@ "p-finally": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz", - "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=", - "dev": true + "integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=" }, "p-is-promise": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-1.1.0.tgz", - "integrity": "sha1-nJRWmJ6fZYgBewQ01WCXZ1w9oF4=", - "dev": true + "integrity": "sha1-nJRWmJ6fZYgBewQ01WCXZ1w9oF4=" }, "p-limit": { "version": "1.3.0", @@ -5862,11 +6040,18 @@ "mimic-fn": "^1.0.0" } }, + "p-some": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/p-some/-/p-some-2.0.1.tgz", + "integrity": "sha1-Zdh8ixVO289SIdFnd4ttLhUPbwY=", + "requires": { + "aggregate-error": "^1.0.0" + } + }, "p-timeout": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-2.0.1.tgz", "integrity": "sha512-88em58dDVB/KzPEx1X0N3LwFfYZPyDc4B6eF38M1rk9VTZMbxXXgjugz8mmwpS9Ox4BDZ+t6t3QP5+/gazweIA==", - "dev": true, "requires": { "p-finally": "^1.0.0" } @@ -6390,8 +6575,7 @@ "process-nextick-args": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", - "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==", - "dev": true + "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==" }, "progress": { "version": "2.0.3", @@ -6427,11 +6611,117 @@ "integrity": "sha512-/6pt4+C+T+wZUieKR620OpzN/LlnNKuWjy1iFLQ/UG35JqHlR/89MP1d96dUfkf6Dne3TuLQzOYEYshJ+Hx8mw==", "dev": true }, + "public-ip": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/public-ip/-/public-ip-2.5.0.tgz", + "integrity": "sha512-XQdvH0GwYlm/SRf+wSqKf8y/8cjykzQJauU4FqMguZpew/RjItiJX9l4+V6A/ezDmAuT8f1I/WkyWXiL819PhA==", + "requires": { + "dns-socket": "^1.6.2", + "got": "^8.0.0", + "is-ip": "^2.0.0", + "pify": "^3.0.0" + }, + "dependencies": { + "@sindresorhus/is": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.7.0.tgz", + "integrity": "sha512-ONhaKPIufzzrlNbqtWFFd+jlnemX6lJAgq9ZeiZtS7I1PIf/la7CW4m83rTXRnVnsMbW2k56pGYu7AUFJD9Pow==" + }, + "cacheable-request": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-2.1.4.tgz", + "integrity": "sha1-DYCIAbY0KtM8kd+dC0TcCbkeXD0=", + "requires": { + "clone-response": "1.0.2", + "get-stream": "3.0.0", + "http-cache-semantics": "3.8.1", + "keyv": "3.0.0", + "lowercase-keys": "1.0.0", + "normalize-url": "2.0.1", + "responselike": "1.0.2" + }, + "dependencies": { + "lowercase-keys": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.0.tgz", + "integrity": "sha1-TjNms55/VFfjXxMkvfb4jQv8cwY=" + } + } + }, + "got": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/got/-/got-8.3.2.tgz", + "integrity": "sha512-qjUJ5U/hawxosMryILofZCkm3C84PLJS/0grRIpjAwu+Lkxxj5cxeCU25BG0/3mDSpXKTyZr8oh8wIgLaH0QCw==", + "requires": { + "@sindresorhus/is": "^0.7.0", + "cacheable-request": "^2.1.1", + "decompress-response": "^3.3.0", + "duplexer3": "^0.1.4", + "get-stream": "^3.0.0", + "into-stream": "^3.1.0", + "is-retry-allowed": "^1.1.0", + "isurl": "^1.0.0-alpha5", + "lowercase-keys": "^1.0.0", + "mimic-response": "^1.0.0", + "p-cancelable": "^0.4.0", + "p-timeout": "^2.0.1", + "pify": "^3.0.0", + "safe-buffer": "^5.1.1", + "timed-out": "^4.0.1", + "url-parse-lax": "^3.0.0", + "url-to-options": "^1.0.1" + } + }, + "http-cache-semantics": { + "version": "3.8.1", + "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-3.8.1.tgz", + "integrity": "sha512-5ai2iksyV8ZXmnZhHH4rWPoxxistEexSi5936zIQ1bnNTW5VnA85B6P/VpXiRM017IgRvb2kKo1a//y+0wSp3w==" + }, + "keyv": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-3.0.0.tgz", + "integrity": "sha512-eguHnq22OE3uVoSYG0LVWNP+4ppamWr9+zWBe1bsNcovIMy6huUJFPgy4mGwCd/rnl3vOLGW1MTlu4c57CT1xA==", + "requires": { + "json-buffer": "3.0.0" + } + }, + "normalize-url": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-2.0.1.tgz", + "integrity": "sha512-D6MUW4K/VzoJ4rJ01JFKxDrtY1v9wrgzCX5f2qj/lzH1m/lW6MhUZFKerVsnyjOhOsYzI9Kqqak+10l4LvLpMw==", + "requires": { + "prepend-http": "^2.0.0", + "query-string": "^5.0.1", + "sort-keys": "^2.0.0" + } + }, + "prepend-http": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz", + "integrity": "sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=" + }, + "sort-keys": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/sort-keys/-/sort-keys-2.0.0.tgz", + "integrity": "sha1-ZYU1WEhh7JfXMNbPQYIuH1ZoQSg=", + "requires": { + "is-plain-obj": "^1.0.0" + } + }, + "url-parse-lax": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-3.0.0.tgz", + "integrity": "sha1-FrXK/Afb42dsGxmZF3gj1lA6yww=", + "requires": { + "prepend-http": "^2.0.0" + } + } + } + }, "pump": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", - "dev": true, "requires": { "end-of-stream": "^1.1.0", "once": "^1.3.1" @@ -6454,6 +6744,16 @@ "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==", "dev": true }, + "query-string": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/query-string/-/query-string-5.1.1.tgz", + "integrity": "sha512-gjWOsm2SoGlgLEdAGt7a6slVOk9mGiXmPFMqrEhLQ68rhQuBnpfs3+EmlvqKyxnCo9/PPlF+9MtY02S1aFg+Jw==", + "requires": { + "decode-uri-component": "^0.2.0", + "object-assign": "^4.1.0", + "strict-uri-encode": "^1.0.0" + } + }, "quick-lru": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-1.1.0.tgz", @@ -6896,7 +7196,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/responselike/-/responselike-1.0.2.tgz", "integrity": "sha1-kYcg7ztjHFZCvgaPFa3lpG9Loec=", - "dev": true, "requires": { "lowercase-keys": "^1.0.0" } @@ -6968,8 +7267,7 @@ "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "dev": true + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, "safe-regex": { "version": "1.1.0", @@ -7412,6 +7710,11 @@ } } }, + "strict-uri-encode": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz", + "integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=" + }, "string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", @@ -8024,8 +8327,7 @@ "timed-out": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/timed-out/-/timed-out-4.0.1.tgz", - "integrity": "sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8=", - "dev": true + "integrity": "sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8=" }, "tmp": { "version": "0.0.33", @@ -8064,8 +8366,7 @@ "to-readable-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/to-readable-stream/-/to-readable-stream-1.0.0.tgz", - "integrity": "sha512-Iq25XBt6zD5npPhlLVXGFN3/gyR2/qODcKNNyTMd4vbm39HUaOiAM4PMq0eMVC/Tkxz+Zjdsc55g9yyz+Yq00Q==", - "dev": true + "integrity": "sha512-Iq25XBt6zD5npPhlLVXGFN3/gyR2/qODcKNNyTMd4vbm39HUaOiAM4PMq0eMVC/Tkxz+Zjdsc55g9yyz+Yq00Q==" }, "to-regex": { "version": "3.0.2", @@ -8428,6 +8729,11 @@ "prepend-http": "^1.0.1" } }, + "url-to-options": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/url-to-options/-/url-to-options-1.0.1.tgz", + "integrity": "sha1-FQWgOiiaSMvXpDTvuu7FBV9WM6k=" + }, "use": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/use/-/use-3.1.1.tgz", @@ -8443,8 +8749,7 @@ "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", - "dev": true + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, "uuid": { "version": "3.3.2", diff --git a/package.json b/package.json index 2980d986a..c954d4266 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "publish-snap": "del dist && tsc && electron-builder --linux && snapcraft push --release=stable dist/*.snap" }, "dependencies": { + "@types/is-online": "^8.0.0", "electron-context-menu": "^0.11.0", "electron-debug": "^2.1.0", "electron-dl": "^1.13.0", @@ -34,7 +35,8 @@ "electron-updater": "^4.0.6", "electron-util": "^0.11.0", "element-ready": "^3.0.0", - "facebook-locales": "^1.0.591" + "facebook-locales": "^1.0.591", + "is-online": "^8.0.0" }, "devDependencies": { "@sindresorhus/tsconfig": "^0.2.0", diff --git a/source/index.ts b/source/index.ts index 6fff952f0..1d67dc7dc 100644 --- a/source/index.ts +++ b/source/index.ts @@ -16,6 +16,7 @@ import { RequestHeaders, OnSendHeadersDetails } from 'electron'; +import isOnline from 'is-online'; import log from 'electron-log'; import {autoUpdater} from 'electron-updater'; import electronDl from 'electron-dl'; @@ -276,6 +277,13 @@ function createMainWindow(): BrowserWindow { return win; } +const networkConnectivity = async (): Promise => { + /* eslint-disable no-await-in-loop */ + while (!(await isOnline())); + /* eslint-enable no-await-in-loop */ + return true; +}; + (async () => { await app.whenReady(); @@ -285,6 +293,12 @@ function createMainWindow(): BrowserWindow { mainWindow = createMainWindow(); tray.create(mainWindow); + const shouldReload = !(await isOnline()); + + if (shouldReload && (await networkConnectivity())) { + mainWindow.reload(); + } + if (is.macos) { const firstItem: MenuItemConstructorOptions = { label: 'Mute Notifications', From e7594b09af3abf0aa76d567eda3b25ccff2c52ce Mon Sep 17 00:00:00 2001 From: Daniel Andrei Date: Sat, 16 Feb 2019 20:02:48 +0200 Subject: [PATCH 02/19] Relaunch app instead of reloading `mainWindow` --- source/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/index.ts b/source/index.ts index 1d67dc7dc..816d7870e 100644 --- a/source/index.ts +++ b/source/index.ts @@ -296,7 +296,8 @@ const networkConnectivity = async (): Promise => { const shouldReload = !(await isOnline()); if (shouldReload && (await networkConnectivity())) { - mainWindow.reload(); + app.quit(); + app.relaunch(); } if (is.macos) { From dde9d3524855d7c490d572d83e56d1eea3804090 Mon Sep 17 00:00:00 2001 From: Daniel Andrei Date: Sat, 16 Feb 2019 20:04:08 +0200 Subject: [PATCH 03/19] Add TODO --- source/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/source/index.ts b/source/index.ts index 816d7870e..75f2d6fcf 100644 --- a/source/index.ts +++ b/source/index.ts @@ -295,6 +295,7 @@ const networkConnectivity = async (): Promise => { const shouldReload = !(await isOnline()); + // TODO: Reload mainWindow instead as soon as #712 is fixed if (shouldReload && (await networkConnectivity())) { app.quit(); app.relaunch(); From 3916b2e1a3c651347b9afd336c7ab57441dc8304 Mon Sep 17 00:00:00 2001 From: Daniel Andrei Date: Sat, 16 Feb 2019 23:50:42 +0200 Subject: [PATCH 04/19] Use `p-wait-for` for polling internet connectivity --- package-lock.json | 8 ++++++++ package.json | 3 ++- source/index.ts | 14 +++----------- source/p-wait-for.d.ts | 1 + 4 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 source/p-wait-for.d.ts diff --git a/package-lock.json b/package-lock.json index 1b5635fb8..78ff4a009 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6061,6 +6061,14 @@ "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=" }, + "p-wait-for": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/p-wait-for/-/p-wait-for-2.0.1.tgz", + "integrity": "sha512-edEuJC7eRokPf3AWycsS3lp8JimWLnVgCeGoWw67qFerUmsAHKyhRBj8rDvaBjPV2bTyzgTwmF+U8vNMMBEcyA==", + "requires": { + "p-timeout": "^2.0.1" + } + }, "package-json": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/package-json/-/package-json-4.0.1.tgz", diff --git a/package.json b/package.json index c954d4266..d3a4f8564 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,8 @@ "electron-util": "^0.11.0", "element-ready": "^3.0.0", "facebook-locales": "^1.0.591", - "is-online": "^8.0.0" + "is-online": "^8.0.0", + "p-wait-for": "^2.0.1" }, "devDependencies": { "@sindresorhus/tsconfig": "^0.2.0", diff --git a/source/index.ts b/source/index.ts index 75f2d6fcf..564966758 100644 --- a/source/index.ts +++ b/source/index.ts @@ -17,6 +17,7 @@ import { OnSendHeadersDetails } from 'electron'; import isOnline from 'is-online'; +import pWaitFor from 'p-wait-for'; import log from 'electron-log'; import {autoUpdater} from 'electron-updater'; import electronDl from 'electron-dl'; @@ -277,13 +278,6 @@ function createMainWindow(): BrowserWindow { return win; } -const networkConnectivity = async (): Promise => { - /* eslint-disable no-await-in-loop */ - while (!(await isOnline())); - /* eslint-enable no-await-in-loop */ - return true; -}; - (async () => { await app.whenReady(); @@ -293,12 +287,10 @@ const networkConnectivity = async (): Promise => { mainWindow = createMainWindow(); tray.create(mainWindow); - const shouldReload = !(await isOnline()); - // TODO: Reload mainWindow instead as soon as #712 is fixed - if (shouldReload && (await networkConnectivity())) { - app.quit(); + if (!(await isOnline()) && (await pWaitFor(() => isOnline()), {interval: 1000})) { app.relaunch(); + app.quit(); } if (is.macos) { diff --git a/source/p-wait-for.d.ts b/source/p-wait-for.d.ts new file mode 100644 index 000000000..a4536c3d8 --- /dev/null +++ b/source/p-wait-for.d.ts @@ -0,0 +1 @@ +declare module 'p-wait-for'; From 9c06d5960ef619631c2fac7aac47141f9e23f230 Mon Sep 17 00:00:00 2001 From: Daniel Andrei Date: Sat, 16 Feb 2019 23:55:37 +0200 Subject: [PATCH 05/19] Remove inline function --- source/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/index.ts b/source/index.ts index 564966758..ab156e9bc 100644 --- a/source/index.ts +++ b/source/index.ts @@ -288,7 +288,7 @@ function createMainWindow(): BrowserWindow { tray.create(mainWindow); // TODO: Reload mainWindow instead as soon as #712 is fixed - if (!(await isOnline()) && (await pWaitFor(() => isOnline()), {interval: 1000})) { + if (!(await isOnline()) && (await pWaitFor(isOnline), {interval: 1000})) { app.relaunch(); app.quit(); } From 00548924a99308dabe4a9ddaebd25a8e202b4144 Mon Sep 17 00:00:00 2001 From: Daniel Andrei Date: Sun, 17 Feb 2019 00:22:35 +0200 Subject: [PATCH 06/19] Fix options passing bug --- source/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/index.ts b/source/index.ts index ab156e9bc..e076e41b9 100644 --- a/source/index.ts +++ b/source/index.ts @@ -288,7 +288,8 @@ function createMainWindow(): BrowserWindow { tray.create(mainWindow); // TODO: Reload mainWindow instead as soon as #712 is fixed - if (!(await isOnline()) && (await pWaitFor(isOnline), {interval: 1000})) { + if (!(await isOnline())) { + await pWaitFor(isOnline, {interval: 1000}); app.relaunch(); app.quit(); } From d38759a00176a1e9be2bb3a89bf5a0b2bc238280 Mon Sep 17 00:00:00 2001 From: Daniel Andrei Date: Sun, 17 Feb 2019 16:58:11 +0200 Subject: [PATCH 07/19] Show retry prompt after 20s --- source/index.ts | 6 +++++- source/util.ts | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/source/index.ts b/source/index.ts index e076e41b9..84214b525 100644 --- a/source/index.ts +++ b/source/index.ts @@ -29,7 +29,7 @@ import {bestFacebookLocaleFor} from 'facebook-locales'; import updateAppMenu from './menu'; import config from './config'; import tray from './tray'; -import {sendAction} from './util'; +import {sendAction, showRetryDialog} from './util'; import {process as processEmojiUrl} from './emoji'; import './touch-bar'; // eslint-disable-line import/no-unassigned-import @@ -289,7 +289,11 @@ function createMainWindow(): BrowserWindow { // TODO: Reload mainWindow instead as soon as #712 is fixed if (!(await isOnline())) { + const connectivityTimeout = setTimeout(() => { + showRetryDialog(`It appears that you're offline`); + }, 20000); await pWaitFor(isOnline, {interval: 1000}); + clearTimeout(connectivityTimeout); app.relaunch(); app.quit(); } diff --git a/source/util.ts b/source/util.ts index e33a336a6..e062edcbb 100644 --- a/source/util.ts +++ b/source/util.ts @@ -33,3 +33,22 @@ export function showRestartDialog(message: string): void { } ); } + +export function showRetryDialog(message: string): void { + dialog.showMessageBox( + { + message, + detail: `Do you want to retry?`, + buttons: ['Try again', 'Quit'], + defaultId: 0, + cancelId: 1 + }, + response => { + if (response === 0) { + app.relaunch(); + } + + app.quit(); + } + ); +} From 7dbfda04bb72af3093269997b742edc6dccdff37 Mon Sep 17 00:00:00 2001 From: Daniel Andrei Date: Sun, 17 Feb 2019 17:12:11 +0200 Subject: [PATCH 08/19] Update timeout message --- source/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/index.ts b/source/index.ts index 84214b525..ca7328120 100644 --- a/source/index.ts +++ b/source/index.ts @@ -290,7 +290,7 @@ function createMainWindow(): BrowserWindow { // TODO: Reload mainWindow instead as soon as #712 is fixed if (!(await isOnline())) { const connectivityTimeout = setTimeout(() => { - showRetryDialog(`It appears that you're offline`); + showRetryDialog(`You appear to be offline. Caprine requires a working internet connection.`); }, 20000); await pWaitFor(isOnline, {interval: 1000}); clearTimeout(connectivityTimeout); From eb0548b3293babc2387f276f4c686f1038454f91 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Mon, 18 Feb 2019 12:18:16 +0100 Subject: [PATCH 09/19] Check for internet connection before creating a window --- source/index.ts | 20 +++++++++----------- source/util.ts | 10 ++++------ 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/source/index.ts b/source/index.ts index ca7328120..5c5031b0e 100644 --- a/source/index.ts +++ b/source/index.ts @@ -279,25 +279,23 @@ function createMainWindow(): BrowserWindow { } (async () => { - await app.whenReady(); - - const trackingUrlPrefix = `https://l.${domain}/l.php`; - - updateAppMenu(); - mainWindow = createMainWindow(); - tray.create(mainWindow); - - // TODO: Reload mainWindow instead as soon as #712 is fixed if (!(await isOnline())) { const connectivityTimeout = setTimeout(() => { showRetryDialog(`You appear to be offline. Caprine requires a working internet connection.`); }, 20000); + await pWaitFor(isOnline, {interval: 1000}); clearTimeout(connectivityTimeout); - app.relaunch(); - app.quit(); } + await app.whenReady(); + + const trackingUrlPrefix = `https://l.${domain}/l.php`; + + updateAppMenu(); + mainWindow = createMainWindow(); + tray.create(mainWindow); + if (is.macos) { const firstItem: MenuItemConstructorOptions = { label: 'Mute Notifications', diff --git a/source/util.ts b/source/util.ts index e062edcbb..2a030982b 100644 --- a/source/util.ts +++ b/source/util.ts @@ -38,17 +38,15 @@ export function showRetryDialog(message: string): void { dialog.showMessageBox( { message, - detail: `Do you want to retry?`, - buttons: ['Try again', 'Quit'], + detail: `Do you want to wait?`, + buttons: ['Wait', 'Quit'], defaultId: 0, cancelId: 1 }, response => { - if (response === 0) { - app.relaunch(); + if (response === 1) { + app.quit(); } - - app.quit(); } ); } From 613b24931d757ed44a08c7e619d045227dcbd06a Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Mon, 18 Feb 2019 12:18:55 +0100 Subject: [PATCH 10/19] Lower the connectivity check timeout to 15 seconds --- source/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/index.ts b/source/index.ts index 5c5031b0e..469558214 100644 --- a/source/index.ts +++ b/source/index.ts @@ -282,7 +282,7 @@ function createMainWindow(): BrowserWindow { if (!(await isOnline())) { const connectivityTimeout = setTimeout(() => { showRetryDialog(`You appear to be offline. Caprine requires a working internet connection.`); - }, 20000); + }, 15000); await pWaitFor(isOnline, {interval: 1000}); clearTimeout(connectivityTimeout); From 7eb02a2104529b749f4c0cd0ba7de794c32f0ec9 Mon Sep 17 00:00:00 2001 From: Daniel Andrei Date: Mon, 18 Feb 2019 13:48:14 +0200 Subject: [PATCH 11/19] Check for window on `activate` --- source/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/index.ts b/source/index.ts index 469558214..9a0165962 100644 --- a/source/index.ts +++ b/source/index.ts @@ -449,7 +449,9 @@ ipcMain.on('mute-notifications-toggled', (_event: ElectronEvent, status: boolean }); app.on('activate', () => { - mainWindow.show(); + if (mainWindow) { + mainWindow.show(); + } }); app.on('before-quit', () => { From 292bfe035412a14a616ae6e4c3b7bb495c0923a5 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 18 Feb 2019 21:09:03 +0700 Subject: [PATCH 12/19] Update index.ts --- source/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/index.ts b/source/index.ts index 9a0165962..87451a3ae 100644 --- a/source/index.ts +++ b/source/index.ts @@ -281,7 +281,7 @@ function createMainWindow(): BrowserWindow { (async () => { if (!(await isOnline())) { const connectivityTimeout = setTimeout(() => { - showRetryDialog(`You appear to be offline. Caprine requires a working internet connection.`); + showRetryDialog('You appear to be offline. Caprine requires a working internet connection.'); }, 15000); await pWaitFor(isOnline, {interval: 1000}); From 6736e9ea0b5bf4bc34d232e5e930e043e0ed3cb4 Mon Sep 17 00:00:00 2001 From: Daniel Andrei Date: Mon, 18 Feb 2019 16:32:35 +0200 Subject: [PATCH 13/19] Move logic for `ensure-online` --- source/ensure-online.ts | 31 +++++++++++++++++++++++++++++++ source/index.ts | 16 +++------------- source/util.ts | 17 ----------------- 3 files changed, 34 insertions(+), 30 deletions(-) create mode 100644 source/ensure-online.ts diff --git a/source/ensure-online.ts b/source/ensure-online.ts new file mode 100644 index 000000000..d5109a24b --- /dev/null +++ b/source/ensure-online.ts @@ -0,0 +1,31 @@ +import {app, dialog} from 'electron'; +import isOnline from 'is-online'; +import pWaitFor from 'p-wait-for'; + +function showRetryDialog(message: string): void { + dialog.showMessageBox( + { + message, + detail: 'Do you want to wait?', + buttons: ['Wait', 'Quit'], + defaultId: 0, + cancelId: 1 + }, + response => { + if (response === 1) { + app.quit(); + } + } + ); +} + +export const ensureOnline = async (): Promise => { + if (!(await isOnline())) { + const connectivityTimeout = setTimeout(() => { + showRetryDialog('You appear to be offline. Caprine requires a working internet connection.'); + }, 15000); + + await pWaitFor(isOnline, {interval: 1000}); + clearTimeout(connectivityTimeout); + } +}; diff --git a/source/index.ts b/source/index.ts index 9a0165962..446d5ed1b 100644 --- a/source/index.ts +++ b/source/index.ts @@ -16,8 +16,6 @@ import { RequestHeaders, OnSendHeadersDetails } from 'electron'; -import isOnline from 'is-online'; -import pWaitFor from 'p-wait-for'; import log from 'electron-log'; import {autoUpdater} from 'electron-updater'; import electronDl from 'electron-dl'; @@ -29,9 +27,10 @@ import {bestFacebookLocaleFor} from 'facebook-locales'; import updateAppMenu from './menu'; import config from './config'; import tray from './tray'; -import {sendAction, showRetryDialog} from './util'; +import {sendAction} from './util'; import {process as processEmojiUrl} from './emoji'; import './touch-bar'; // eslint-disable-line import/no-unassigned-import +import {ensureOnline} from './ensure-online'; electronDebug({ enabled: true, // TODO: This is only enabled to allow `Command+R` because messenger sometimes gets stuck after computer waking up @@ -279,16 +278,7 @@ function createMainWindow(): BrowserWindow { } (async () => { - if (!(await isOnline())) { - const connectivityTimeout = setTimeout(() => { - showRetryDialog(`You appear to be offline. Caprine requires a working internet connection.`); - }, 15000); - - await pWaitFor(isOnline, {interval: 1000}); - clearTimeout(connectivityTimeout); - } - - await app.whenReady(); + await Promise.all([ensureOnline(), app.whenReady()]); const trackingUrlPrefix = `https://l.${domain}/l.php`; diff --git a/source/util.ts b/source/util.ts index 2a030982b..e33a336a6 100644 --- a/source/util.ts +++ b/source/util.ts @@ -33,20 +33,3 @@ export function showRestartDialog(message: string): void { } ); } - -export function showRetryDialog(message: string): void { - dialog.showMessageBox( - { - message, - detail: `Do you want to wait?`, - buttons: ['Wait', 'Quit'], - defaultId: 0, - cancelId: 1 - }, - response => { - if (response === 1) { - app.quit(); - } - } - ); -} From 47dd4f12bbe8b8dd8b5639ae3e37bff893f3abbd Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Mon, 18 Feb 2019 15:42:33 +0100 Subject: [PATCH 14/19] Rename `showRetryDialog` and move the message inside it --- source/ensure-online.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/source/ensure-online.ts b/source/ensure-online.ts index d5109a24b..704f9a5f8 100644 --- a/source/ensure-online.ts +++ b/source/ensure-online.ts @@ -2,10 +2,10 @@ import {app, dialog} from 'electron'; import isOnline from 'is-online'; import pWaitFor from 'p-wait-for'; -function showRetryDialog(message: string): void { +function showWaitDialog(): void { dialog.showMessageBox( { - message, + message: 'You appear to be offline. Caprine requires a working internet connection.', detail: 'Do you want to wait?', buttons: ['Wait', 'Quit'], defaultId: 0, @@ -21,9 +21,7 @@ function showRetryDialog(message: string): void { export const ensureOnline = async (): Promise => { if (!(await isOnline())) { - const connectivityTimeout = setTimeout(() => { - showRetryDialog('You appear to be offline. Caprine requires a working internet connection.'); - }, 15000); + const connectivityTimeout = setTimeout(showWaitDialog, 15000); await pWaitFor(isOnline, {interval: 1000}); clearTimeout(connectivityTimeout); From 75cfd564c6b4e2129e5594655465706a3112f303 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 18 Feb 2019 23:56:27 +0700 Subject: [PATCH 15/19] Update ensure-online.ts --- source/ensure-online.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/ensure-online.ts b/source/ensure-online.ts index 704f9a5f8..b647eba8d 100644 --- a/source/ensure-online.ts +++ b/source/ensure-online.ts @@ -7,7 +7,10 @@ function showWaitDialog(): void { { message: 'You appear to be offline. Caprine requires a working internet connection.', detail: 'Do you want to wait?', - buttons: ['Wait', 'Quit'], + buttons: [ + 'Wait', + 'Quit' + ], defaultId: 0, cancelId: 1 }, From 351b5e48e330526d3760c09e6f01a11b578b2c49 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 19 Feb 2019 00:01:54 +0700 Subject: [PATCH 16/19] Update ensure-online.ts --- source/ensure-online.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/ensure-online.ts b/source/ensure-online.ts index b647eba8d..78676b633 100644 --- a/source/ensure-online.ts +++ b/source/ensure-online.ts @@ -22,7 +22,7 @@ function showWaitDialog(): void { ); } -export const ensureOnline = async (): Promise => { +export default async (): Promise => { if (!(await isOnline())) { const connectivityTimeout = setTimeout(showWaitDialog, 15000); From 860ec24f80e4aa3f25851d0f16d8dd77850fc1cf Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 19 Feb 2019 00:02:53 +0700 Subject: [PATCH 17/19] Update index.ts --- source/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/index.ts b/source/index.ts index 446d5ed1b..8aac16cb7 100644 --- a/source/index.ts +++ b/source/index.ts @@ -29,8 +29,8 @@ import config from './config'; import tray from './tray'; import {sendAction} from './util'; import {process as processEmojiUrl} from './emoji'; +import ensureOnline from './ensure-online'; import './touch-bar'; // eslint-disable-line import/no-unassigned-import -import {ensureOnline} from './ensure-online'; electronDebug({ enabled: true, // TODO: This is only enabled to allow `Command+R` because messenger sometimes gets stuck after computer waking up @@ -278,7 +278,10 @@ function createMainWindow(): BrowserWindow { } (async () => { - await Promise.all([ensureOnline(), app.whenReady()]); + await Promise.all([ + ensureOnline(), + app.whenReady() + ]); const trackingUrlPrefix = `https://l.${domain}/l.php`; From 723abf8bb3da51160daadb11563324973fd25bfa Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 19 Feb 2019 00:10:47 +0700 Subject: [PATCH 18/19] F*&*& prettier --- source/ensure-online.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/source/ensure-online.ts b/source/ensure-online.ts index 78676b633..938779618 100644 --- a/source/ensure-online.ts +++ b/source/ensure-online.ts @@ -7,10 +7,7 @@ function showWaitDialog(): void { { message: 'You appear to be offline. Caprine requires a working internet connection.', detail: 'Do you want to wait?', - buttons: [ - 'Wait', - 'Quit' - ], + buttons: ['Wait', 'Quit'], defaultId: 0, cancelId: 1 }, From f0d2271c88f29bbcb21383642ff41068c9d4af13 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 19 Feb 2019 00:11:23 +0700 Subject: [PATCH 19/19] =?UTF-8?q?prettier=20=F0=9F=92=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/index.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/source/index.ts b/source/index.ts index 8aac16cb7..f7f0015b7 100644 --- a/source/index.ts +++ b/source/index.ts @@ -278,10 +278,7 @@ function createMainWindow(): BrowserWindow { } (async () => { - await Promise.all([ - ensureOnline(), - app.whenReady() - ]); + await Promise.all([ensureOnline(), app.whenReady()]); const trackingUrlPrefix = `https://l.${domain}/l.php`;