Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save the path of the last time a gpx file was exported #9

Merged
merged 2 commits into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"dependencies": {
"autolesshint": "^0.2.2",
"dateformat": "^3.0.3",
"electron-json-storage": "^4.1.7",
"keytar": "^4.13.0",
"lessc": "^1.0.2",
"lesshint": "^6.3.7"
Expand Down
20 changes: 20 additions & 0 deletions src/preferences.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const storage = require('electron-json-storage');

const path = require('path');
const util = require('util');


class Preferences {

async getLastSaveDir() {
return util.promisify(storage.get)('LAST_SAVE_DIR')
}

async updateLastSaveDir(filePath) {
const directoryPath = path.dirname(filePath);

await util.promisify(storage.set)('LAST_SAVE_DIR', directoryPath)
}
}

module.exports = Preferences;
26 changes: 17 additions & 9 deletions view/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Activity = require('../src/withings/activity.js')
const GpxGenerator = require('../src/gpxgenerator.js')
const dateFormat = require('dateformat');
const fs = require('fs')

const Preferences = require('../src/preferences')

let login = new Login()
let account = new Account()
Expand Down Expand Up @@ -233,20 +233,28 @@ async function generateGpx(selectedActivity){
+ '.gpx'

const { dialog, app } = require('electron').remote

const preferences = new Preferences()

const lastSaveDir = await preferences.getLastSaveDir();

const options = {
defaultPath: app.getPath('documents') + '/' + fileName,
defaultPath: (lastSaveDir ? lastSaveDir : app.getPath('documents')) + '/' + fileName,
}
dialog.showSaveDialog(null, options, (path) => {
if(path){

const { filePath } = await dialog.showSaveDialog(null, options);

if( filePath ){
try{
fs.writeFileSync(path, gpxContent, 'utf-8');
fs.writeFileSync(filePath, gpxContent, 'utf-8');

await preferences.updateLastSaveDir(filePath);
}catch(e){
alert('failed to save the file: ' + e);
}
}
hideAllPanels();
document.getElementById('activitiesDialog').hidden = false;
});
}
hideAllPanels();
document.getElementById('activitiesDialog').hidden = false;
}

startAutoLogin();
35 changes: 33 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ async-exit-hook@^2.0.1:
resolved "https://registry.yarnpkg.com/async-exit-hook/-/async-exit-hook-2.0.1.tgz#8bd8b024b0ec9b1c01cccb9af9db29bd717dfaf3"
integrity sha512-NW2cX8m1Q7KPA7a5M2ULQeZ2wR5qI5PAbw5L0UOMxdioVk9PMZ0h1TmyZEkPYrCvYjDlFICusOu1dlEKAAeXBw==

async@^2.0.0:
version "2.6.3"
resolved "https://registry.yarnpkg.com/async/-/async-2.6.3.tgz#d72625e2344a3656e3a3ad4fa749fa83299d82ff"
integrity sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==
dependencies:
lodash "^4.17.14"

asynckit@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
Expand Down Expand Up @@ -911,6 +918,18 @@ electron-download@^4.1.0:
semver "^5.4.1"
sumchecker "^2.0.2"

electron-json-storage@^4.1.7:
version "4.1.7"
resolved "https://registry.yarnpkg.com/electron-json-storage/-/electron-json-storage-4.1.7.tgz#8a7028a1aab8f5d3dd8856fbc6d4d4afdcdd0b7e"
integrity sha512-dUjTJtESbtI1w1dVjcuc8CcWrAX8azhg47EllDw6yn7lcMDwFVKiUv+ajyFkMDAsuAQWY5fdomrexyvRdv1akg==
dependencies:
async "^2.0.0"
lockfile "^1.0.4"
lodash "^4.0.1"
mkdirp "^0.5.1"
rimraf "^2.5.1"
write-file-atomic "^2.4.2"

electron-publish@21.2.0:
version "21.2.0"
resolved "https://registry.yarnpkg.com/electron-publish/-/electron-publish-21.2.0.tgz#cc225cb46aa62e74b899f2f7299b396c9802387d"
Expand Down Expand Up @@ -1915,6 +1934,13 @@ locate-path@^3.0.0:
p-locate "^3.0.0"
path-exists "^3.0.0"

lockfile@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/lockfile/-/lockfile-1.0.4.tgz#07f819d25ae48f87e538e6578b6964a4981a5609"
integrity sha512-cvbTwETRfsFh4nHsL1eGWapU1XFi5Ot9E85sWAwia7Y7EgB7vfqcZhTKZ+l7hCGxSPoushMv5GKhT5PdLv03WA==
dependencies:
signal-exit "^3.0.2"

lodash.assign@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.assign/-/lodash.assign-4.2.0.tgz#0d99f3ccd7a6d261d19bdaeb9245005d285808e7"
Expand All @@ -1930,6 +1956,11 @@ lodash.orderby@^4.6.0:
resolved "https://registry.yarnpkg.com/lodash.orderby/-/lodash.orderby-4.6.0.tgz#e697f04ce5d78522f54d9338b32b81a3393e4eb3"
integrity sha1-5pfwTOXXhSL1TZM4syuBozk+TrM=

lodash@^4.0.1, lodash@^4.17.14:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==

log-symbols@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-2.2.0.tgz#5740e1c5d6f0dfda4ad9323b5332107ef6b4c40a"
Expand Down Expand Up @@ -2804,7 +2835,7 @@ ret@~0.1.10:
resolved "https://registry.yarnpkg.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc"
integrity sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==

rimraf@2:
rimraf@2, rimraf@^2.5.1:
version "2.7.1"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec"
integrity sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==
Expand Down Expand Up @@ -3509,7 +3540,7 @@ wrappy@1:
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=

write-file-atomic@^2.0.0:
write-file-atomic@^2.0.0, write-file-atomic@^2.4.2:
version "2.4.3"
resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-2.4.3.tgz#1fd2e9ae1df3e75b8d8c367443c692d4ca81f481"
integrity sha512-GaETH5wwsX+GcnzhPgKcKjJ6M2Cq3/iZp1WyY/X1CSqrW+jVNM9Y7D8EC2sM4ZG/V8wZlSniJnCKWPmBYAucRQ==
Expand Down