From c86fefad9eaffed09c3c0189b0442378c2b51a97 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Thu, 20 Feb 2020 12:34:53 +0800 Subject: [PATCH] implement persistent settings #149 --- package.json | 1 + src/renderer.jsx | 32 ++++++++++++++------- src/store.js | 17 +++++++++++ yarn.lock | 74 ++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 src/store.js diff --git a/package.json b/package.json index 8409ef6f..10c17abf 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "color": "^3.1.0", "electron-default-menu": "^1.0.0", "electron-is-dev": "^0.1.2", + "electron-store": "^5.1.0", "evergreen-ui": "^4.23.0", "execa": "^0.5.0", "ffmpeg-static": "3", diff --git a/src/renderer.jsx b/src/renderer.jsx index 6ca85140..31cacea3 100644 --- a/src/renderer.jsx +++ b/src/renderer.jsx @@ -40,6 +40,7 @@ const { showMergeDialog, showOpenAndMergeDialog } = require('./merge/merge'); const allOutFormats = require('./outFormats'); const captureFrame = require('./capture-frame'); const ffmpeg = require('./ffmpeg'); +const configStore = require('./store'); const { defaultProcessedCodecTypes, getStreamFps, isCuttingStart, isCuttingEnd } = ffmpeg; @@ -106,18 +107,29 @@ const App = memo(() => { const [streamsSelectorShown, setStreamsSelectorShown] = useState(false); const [zoom, setZoom] = useState(1); - // Global state & preferences - const [captureFormat, setCaptureFormat] = useState('jpeg'); - const [customOutDir, setCustomOutDir] = useState(); - const [keyframeCut, setKeyframeCut] = useState(true); - const [autoMerge, setAutoMerge] = useState(false); + // Preferences + const [captureFormat, setCaptureFormat] = useState(configStore.get('captureFormat')); + useEffect(() => configStore.set('captureFormat', captureFormat), [captureFormat]); + const [customOutDir, setCustomOutDir] = useState(configStore.get('customOutDir')); + useEffect(() => (customOutDir === undefined ? configStore.delete('customOutDir') : configStore.set('customOutDir', customOutDir)), [customOutDir]); + const [keyframeCut, setKeyframeCut] = useState(configStore.get('keyframeCut')); + useEffect(() => configStore.set('keyframeCut', keyframeCut), [keyframeCut]); + const [autoMerge, setAutoMerge] = useState(configStore.get('autoMerge')); + useEffect(() => configStore.set('autoMerge', autoMerge), [autoMerge]); + const [timecodeShowFrames, setTimecodeShowFrames] = useState(configStore.get('timecodeShowFrames')); + useEffect(() => configStore.set('timecodeShowFrames', timecodeShowFrames), [timecodeShowFrames]); + const [invertCutSegments, setInvertCutSegments] = useState(configStore.get('invertCutSegments')); + useEffect(() => configStore.set('invertCutSegments', invertCutSegments), [invertCutSegments]); + const [autoExportExtraStreams, setAutoExportExtraStreams] = useState(configStore.get('autoExportExtraStreams')); + useEffect(() => configStore.set('autoExportExtraStreams', autoExportExtraStreams), [autoExportExtraStreams]); + const [askBeforeClose, setAskBeforeClose] = useState(configStore.get('askBeforeClose')); + useEffect(() => configStore.set('askBeforeClose', askBeforeClose), [askBeforeClose]); + const [muted, setMuted] = useState(configStore.get('muted')); + useEffect(() => configStore.set('muted', muted), [muted]); + + // Global state const [helpVisible, setHelpVisible] = useState(false); - const [timecodeShowFrames, setTimecodeShowFrames] = useState(false); const [mifiLink, setMifiLink] = useState(); - const [invertCutSegments, setInvertCutSegments] = useState(false); - const [autoExportExtraStreams, setAutoExportExtraStreams] = useState(true); - const [askBeforeClose, setAskBeforeClose] = useState(true); - const [muted, setMuted] = useState(false); const videoRef = useRef(); const timelineWrapperRef = useRef(); diff --git a/src/store.js b/src/store.js new file mode 100644 index 00000000..6dc90bbf --- /dev/null +++ b/src/store.js @@ -0,0 +1,17 @@ +const Store = require('electron-store'); + +const store = new Store({ + defaults: { + captureFormat: 'jpeg', + customOutDir: undefined, + keyframeCut: true, + autoMerge: false, + timecodeShowFrames: false, + invertCutSegments: false, + autoExportExtraStreams: true, + askBeforeClose: true, + muted: false, + }, +}); + +module.exports = store; diff --git a/yarn.lock b/yarn.lock index 5b30dcb3..b5cef9e2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1683,6 +1683,22 @@ concat-stream@1.6.2: readable-stream "^2.2.2" typedarray "^0.0.6" +conf@^6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/conf/-/conf-6.2.0.tgz#274d37a0a2e50757ffb89336e954d08718eb359a" + integrity sha512-fvl40R6YemHrFsNiyP7TD0tzOe3pQD2dfT2s20WvCaq57A1oV+RImbhn2Y4sQGDz1lB0wNSb7dPcPIvQB69YNA== + dependencies: + ajv "^6.10.2" + debounce-fn "^3.0.1" + dot-prop "^5.0.0" + env-paths "^2.2.0" + json-schema-typed "^7.0.1" + make-dir "^3.0.0" + onetime "^5.1.0" + pkg-up "^3.0.1" + semver "^6.2.0" + write-file-atomic "^3.0.0" + config-chain@^1.1.11: version "1.1.12" resolved "https://registry.yarnpkg.com/config-chain/-/config-chain-1.1.12.tgz#0fde8d091200eb5e808caf25fe618c02f48e4efa" @@ -1843,6 +1859,13 @@ dashdash@^1.12.0: dependencies: assert-plus "^1.0.0" +debounce-fn@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/debounce-fn/-/debounce-fn-3.0.1.tgz#034afe8b904d985d1ec1aa589cd15f388741d680" + integrity sha512-aBoJh5AhpqlRoHZjHmOzZlRx+wz2xVwGL9rjs+Kj0EWUrL4/h4K7OD176thl2Tdoqui/AaA4xhHrNArGLAaI3Q== + dependencies: + mimic-fn "^2.1.0" + debug@2.6.9, debug@^2.2.0, debug@^2.6.8, debug@^2.6.9: version "2.6.9" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" @@ -2002,7 +2025,7 @@ dom-helpers@^3.2.1, dom-helpers@^3.4.0: dependencies: "@babel/runtime" "^7.1.2" -dot-prop@^5.1.0: +dot-prop@^5.0.0, dot-prop@^5.1.0: version "5.2.0" resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-5.2.0.tgz#c34ecc29556dc45f1f4c22697b6f4904e0cc4fcb" integrity sha512-uEUyaDKoSQ1M4Oq8l45hSE26SnTxL6snNnqvK/VWx5wJhmff5z0FUVJDKDanor/6w3kzE3i7XZOk+7wC0EXr1A== @@ -2119,6 +2142,14 @@ electron-publish@22.3.3: lazy-val "^1.0.4" mime "^2.4.4" +electron-store@^5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/electron-store/-/electron-store-5.1.0.tgz#0b3cb66b15d0002678fc5c13e8b0c38a8678d670" + integrity sha512-uhAF/4+zDb+y0hWqlBirEPEAR4ciCZDp4fRWGFNV62bG+ArdQPpXk7jS0MEVj3CfcG5V7hx7Dpq5oD+1j6GD8Q== + dependencies: + conf "^6.2.0" + type-fest "^0.7.1" + electron-to-chromium@^1.3.47: version "1.3.351" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.351.tgz#78bcf8e9092013232b2fb72b9db423d96e92604c" @@ -2670,6 +2701,13 @@ find-up@^2.0.0, find-up@^2.1.0: dependencies: locate-path "^2.0.0" +find-up@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-3.0.0.tgz#49169f1d7993430646da61ecc5ae355c21c97b73" + integrity sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg== + dependencies: + locate-path "^3.0.0" + find-up@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19" @@ -3690,6 +3728,11 @@ json-schema-traverse@^0.4.1: resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660" integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg== +json-schema-typed@^7.0.1: + version "7.0.3" + resolved "https://registry.yarnpkg.com/json-schema-typed/-/json-schema-typed-7.0.3.tgz#23ff481b8b4eebcd2ca123b4fa0409e66469a2d9" + integrity sha512-7DE8mpG+/fVw+dTpjbxnx47TaMnDfOI1jwft9g1VybltZCduyRQPJPvc+zzKY9WPHxhPWczyFuYa6I8Mw4iU5A== + json-schema@0.2.3: version "0.2.3" resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13" @@ -3855,6 +3898,14 @@ locate-path@^2.0.0: p-locate "^2.0.0" path-exists "^3.0.0" +locate-path@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-3.0.0.tgz#dbec3b3ab759758071b58fe59fc41871af21400e" + integrity sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A== + dependencies: + p-locate "^3.0.0" + path-exists "^3.0.0" + locate-path@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0" @@ -4388,7 +4439,7 @@ p-limit@^1.1.0: dependencies: p-try "^1.0.0" -p-limit@^2.2.0: +p-limit@^2.0.0, p-limit@^2.2.0: version "2.2.2" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.2.2.tgz#61279b67721f5287aa1c13a9a7fbbc48c9291b1e" integrity sha512-WGR+xHecKTr7EbUEhyLSh5Dube9JtdiG78ufaeLxTgpudf/20KqyMioIUZJAezlTIi6evxuoUs9YXc11cU+yzQ== @@ -4402,6 +4453,13 @@ p-locate@^2.0.0: dependencies: p-limit "^1.1.0" +p-locate@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-3.0.0.tgz#322d69a05c0264b25997d9f40cd8a891ab0064a4" + integrity sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ== + dependencies: + p-limit "^2.0.0" + p-locate@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-4.1.0.tgz#a3428bb7088b3a60292f66919278b7c297ad4f07" @@ -4609,6 +4667,13 @@ pkg-dir@^2.0.0: dependencies: find-up "^2.1.0" +pkg-up@^3.0.1: + version "3.1.0" + resolved "https://registry.yarnpkg.com/pkg-up/-/pkg-up-3.1.0.tgz#100ec235cc150e4fd42519412596a28512a0def5" + integrity sha512-nDywThFk1i4BQK4twPQ6TA4RT8bDY96yeuCVBWL3ePARCiEKDRSrNGbFIgUJpLp+XeIR65v8ra7WuJOFUBtkMA== + dependencies: + find-up "^3.0.0" + pn@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/pn/-/pn-1.1.0.tgz#e2f4cef0e219f463c179ab37463e4e1ecdccbafb" @@ -5959,6 +6024,11 @@ type-fest@^0.6.0: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.6.0.tgz#8d2a2370d3df886eb5c90ada1c5bf6188acf838b" integrity sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg== +type-fest@^0.7.1: + version "0.7.1" + resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.7.1.tgz#8dda65feaf03ed78f0a3f9678f1869147f7c5c48" + integrity sha512-Ne2YiiGN8bmrmJJEuTWTLJR32nh/JdL1+PSicowtNb0WFpn59GK8/lfD61bVtzguz7b3PBt74nxpv/Pw5po5Rg== + type-fest@^0.8.0, type-fest@^0.8.1: version "0.8.1" resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d"