<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nissi Lawrence Kazembe</title>
    <description>The latest articles on DEV Community by Nissi Lawrence Kazembe (@nissikazembe).</description>
    <link>https://dev.to/nissikazembe</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F849153%2F8cefe5e4-bf76-4ac2-9b28-87b3a47721e6.jpeg</url>
      <title>DEV Community: Nissi Lawrence Kazembe</title>
      <link>https://dev.to/nissikazembe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nissikazembe"/>
    <language>en</language>
    <item>
      <title>Getting Started with ElectronJS</title>
      <dc:creator>Nissi Lawrence Kazembe</dc:creator>
      <pubDate>Tue, 10 May 2022 20:09:48 +0000</pubDate>
      <link>https://dev.to/nissikazembe/getting-started-with-electronjs-14h0</link>
      <guid>https://dev.to/nissikazembe/getting-started-with-electronjs-14h0</guid>
      <description>&lt;p&gt;Electron is a JavaScript framework built on Chromium that comes in pretty handy in developing cross-platform desktop applications. My first encounter with this framework dates back to 2019 as I found myself looking for something different to develop windows desktop apps apart from C# with WinForms. It looked interesting and ended up making a widget-sized app for displaying quotes with it, alas that was the end of our affair. This year in April, I set out to immerse myself back into it and use a project as a way of learning. This article sets out to document the experience. Bear with me it might be a bit of a read but&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The journey is more important than the destination - Bill King&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The Idea and Design
&lt;/h2&gt;

&lt;p&gt;The goal was to make an app that could be of use to improve productivity. Ever heard of Pomodoro Technique? If not read it up. It is a time management method. The app's functionality is inspired by this technique. The following were the requirements considered in the design phase.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Functional requirements&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Display tasks with corresponding details and time.&lt;/li&gt;
&lt;li&gt;Display the progress i.e. a percentage of how many tasks done.&lt;/li&gt;
&lt;li&gt;Input and save task details.&lt;/li&gt;
&lt;li&gt;Input and save app settings.&lt;/li&gt;
&lt;li&gt;Define a constant time length for executing a task and its subsequent break time.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Non-functional requirements&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Availability of data required by the application&lt;/li&gt;
&lt;li&gt;Reliable data presentation&lt;/li&gt;
&lt;li&gt;Easy to use&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Took these points into Adobe XD and came up with a couple of designs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BPaU18im--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/68hq6xgph6qllslq5aw7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BPaU18im--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/68hq6xgph6qllslq5aw7.png" alt="AdobeXD App Layout Design" width="880" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it. Nothing fancy at all but I find listing these details and having a design pinned down does allow you to focus. &lt;/p&gt;

&lt;h2&gt;
  
  
  The Execution and Outcome
&lt;/h2&gt;

&lt;p&gt;Learning never stops but it is always good to have some order to deal with all the chaos. One day I will go into detail as to how I approach technologies that are foreign to me. However, just to highlight, the areas I focus primarily are syntax and the ways data could be passed between various components. The rest can always be worked on later. Results motivate me so the goal is to get that first project done first and then build on that experience. &lt;/p&gt;

&lt;p&gt;Getting back, a month of juggling between work and coding, video tutorials and documentation readings, the results? See for yourself below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wLh5f5Mi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sjmv8aps5g36mfacta8h.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wLh5f5Mi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sjmv8aps5g36mfacta8h.gif" alt="App Demo" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A look at the code, the folder structure has two key folders &lt;em&gt;"db"&lt;/em&gt; and &lt;em&gt;"src"&lt;/em&gt;. An honorary mention to the &lt;em&gt;".circleci"&lt;/em&gt; folder, DevOps y'all, if you know you know (See, I specialize in making jokes in my spare time).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3xtjdEwr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0avi73pm9slpgsqmc9ct.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3xtjdEwr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0avi73pm9slpgsqmc9ct.png" alt="Folder Structure View" width="880" height="469"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my opinion, Electron as a framework requires understanding three things, the context bridge, the renderer, and the main processes. In condensed terms, the renderer process offers functionalities that can add dynamism to the UI. The main process has access to node modules and other components like file systems etc. However, one should view these two as separate realms that require a bridge between them. Enter the context bridge, a concept that enables mutual data sharing. Maybe a folder structure reflecting this would be suitable, something worth considering in the next project. If you are new to node project then the &lt;em&gt;package.json&lt;/em&gt; is something you must be comfortable with. Dependencies, some app info, and deployment/packaging details are defined there.&lt;/p&gt;

&lt;p&gt;Breaking down the code:&lt;/p&gt;

&lt;h3&gt;
  
  
  Main: main.js, store.js
&lt;/h3&gt;

&lt;p&gt;Despite the application, you will find yourself writing a similar type of code as below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const createMainWindow = () =&amp;gt; {
  // Create the browser window.
  mainWindow = new BrowserWindow({
    width: 400,
    height: 600,
    show: false,
    icon: 'src/tasker-view.ico',
    resizable: false,
    autoHideMenuBar:true,
    webPreferences:{
      nodeIntegration: true,
      contextIsolation: true,
      preload: path.join(__dirname, 'preload.js'),
    }
  });
  mainWindow.loadFile(path.join(__dirname, 'index.html'));

  var splashWindow = new BrowserWindow({
    width: 400,
    height: 600,
    frame: false,
    alwaysOnTop: true
  });

  splashWindow.loadFile(path.join(__dirname, 'loading.html'))
  splashWindow.center();
  setTimeout(function(){
    splashWindow.close();
    mainWindow.center();
    mainWindow.show();
  }, 5000);
  // Open the DevTools.
  //mainWindow.webContents.openDevTools();
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The BrowserWindow as the name suggests allows for the definition of the state of the container that holds your application, The dimensions, the visibility, the menus (standard menu bar or context menu) and so much more.&lt;/p&gt;

&lt;p&gt;This application is designed to keep both user preferences and a list of tasks in a flat-file format, &lt;em&gt;.json&lt;/em&gt; in this case. In store.js, methods are defined that handle the creation, writing, and reading of the JSON files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const electron = require('electron');
const path = require('path');
const fs = require('fs');

class Store{

    constructor(opts){
        const userDataPath = (electron.app || electron.remote.app).getPath('userData');

        this.path = path.join(userDataPath, opts.configName + '.json');
        this.data = parseDataFile(this.path, opts.defaults);

    }

    get(key){
        return this.data[key];
    }

    set(key, val){
        this.data[key] = val;
        fs.writeFileSync(this.path, JSON.stringify(this.data));
    }
}

function parseDataFile(filePath, defaults) {
    try{
        return JSON.parse(fs.readFileSync(filePath));
    }catch(error){
        return defaults;
    }
}

module.exports = Store; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go through the code and try to see what is going on. Done? Not so complicated right? Here we have setters and getters to keep and retrieve data and have defined that we access the defined default values from the main.js if no data has yet been stored.&lt;br&gt;
Below is the implementation in the main.js of this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const store = new Store({
  configName: 'user-preferences',
  defaults:{
    userValues:{
      name: 'Tasker User',
      resetTime: getDatePlusAdd(1),
      startTime: Date.now(),
      sessionDuration: 25,
      pauseDuration: 5,
    },
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Context Bridge: preload.js.
&lt;/h3&gt;

&lt;p&gt;Not many lines of code here but what this piece of code is doing is significant. Here we make use of the Inter-Process Communication, IPC which gives us ipcMain and ipcRenderer modules. Self-explanatory as to which process they belong to. Depending on the desired use case the implementation can be asynchronous or synchronous. The blocks of code below show the implementation of an asynchronous exchange that involves reading userValues data from the storage and passing it to the renderer side (UI).&lt;/p&gt;

&lt;p&gt;In preload.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const WINDOWS_API = {....,
    GetUserValues: () =&amp;gt; ipcRenderer.invoke('get/userValues'),
};

contextBridge.exposeInMainWorld('windowsAPI', WINDOWS_API);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the main:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let currentUserValues = store.get('userValues');
.....
.....
  ipcMain.handle('get/userValues', async ()=&amp;gt;{
    let userValues = currentUserValues;
    return userValues;
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the renderer, index.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function initializeView(){
  const userAsync = window.windowsAPI.GetUserValues();
...
...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Renderer: index.js, index.html, index.css, loading.html
&lt;/h3&gt;

&lt;p&gt;Not much to talk about here just some good old Vanilla JS, HTML, and CSS helping to make the design tick but much to be honest is done between the main.js and preload.js.&lt;/p&gt;

&lt;p&gt;And breathe!! Not a masterpiece but this is something that is good enough as a prototype and can pass the Proof Of Concept (POC) stage. Next up, optimizing and tweaking a few things as I continue learning about what this framework has to offer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/nissik120/promodorro-tasker"&gt;Find the complete source code here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you enjoyed reading it as much as I enjoyed writing this. Until the next piece. Get some comments below!!!&lt;/p&gt;

&lt;p&gt;Some useful resources used were:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.electronjs.org/docs/latest/"&gt;The official ElectronJS Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/playlist?list=PL_2VhOvlMk4XWvfNRz0oS0dbbTewX6iYG"&gt;Getting Started w/ Electron by JSimplified&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cameronnokes.com/blog/how-to-store-user-data-in-electron/"&gt;How to store user data in Electron by Cameron Nokes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>electron</category>
      <category>programming</category>
    </item>
    <item>
      <title>To Some Creativity and to Others ...</title>
      <dc:creator>Nissi Lawrence Kazembe</dc:creator>
      <pubDate>Tue, 10 May 2022 20:09:23 +0000</pubDate>
      <link>https://dev.to/nissikazembe/to-some-creativity-and-to-others--4gih</link>
      <guid>https://dev.to/nissikazembe/to-some-creativity-and-to-others--4gih</guid>
      <description>&lt;p&gt;Once in a while I find myself having an idea. Typically, this is something along the line of either a mobile, desktop, or web application. In such situations of conceiving an idea, I believe, self-awareness is an important skill to have. Realizing one's strength helps one to avoid wasting time on things that may drain the hype created by the Eureka moment.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Strike while the iron is hot. - Old Proverb&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Timing, perfect execution, and passion will always in my view produce the best results. Having a design that speaks to one's idea is one way of taking advantage of the momentum at conception. The design can take the form of UI, functional block diagrams or flowcharts, anything that allows you to present ideas to potential clients or your team. However, an area like UI design is not my strong suit. So how do I manage to still come up with something presentable? Something that requires not mentioning every now and then during a presentation that the design is in a premature state? Well, with the help of a few handy tips and tools.&lt;/p&gt;

&lt;h3&gt;
  
  
  Be Inspired
&lt;/h3&gt;

&lt;p&gt;Imitation is one form of learning, I learned this in an Expressive Arts class during my Primary School. There are so many great designs out there that you can get ideas from to create your designs. If a base design is hard to create, the various mockups available can give a sense of direction. I recommend making a sketch or wireframe layout just to kill some noise. Designs are mazes you can easily get lost in.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://dribbble.com/"&gt;Dribbble&lt;/a&gt;, my personal go-to-site.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://uplabs.com"&gt;Uplabs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What tools can you use?
&lt;/h3&gt;

&lt;p&gt;We live in fortunate times where tools are surplus that can aid in arriving at the same outcome. Other tools automate the entire process and others require more input from the user, trade-offs are inevitable. Whatever your preferences are, chances are there is something on the market for you. The tools listed here are just the bare tip of the iceberg. There are free and/or freemium offers with respect to each of these tools.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adobe XD&lt;/li&gt;
&lt;li&gt;Adobe Express&lt;/li&gt;
&lt;li&gt;Canva&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.diagrams.net/"&gt;Diagrams.net&lt;/a&gt;, formerly draw.io&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.gimp.org/"&gt;GIMP&lt;/a&gt;, the Photoshop alternative.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;To some He gave abundant creativity and others like me the ability to know when something is at least presentable. So I look for that.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hope you enjoyed this read and got something out of it. Would love to hear from you about the various tools you use.&lt;/p&gt;

&lt;p&gt;Stay Productive!!!&lt;/p&gt;

</description>
      <category>writing</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
