File Manager Electronjs application example
There are a lot of ideas that come to mind when it comes to making an electronjs project example, one of which would be to make a file manager. This is one of many project ideas where getting the core set of features working might not take to long, but in the long run can turn into a major project that can take months, or even years to refine if doing so is justified. The starting point I had in mind was to just have a way to navigate around a file system, and be able to start a terminal window at the current working folder. Just that alone is simple enough for sure, but then there is working on the additional basic features that one would expect of any file manager, and how to go about doing just that. There is working out javaScript solutions for everything, but then there is also the idea of using the child process module to make use of binaries that there are to work with in the underlaying OS and being done with it.
This will then be a post on the current state of an electionjs project where the aim is to start making something that is at least starting to look like a file manager program. Like many of these examples thus far I will want to keep the bar low for now unless I do start to use this all the time, or people take interest or so forth. The main goal then is to just be able to navigate around folders, and then start a terminal window or alternate file manager at the current path. On top of that there is also getting this to work on the operating system that I use most of the time which for now are windows 10 and Raspberry Pi OS.
The election.js File manager project example and what to knwo first
This is a post on an electionjs project example where the aim is to make a file manager using electionjs. This is not then any kind of getting started type post with the basics of electionjs, as well as any additional skills that are required that have to do with nodejs, as well as client side javaScript. However in these sections I do often like to wrote about at least a few things that you might want to read up more on before continuing to read the rest if this content.
Source Code is up on Gihub also
I have the source code for this project also up on Github.
1 - The main javaScript file
Nothing out of the usual when it comes to the main javaScript file for this electron project thus far. I just have a create window method that will create the first, and also any additional windows for a current file system location to view the contents of. So the create window method will be called for the first time when the app starts, and also whenever I use the application menu to create a new window from the file menu. Speaking of the file menu I am using a custom menu template for this project of course that I also define here in this main javaScrit file as well.
|
|
2 - The preload javascript file
In the preload file I will want to define a number of methods that I can use in my client system to get the contents of a current working folder. The idea here is that I will bee storing what the current working path is in the client system, but will need a number of methods here to make use of nodejs features that will allow me to get the contents of a current working folder. So then for this preload file I am once again using the context bride module to go about defining what the public API should be in terms of a fm global that I can use from the client system.
So then I am making use of a whole lot of nodejs built in module for this preload file then such as the os module to have a way to find out what platform this is running on, as well as having a way to quickly fine out where the home folder is for the system. I am also going to want to use many of the methods in the path module for this one as well of course as this is very much a project in which I will be dealing with that a whole lot. To help me read the contents of the current working folder I will of course need to use the read dir method of the file system module, and I will also want to use the file system module to get stat objects as well for sure. Also on top of all of this I will also want to have a way to run commands from my client system that will differ from one platform to another, so I will want to have the exec and spawn methods of the child process module at the ready as well for thous kinds of methods.
|
|
3 - The Client System
When it comes to the client system for this project I have an html folder in which I will have all front end code and other assets. In this html folder I have a main window html file that make used of a few additional javaScript files, and an css file to have at least some basic staring style for this project. In this section then I will be going over the state of these various files that make use of my main and preload election js files.
3.1 - The main window HTML file
In the main html file I am making use of a CSP policy, and am also linking to an external CSS file in the head of the file. In the body of the html I have a basic layout for the various parts of the user interface for this file manager program. At the bottom of the file I am linking to my actions javaScrit file first, then an additional javaScript file that will contain any main javaScript code for just this html file. In any future revisions of this example I might have additional html files, but for now I am just staring that kind of situation thus far.
|
|
3.1 - Actions javaScript file
If I do continue to work on this project I am going to want to get things working great on more than one platform. In time I might want to have some kind of system where I have a whole bunch of files where there are a custom set of functions for each target file system. So when I make a built I just need to swap in a single javaScript file for a target OS. Also I am sure that I will want to have a way to customize what I am working out here though some kind of settings dialog or something to that effect. However for now I have just this one file in which I have everything for the two target OS systems that I am supporting thus far.
|
|
3.1 - Main window javaScript file
This is then the current state of the main javaScript file in which I am doing everything that I want to do in the main html file. this is where I have a current state object that contains values like the current working path, as well as many other state values. I am also attaching any and all event handers that i want to have for things like the tool bar as well as all the item dive elements for the contents of the current working path.
|
|
3.1 - style CSS file
When it comes to the CSS for this project I have worked out a few things using a CSS Grid, which is a new thing for me. I am sure that there is a great deal more to write about when it comes to GRIDS and CSS, but for now I just have a basic something working okay when it comes to the div elements that I use to display a folder or file.
|
|
Conclusion
When it comes to the very basic idea of what I wanted to start with making this I all ready have that working well. All I wanted was a way to navigate around a file system and then start a terminal window, or start another file manager and that is it. I also wanted to work out some platform specific things while I was at it such as starting a Linux bash prompt window in a Linux system, and a command prompt window in a windows system. So with that aid because I set the bar so low I was able to get what I wanted working fast which is great. However when it comes to turning this into a major project that other people might like to use I of course would have a lot more work ahead of me with this. That seams to be the case with every electronjs example project that I have started thus far though. The most basic form of the project is easy enough to get up and running, but work will never truly be done with it if I choose to continue to support it.