-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
support for portable storage #56
Conversation
Electron itself also stores a lot of information in the appConfig directory and we can not change this (see previous discussion at #30 ) so I'm not comfortable calling this "portable", but maybe we can use this flag to set a custom directory to store your data instead? I prefer using https://www.npmjs.com/package/minimist by the way :) |
agreed.. yea I found minimist after I created this PR and have been using it instead as I have also created a switch to set an alternate save directory so I can sync notes with dropbox. I'll probably amend this PR with those changes..thx I thought electron had implemented the ability to change the appConfig directory by doing something like the following:
I'm relatively new to node and electron development so I'm still getting my sea legs.. |
Just as an aside I'm also using Hasklig Nerd Font Complete to support the ligatures as well as a bunch of other symbols, I find the Hasklig font to be a bit cleaner.. https://github.com/ryanoasis/nerd-fonts |
If -p could also call setPath for userdata to a selected folder then it would be portable 👍 I much prefer Fira Code to Hasklig because I really like the Fira line of fonts, Fira Mono included. |
Will do .. already have it working locally.. I'll update the PR in a bit. Would be nice to be able to set the font, because people have their favorites for sure.. I might code up a quick settings dialog for colors and fonts, let me know if you are interested, otherwise I will keep it in my own fork and just merge from upstream. Thanks again.. |
Cool, I look forward to it! No settings dialogs in FromScratch, sorry! |
ok.. so no settings dialog. I appreciate the initial vision of keeping the app clean and simple, but would you be apposed to a function that checks the data directory for a user style sheet that gets applied on start up? I think that is the route I would go for myself anyway similar to sublime and atom. |
Please see #6, I am open to user stylesheets or configurable color settings, but the current color palette is dynamically generated so it's a lot of work to overwrite it. Still though that's my preferred solution other than the 'day mode' that is already in master (but not yet in a released version) |
ok.. #6 seems to be what I had in mind, I should have checked this issues fist.. I'll put a bow on that PR today for the portable settings. |
Ok.. changes made to support command line param to set user data directory, been using it for a few hours now locally and has been working well.. Le me know if you require any changes. |
Can I also ask you to :
|
main.js
Outdated
args_slice = 2 | ||
} | ||
|
||
let argv = minimist(process.argv.slice(arg_slice)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this a const with a ternary operator? That gets rid of arg_slice
completely and argv
doesn't change anyway. Like this:
const argv = minimist(process.argv.slice(process.env.NODE_ENV === 'development' ? 2 : 1));
main.js
Outdated
let argv = minimist(process.argv.slice(arg_slice)); | ||
|
||
// get data location | ||
const dataLocation = () =>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry to nit, but please add a space between =>
and {
main.js
Outdated
defaultLocation = process.cwd() +'/userdata' | ||
if(argv.userdata){ | ||
if(typeof(argv.userdata) === 'string' ){ | ||
defaultLocation = argv.userdata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, needs a ;
(in multiple places: line 29, 34, 38 too)
(please check the eslint rules of the project, for this and spacing etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do, I'll lint before submitting the requested changes..
ok.. I think I covered all the bases , thanks.. |
Thanks, all looks good :) Would it be possible to get rid of the
(and |
sure.. I can do that.. you want that part of this PR? I assume so, but just give me a nod |
Sorry for it being a bit back-and-forth this way but yes, lets get the CLI for this right the first time. |
@CTrauma I want to make a new release of FromScratch in the next month or so, are you still interested in this PR? |
yes.. sorry.. spaced on it.. will get the latest code into pr and submit. |
For some reason the standard formatter in Atom did not respect the eslint settings, so I corrected the formatting, but it left a really messy commit. the important bit is at the top: const argv = minimist(process.argv.slice(process.env.NODE_ENV === 'development' ? 2 : 1), {
boolean: ['help'],
string: ['portable'],
alias: {
help: 'h',
portable: 'p'
}
});
if (argv.help) {
console.log(
`Usage: fromscratch [OPTION]...
Default is to start fromscratch using home directory to save data.
Optional arguments:
-p, --portable [DIRECTORY] run in portable mode, saving data in executable directory, or in alternate path
-h, --help show this usage text.`
);
process.exit(0);
}
// get data location
const dataLocation = () => {
let defaultLocation = process.env[(process.platform === 'win32') ?
'USERPROFILE' : 'HOME'] + '/.fromscratch' +
(process.env.NODE_ENV === 'development' ? '/dev' : '');
if (typeof (argv.portable) !== 'undefined') {
if (argv.portable !== '') {
defaultLocation = argv.portable;
} else {
defaultLocation = process.cwd() + '/userdata';
}
}
app.setPath('userData', defaultLocation); In order to get minimist to treat a parameter that takes a value like a boolean I just check for 'undefined' and then empty string, I couldn't find a cleaner way to do that. |
Awesome! |
will have to watch to see if any issues crop up from this. Working with making another electron based app portable, and getting the working directory is tricky and doesn't always give you what you want. I'm working on a better solution than using process.cwd(), but if it works in this case probably no need to change anything, but if issues crop up I might have a more reliable method. |
Added code to make fromscratch more portable. --portable switch saves data in /userdata directory in the application directory instead of the user profile directory.