Repository: hovancik/stretchly
Pull request #536 (2020-02-27 09:00:02)

Small fixes and features


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 03e61f4..1d4ade6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
 and this project adheres to [Semantic Versioning](http://semver.org/).
 
 ## [Unreleased]
+### Changed
+- default icon is colorful
+
+### Added
+- new break ideas
+
+### Fixed
+- notify of new version only if new version is higher then current
 
 ## [0.21.1] - 2020-01-16
 ### Changed
diff --git a/app/package-lock.json b/app/package-lock.json
index fa010a1..ec777e2 100644
--- a/app/package-lock.json
+++ b/app/package-lock.json
@@ -111,6 +111,11 @@
       "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz",
       "integrity": "sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw=="
     },
+    "semver": {
+      "version": "7.1.3",
+      "resolved": "https://registry.npmjs.org/semver/-/semver-7.1.3.tgz",
+      "integrity": "sha512-ekM0zfiA9SCBlsKa2X1hxyxiI4L3B6EbVJkkdgQXnSEEaHlGdvyodMruTiulSRWMMB4NeIuYNMC9rTKTz97GxA=="
+    },
     "sprintf-js": {
       "version": "1.0.3",
       "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
diff --git a/app/package.json b/app/package.json
index 1ad0322..6df491d 100644
--- a/app/package.json
+++ b/app/package.json
@@ -23,7 +23,8 @@
     "@meetfranz/electron-notification-state": "^1.0.0",
     "i18next": "^19.0.3",
     "i18next-node-fs-backend": "^2.1.3",
-    "moment": "^2.24.0"
+    "moment": "^2.24.0",
+    "semver": "^7.1.3"
   },
   "devDependencies": {}
 }
diff --git a/app/process.js b/app/process.js
index 82dbfc7..f6c2a4c 100644
--- a/app/process.js
+++ b/app/process.js
@@ -1,6 +1,7 @@
 const { ipcRenderer, shell, remote } = require('electron')
 const VersionChecker = require('./utils/versionChecker')
 const i18next = remote.require('i18next')
+const semver = require('semver')
 
 ipcRenderer.on('playSound', (event, file, volume) => {
   const audio = new Audio(`audio/${file}.wav`)
@@ -15,8 +16,8 @@ ipcRenderer.on('checkVersion', (event, { oldVersion, notify, silent }) => {
     new VersionChecker()
       .latest()
       .then(version => {
-        const semantic = /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/
-        if (version.match(semantic) && oldVersion !== version) {
+        const cleanVersion = semver.clean(version)
+        if (semver.valid(cleanVersion) && semver.gt(cleanVersion, oldVersion)) {
           remote.getGlobal('shared').isNewVersion = true
           ipcRenderer.send('update-tray')
           if (notify) {
diff --git a/app/utils/defaultMicrobreakIdeas.js b/app/utils/defaultMicrobreakIdeas.js
index 2a707c6..fbcebd4 100644
--- a/app/utils/defaultMicrobreakIdeas.js
+++ b/app/utils/defaultMicrobreakIdeas.js
@@ -19,5 +19,6 @@ module.exports = [
   { data: 'Place your fingertips on your shoulders. Roll your shoulders forward for 10 seconds, then backward.', enabled: true },
   { data: 'Raise your right arm, stretch it over your head to the left, and hold for 10 seconds. Repeat on the other side.', enabled: true },
   { data: 'With your right hand, grab each finger of your left hand in turn and squeeze. Repeat on the other side.', enabled: true },
-  { data: 'Stand up and do a lunge. Hold for 10 seconds, then do the other leg.', enabled: true }
+  { data: 'Stand up and do a lunge. Hold for 10 seconds, then do the other leg.', enabled: true },
+  { data: 'Close your eyes and simply notice whatever arises in current moment, without judgement.', enabled: true }
 ]
diff --git a/app/utils/defaultSettings.js b/app/utils/defaultSettings.js
index ed362f4..51b1b5a 100644
--- a/app/utils/defaultSettings.js
+++ b/app/utils/defaultSettings.js
@@ -34,7 +34,7 @@ module.exports = {
   isFirstRun: true,
   posLatitude: 0.0,
   posLongitude: 0.0,
-  useMonochromeTrayIcon: true,
+  useMonochromeTrayIcon: false,
   useMonochromeInvertedTrayIcon: false,
   silentNotifications: false,
   monitorDnd: true,
diff --git a/app/utils/settings.js b/app/utils/settings.js
index 8fb13fd..2cb2543 100644
--- a/app/utils/settings.js
+++ b/app/utils/settings.js
@@ -13,7 +13,7 @@ class Settings {
         this._loadMissing()
       }
     } else {
-      this.data = defaultSettings
+      this.data = Object.assign({}, defaultSettings)
       this._save(true)
     }
   }
@@ -30,6 +30,12 @@ class Settings {
     this._save()
   }
 
+  restoreDefaults () {
+    this.data = Object.assign({}, defaultSettings)
+    this.data.isFirstRun = false
+    this._save(true)
+  }
+
   _load (retryCount = 5) {
     try {
       this.data = JSON.parse(fs.readFileSync(this.settingsFile, 'utf8'))
@@ -39,7 +45,7 @@ class Settings {
         console.log('Failed to load settings JSON file, retrying in 10 milliseconds')
         return
       }
-      this.data = defaultSettings
+      this.data = Object.assign({}, defaultSettings)
       // TODO maybe I should `this._save(true)` here?
       console.log('Failed to load settings JSON file, giving up and resetting')
     }
diff --git a/package-lock.json b/package-lock.json
index 4599906..ba680df 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -337,6 +337,14 @@
         "sanitize-filename": "^1.6.1",
         "semver": "^6.1.1",
         "temp-file": "^3.3.3"
+      },
+      "dependencies": {
+        "semver": {
+          "version": "6.3.0",
+          "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
+          "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
+          "dev": true
+        }
       }
     },
     "archiver": {
@@ -1690,6 +1698,12 @@
             "through": "^2.3.6"
           }
         },
+        "semver": {
+          "version": "6.3.0",
+          "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
+          "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
+          "dev": true
+        },
         "string-width": {
           "version": "2.1.1",
           "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
@@ -2038,6 +2052,12 @@
           "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.4.tgz",
           "integrity": "sha512-MzbUSahkTW1u7JpKKjY7LCARd1fU5W2rLdxlM4kdkayuCwZImjkpluF9CM1aLewYJguPDqewLam18Y6AU69A8A==",
           "dev": true
+        },
+        "semver": {
+          "version": "6.3.0",
+          "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
+          "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
+          "dev": true
         }
       }
     },
@@ -2510,6 +2530,15 @@
         "roarr": "^2.14.5",
         "semver": "^6.3.0",
         "serialize-error": "^5.0.0"
+      },
+      "dependencies": {
+        "semver": {
+          "version": "6.3.0",
+          "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
+          "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
+          "dev": true,
+          "optional": true
+        }
       }
     },
     "global-dirs": {
@@ -3957,6 +3986,14 @@
         "registry-auth-token": "^4.0.0",
         "registry-url": "^5.0.0",
         "semver": "^6.2.0"
+      },
+      "dependencies": {
+        "semver": {
+          "version": "6.3.0",
+          "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
+          "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
+          "dev": true
+        }
       }
     },
     "parent-module": {
@@ -4731,10 +4768,9 @@
       "dev": true
     },
     "semver": {
-      "version": "6.3.0",
-      "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
-      "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
-      "dev": true
+      "version": "7.1.3",
+      "resolved": "https://registry.npmjs.org/semver/-/semver-7.1.3.tgz",
+      "integrity": "sha512-ekM0zfiA9SCBlsKa2X1hxyxiI4L3B6EbVJkkdgQXnSEEaHlGdvyodMruTiulSRWMMB4NeIuYNMC9rTKTz97GxA=="
     },
     "semver-compare": {
       "version": "1.0.0",
diff --git a/package.json b/package.json
index e95d997..313024e 100644
--- a/package.json
+++ b/package.json
@@ -136,6 +136,7 @@
     "@meetfranz/electron-notification-state": "^1.0.0",
     "i18next": "^19.0.3",
     "i18next-node-fs-backend": "^2.1.3",
-    "moment": "^2.24.0"
+    "moment": "^2.24.0",
+    "semver": "^7.1.3"
   }
 }


Test patch:
diff --git a/test/assets/settings.test-missing.json b/test/assets/settings.test-missing.json
index f976b76..6019c7f 100644
--- a/test/assets/settings.test-missing.json
+++ b/test/assets/settings.test-missing.json
@@ -3,7 +3,7 @@
     "microbreakInterval": 600000,
     "breakDuration": 300000,
     "breakInterval": 2,
-    "microbreak": false,
+    "microbreak": true,
     "mainColor": "#478484",
     "audio": "crystal-glass"
 }
diff --git a/test/settings.js b/test/settings.js
index 16c3e05..49c84f0 100644
--- a/test/settings.js
+++ b/test/settings.js
@@ -25,7 +25,6 @@ describe('Settings', () => {
     fs.writeFileSync(testMissingFileCopyLocation, testData)
     // we create copy to not worry about git changes to `test-missing.json`
     settings = new Settings(testMissingFileCopyLocation)
-    defaultSettings.microbreak = false
     settings.data.should.be.deep.equal(defaultSettings)
   })
 
@@ -44,6 +43,16 @@ describe('Settings', () => {
     }, 300)
   })
 
+  it('should set a default value in the runtime while restoring defaults', (done) => {
+    settings.restoreDefaults()
+    settings.set('isFirstRun', true)
+    // when restoring defaults, we don't reset `isFirstRun`
+    setTimeout(() => {
+      settings.data.should.be.deep.equal(defaultSettings)
+      done()
+    }, 300)
+  })
+
   it('should instantly save to a file with force enabled', () => {
     settings.set('test_key', 'test_value')
     settings._save(true)