Create desktop folder electron - node.js

I'm using node fs to create a directory and then watch it in my electron app. Users can then use that directory to upload documents. I use chokidar to watch the directory for documents. This all works locally; fs creates the directory inside my app folder. I can drag and drop files in, everything works.
This doesn't work, however, when I deploy the app to windows. I've searched the filesystem and cannot find where this folder was created.
What I'd like to do is create the folder on their Desktop. It would be even cooler if I could react to movements of the folder (e.g. the user moves it to Documents).
Is there a way to
Create the folder on their desktop (both osx and windows)
Listen for when the folder has been moved to another location.
Thanks!
Update
Found a way to find their desktop directory
const dir = Path.join(require('os').homedir(), 'Desktop/whatever');
Is there a way to do number 2?

Related

Copying files/folders to Electron Dist folder

Long story short:
I need to copy some files/directories over from my src folder to my dist/resources folder. Is there any way I can 'automatically' copy these files/folders over during packaging? I am using Electron-packager.
Long story:
I have a couple of folders containing JSON files that need to be read and copied over to a certain user directory. These are all done when I mount a certain component.
I use readFileSync() and using path.resolve with __dirname - but this generates an error since my relative path is different when I am running the packaged app (inside dist folder). Error is it cannot find my JSON file in dist/resources/config/settings.json. Also tried to check content of my app.asar but can't seem to find it there.
So my working workaround is to copy the directory/files over from my src folder to my dist/resources folder.
But this is kind of hacky and prone to forgetting. Is there any way I can 'automatically' copy these files/folders over during packaging?
I've seen a lot of questions like this and I've never really understood them. Maybe your project structure is very different than mine (below)?
Everything that is within my "app" directory is included by electron-packager (or electron-builder – I use both) and so it's all available when the app i packaged. In my case I have some Excel templates which the user can opt to save to disk but I could just as well create a directory and copy them there at first launch (haven't tried this but assuming permissions are ok I don't doubt that it will work). Maybe that is less "clean" than having a separate resources folder?
That said, I have seen this: Electron - How to add external files?

Where to store files locally so they will not be deleted after deleting an Electron application?

Right now I store my files right inside installed app directory and on macOS after deleting an application all saved files are gone too because they were right inside .app directory.
Where should I store files so they will not be deleted after deleting an application? Both on Windows and macOS.
For example, electron-store on macOS stores all data here: ~/Library/Application Support/App Name/ but I don't know where exactly it stores it on Windows.
More context:
I have an Electron app that stores images that user saves and show it inside the app. But the user shouldn't have an easy access to these images using any file provider because these images are the part of the database and I store paths and information about them. Hope it helps :)
Typically data is stored in the user’s “app data” folder where this directory is varies by operating system.
Mac OS: ~/Library/Application Support/{Your App Name (taken from the name property in package.json)}
Windows: C:\Users\\AppData\Local{Your App Name}
Linux: ~/.config/{Your App Name}
Electron provides app.getPath which returns the right directory, depending on your platform.
check this link for more info electron-store-data

Electron: Share Files Between Different O.S Packages

I've created an Electron app and build packages for Windows and MacOS using electron-packager. The app data is stored in a JSON file inside the resources folder and i'm using fs to perform file I/O tasks in the app.
What i would like to do is store the JSON file in a folder that could be accessed by both packages (Win and Mac). This way my client could use both versions of the app and the data source will be the same, thus, the data always updated.
Since i'm a Electron newbie, is there a way to "merge" both packages and share the same data file?
Thanks to #kevingelion and #revln9 from the Slack Electron discussion, i was able to solve my issue.
All i need to use is getAppPath() and from there go to the parent folder where the data file is located:
var app = require('electron').remote.app;
resourcePath = path.join(app.getAppPath(), '../../../db/'); //shared folder

Regarding user settings - whats the purpose of the assets folder?

I want to find the correct place to save my user settings for my uwp app. I know there exists:
local: Data that exists on the current device and is backed up in the cloud
roaming: Data that exists on all devices on which the user has installed the app
temporary: Data that could be removed by the system any time the app isn't running
-localcache: Persistent data that
exists only on the current device
I can access the above places with ApplicationData.Current. Which are located somewhere in C:\Users\bla\AppData\Local\Packages\1e7e-94a6-4235-a0c5-9b143f8b_8webbwe
The project also contains a Asset folder, and I can't find a good source which tells me where the folder is located when the app is installed (not in developer mode).
Some developers place there settings into the asset folder. Why? What's the advantage? Is there also a file size limit like for ApplicationData.Current ? When deploying a settings folder into the asset folder will it be available for all user which installed my app? Any background informations regarding the asset folder are appreciated.
Settings files are most appropriate in the ApplicationData folders or ApplicationData.LocalSettings or .RoamingSettings See Store and retrieve settings and other app data
The assets folder is purely a convention. The "assets" name is not special other than to suggest what types of files go in the folder. It is just a useful way to organize the application package to have a place for assets (images, etc.) that are used in the app.
When the app is installed the assets will be in the Package.InstalledLocation directory and can be addressed with an ms-appx:///assets/ URI. Typically this will end up somewhere in \Program Files\WindowsApps\.
Putting a settings file in assets would be a bad idea as the InstalledLocation is read-only and as settings are user data.
There is no hard size limit for files in ApplicationData folders, although if too much data is stored in RoamingFolder then it won't roam. The files will still be available locally.

Linux Folder/Package Management

I'm looking for a way to store all my applications files within a single folder. However, when someone clicks on the folder I want the application inside the folder to open up as opposed to open the folder itself. I want to keep all dependancies and files inside this folder at all times.
I'm doing this because I'm going to be deploying a couple applications on a common framework and want to ensure that they are together and independent of the distribution have all requirements.
Folders are directories, and directories are distinct from files. There's no way to redirect a directory to an executable file. However, you can make a hidden directory (begin name with ".") and use an executable file to provide access to that directory. The directory will then not appear in window manager folders, just the application. However, window managers will not misrepresent the executable file as a directory.

Resources