<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kushan Pabasara on Medium]]></title>
        <description><![CDATA[Stories by Kushan Pabasara on Medium]]></description>
        <link>https://medium.com/@kushanpabasara78?source=rss-fe1f7fa26a5a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*1ZP6FNJuFby84nQ9.jpg</url>
            <title>Stories by Kushan Pabasara on Medium</title>
            <link>https://medium.com/@kushanpabasara78?source=rss-fe1f7fa26a5a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 03:20:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kushanpabasara78/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Getting Started with VoltAgent: Build AI Agents Using a Free LLM Instead of GPT-4]]></title>
            <link>https://medium.com/@kushanpabasara78/getting-started-with-voltagent-build-ai-agents-using-a-free-llm-instead-of-gpt-4-edefc01340ca?source=rss-fe1f7fa26a5a------2</link>
            <guid isPermaLink="false">https://medium.com/p/edefc01340ca</guid>
            <category><![CDATA[voltagent]]></category>
            <category><![CDATA[open-router]]></category>
            <category><![CDATA[multi-agent-systems]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Kushan Pabasara]]></dc:creator>
            <pubDate>Wed, 30 Apr 2025 20:06:13 GMT</pubDate>
            <atom:updated>2025-04-30T20:06:13.206Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*F1eFCGUuPWEV6oX6" /><figcaption>VoltAgent</figcaption></figure><p>In this blog post, I’ll introduce <a href="https://voltagent.dev/"><strong>VoltAgent</strong></a>, a TypeScript-based toolkit designed to help you easily build AI agents and even multi-agent applications. VoltAgent offers a set of ready-made building blocks, allowing developers to focus more on logic than infrastructure.</p><p>To keep things practical and beginner-friendly, I’ll walk you through building a simple AI agent. I’ll also show you how to use a <strong>free, open-source LLM</strong> as an alternative to GPT-4 — which can be costly for many developers.</p><h4>What is <strong>VoltAgent</strong>?</h4><p>Think of <a href="https://voltagent.dev/"><strong>VoltAgent</strong> </a>as a powerful toolkit built with TypeScript that helps developers create smart AI-powered applications — like chatbots, virtual assistants, or any software that can think and interact intelligently.</p><p>Instead of building everything from scratch, VoltAgent gives you a set of ready-made, modular building blocks. Here’s what makes it stand out:</p><ul><li><strong>Core Engine (@voltagent/core)<br></strong> This is the brain of VoltAgent. It provides all the essential logic and capabilities needed to run an AI agent.</li><li><strong>Modular Features<br></strong> Want your AI to speak? Just plug in @voltagent/voice. VoltAgent works like an app store for your agent — add what you need, skip what you don’t.</li><li><strong>Easy Integrations<br></strong> Your agents can connect to websites, tools, or data sources. That means your AI can do more than just chat — it can take action.</li><li><strong>Memory Support<br></strong> VoltAgent agents can remember past conversations. This allows them to hold more natural, human-like interactions.</li><li><strong>Multiple Model Support<br></strong> You’re not tied to GPT-4. VoltAgent supports multiple AI providers like <strong>OpenAI, Google, Anthropic</strong>, and more — including <strong>free and open-source models</strong>.</li><li><strong>Quick Start Tools<br></strong> Tools like create-voltagent-app and @voltagent/cli help you bootstrap projects in seconds, so you can focus on building.</li></ul><p>To monitor and manage the agents you build with VoltAgent more easily, you can use <a href="https://console.voltagent.dev/"><strong>VoltAgent Console</strong></a> — a separate tool that offers a clean, user-friendly interface. It bridges the gap between full coding flexibility and no-code convenience, making it easier to oversee and interact with your agents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*a_DW_G4XQ1H8FMKC" /><figcaption><strong>VoltAgent Console</strong></figcaption></figure><h3>🛠️ Project Setup</h3><p>You can quickly spin up a new VoltAgent project using the official CLI tool: create-voltagent-app.</p><p>Run the following command in your terminal:</p><pre>npm create voltagent-app@latest my-voltagent-app</pre><p>After running this, you’ll see a welcome screen from the VoltAgent Generator. It will guide you through a few prompts to configure your project based on your preferences.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*JPvGvJnVQoLRqrfq" /></figure><p>Once setup is complete, navigate to your project folder and start the development server:</p><pre>cd my-voltagent-app<br>npm install<br>npm run dev</pre><p>When you run the dev command, tsx will compile and run your code. You should see the VoltAgent server startup message in your terminal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/0*B0hI4VQHpEVgRNoe" /><figcaption>Server startup</figcaption></figure><h3>🚀 Interact with Your Agent</h3><p>Your agent is now up and running! To start interacting with it:</p><ol><li><strong>Open the Console<br></strong> In your terminal output, look for a link like:<br> <a href="https://console.voltagent.dev/">https://console.voltagent.dev</a><br> Click it, or copy and paste it into your browser.</li><li><strong>Find Your Agent<br></strong> Once the VoltAgent Console opens, you should see your agent listed — for example, “my-agent”.</li><li><strong>Open Agent Details<br></strong> Click on your agent’s name to view more details.</li><li><strong>Start Chatting<br></strong> On the agent detail page, click the <strong>chat icon</strong> in the bottom right corner to open the chat window.</li><li><strong>Send a Message<br></strong> Try typing something like “Hello” and hit <strong>Enter</strong> — your agent will respond!</li></ol><h3>🤔 Didn’t Get a Response from the Agent?</h3><p>No worries — I know what’s going on!</p><p>This usually happens because we didn’t set an OPENAI_API_KEY in the .env file. If you already have an OpenAI API key, you can add it like this:</p><pre># Make sure to replace &#39;your_openai_api_key&#39; with your actual key<br>OPENAI_API_KEY=your_openai_api_key</pre><p>⚠️ Note: OpenAI offers limited free usage per day. Beyond that, you’ll need to pay. You can check their usage tiers and limits here:<br><a href="https://platform.openai.com/docs/guides/rate-limits#usage-tiers"> OpenAI Rate Limits &amp; Usage Tiers</a></p><h3>🎉 The Better (Free) Option — Use OpenRouter Models</h3><p>Now for the fun part — I’ll show you how to use <a href="https://openrouter.ai/"><strong>OpenRouter</strong> </a>to connect your agent with <strong>free and open-source LLMs</strong>, so you don’t need to rely on GPT-4 or pay for every request.</p><h3>🔗 What is OpenRouter?</h3><p><a href="https://openrouter.ai/"><strong>OpenRouter</strong></a> is a platform that provides unified access to various LLMs. It supports both paid and free models, allowing developers to experiment, test, or build projects without upfront costs.</p><h3>🚀 How to get an api key</h3><h3>1. Sign Up on OpenRouter</h3><p>Head over to <a href="https://openrouter.ai/">OpenRouter.ai</a> and create a free account.</p><h3>2. Generate Your API Key</h3><ul><li>Go to <strong>Settings &gt; Keys</strong></li><li>Click <strong>Create Key</strong></li><li>Copy the generated API key</li></ul><p><em>👉 Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*o6e4DzyowoEw-kL6" /><figcaption>OpenRouter.ai</figcaption></figure><h3>🧠 Use OpenRouter for Free LLMs</h3><p>Let’s jump into the code and connect your agent to a <strong>free model</strong> using<a href="https://openrouter.ai/"> OpenRouter</a>.</p><h3>Step 1: Install the OpenRouter Provider</h3><p>First, install the OpenRouter AI SDK provider:</p><pre>npm i @openrouter/ai-sdk-provider</pre><h3>Step 2: Update Your Agent Code</h3><p>Now open your index.ts file and update the code to use an OpenRouter-supported model. In this example, we’ll use the free <strong>google/gemini-2.0-flash-exp:free</strong> model — but you can find many others on <a href="https://openrouter.ai/models?q=search">OpenRouter’s model search</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/0*qXtKV-Bpxp0N72dp" /><figcaption>OpenRouter SDK</figcaption></figure><p>Make sure you add your OpenRouter API key to your .env file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/0*q8i-wVfEBqrRR56z" /><figcaption>.env</figcaption></figure><h3>🔁 Restart and Try Again</h3><p>Now that everything is set up:</p><ol><li><strong>Restart your terminal</strong> (or stop and restart the dev server):</li></ol><pre>npm run dev</pre><ol><li>Open the <a href="https://console.voltagent.dev/"><strong>VoltAgent Console</strong></a>, click on your agent, and open the chat.</li><li><strong>Type something like</strong> “Hello” and hit <strong>Enter</strong> — this time, your agent will definitely respond! 🎉</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*45xP4Be7qCo6ydW2" /><figcaption>my-agent-app</figcaption></figure><h3>📚 Learn More About VoltAgent</h3><p>What we’ve covered is just the beginning! VoltAgent is a powerful and flexible toolkit with many features you can dive deeper into — from customizing <strong>agent options</strong>, adding <strong>memory</strong>, creating your own <strong>tools</strong>, and much more.</p><p>To explore all the concepts and capabilities, check out the official VoltAgent documentation:</p><p>👉<a href="https://voltagent.dev/docs/"> https://voltagent.dev/docs/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edefc01340ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Meet Cline: The Best Free Open-Source Alternative to Cursor]]></title>
            <link>https://medium.com/@kushanpabasara78/meet-cline-the-best-free-open-source-alternative-to-cursor-2b2d83000cbe?source=rss-fe1f7fa26a5a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b2d83000cbe</guid>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[cursor]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[cline]]></category>
            <category><![CDATA[vscode]]></category>
            <dc:creator><![CDATA[Kushan Pabasara]]></dc:creator>
            <pubDate>Sun, 13 Apr 2025 14:08:22 GMT</pubDate>
            <atom:updated>2025-04-13T14:09:07.949Z</atom:updated>
            <content:encoded><![CDATA[<p>Say goodbye to expensive AI tools — explore how Cline brings powerful, transparent coding assistance inside VS Code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g4lBlWwvCdBorE0gijo54Q.png" /><figcaption>Cline code agent</figcaption></figure><h3>✨ What is Cline?</h3><p><strong>Cline</strong> is more than just an autocomplete tool. It’s designed to <em>think, act,</em> and <em>collaborate</em> with developers inside VS Code. From generating code to executing commands and even interacting with the browser, Cline transforms VS Code into an <strong>AI-powered command center</strong>.</p><h3>🔑 Key Features That Make Cline Shine</h3><h3>🧠 Autonomous Coding Agent</h3><p>Cline can autonomously:</p><ul><li>Create and modify files</li><li>Run terminal commands</li><li>Interact with the browser<br> … all without leaving your editor.</li></ul><h3>🎯 Dual Plan/Act Modes</h3><p>Cline isn’t just reactive — it’s strategic. It offers two distinct modes:</p><ul><li><strong>Plan Mode:</strong> Cline asks questions, gathers information, and builds a clear action plan before doing anything.</li><li><strong>Act Mode:</strong> Cline immediately executes tasks based on your instructions.</li></ul><p>This approach keeps developers in control while getting the benefits of AI assistance.</p><h3>🌐 Model Context Protocol (MCP)</h3><p>Cline supports <strong>MCP servers</strong>, enabling integration with:</p><ul><li>External databases</li><li>Live documentation</li><li>Other context providers</li></ul><p>This significantly extends its coding intelligence and adaptability.</p><h3>🛠️ Open-Source and Customizable</h3><p>Being <strong>fully open-source</strong>, Cline allows developers to:</p><ul><li>Review the code</li><li>Modify behaviors</li><li>Extend features<br> No black box — total transparency.</li></ul><h3>🔐 Security &amp; Privacy: What You Need to Know</h3><p>Cline respects user privacy and data rights:</p><ul><li><strong>No User Tracking:</strong> Cline doesn’t track or store your data.</li><li><strong>Clear Privacy Policies:</strong> The documentation outlines how any user data is collected and used.</li><li><strong>Data Rights:</strong> Users can access, correct, or delete their personal data.</li><li><strong>Third-Party Sharing:</strong> Cline may share data with partners or services when necessary (and legally required).</li><li><strong>Data Protection:</strong> Reasonable security measures are taken to prevent unauthorized access.</li></ul><p>✔️ Bottom Line: Cline prioritizes <strong>privacy, transparency</strong>, and <strong>user control</strong>.</p><h3>🔌 Seamless Integration with VS Code</h3><p>Cline is built <em>for developers, by developers</em> — which is why it fits perfectly inside <strong>VS Code</strong>, one of the most popular code editors in the world.</p><ul><li><strong>Direct Integration</strong>: No complex setup — just install and start coding.</li><li><strong>Model Flexibility</strong>: Use your favorite models — local, or through platforms like <strong>OpenRouter</strong> — based on your preference or budget.</li></ul><h3>🎯 Accuracy &amp; Developer Feedback</h3><p>Using powerful AI models under the hood, Cline provides:</p><ul><li>Accurate code generation</li><li>Helpful suggestions</li><li>Faster debugging</li></ul><p>📣 Developers have reported <strong>smoother workflows</strong> and <strong>greater productivity</strong>, calling Cline a <em>game-changer for everyday coding</em>.</p><h3>🌍 Community &amp; Documentation</h3><ul><li><strong>Open-Source Community</strong>: Cline thrives thanks to its growing community of contributors and users.</li><li><strong>Comprehensive Docs</strong>: Its <a href="https://github.com/">GitHub Wiki</a> includes clear setup guides, usage tips, and examples to get you started quickly.</li></ul><h3>💸 Cost Breakdown</h3><ul><li>✅ <strong>Cline is 100% free and open-source</strong></li><li>⚠️ <em>Some AI models may have usage fees</em> depending on the provider (like OpenAI, Anthropic, etc.)</li></ul><p>This makes Cline ideal for:</p><ul><li>Indie developers</li><li>Startups</li><li>Hackathon participants</li><li>Budget-conscious teams</li></ul><h3>🆓 Use Cline for Free with OpenRouter Integration</h3><p>One of the standout advantages of using <strong>Cline</strong> is its flexibility when it comes to choosing and connecting AI models — <strong>without the cost</strong>.</p><p>Typically, using powerful language models (LLMs) comes with a price tag — based on request count or monthly subscription. But with <strong>OpenRouter</strong>, you can access a wide variety of AI models <strong>for free</strong>, and Cline makes it incredibly easy to integrate.</p><h3>🔗 What is OpenRouter?</h3><p><a href="https://openrouter.ai/"><strong>OpenRouter</strong></a> is a platform that provides unified access to various LLMs. It supports both paid and free models, allowing developers to experiment, test, or build projects without upfront costs.</p><h3>🚀 How to Connect OpenRouter with Cline (Step-by-Step)</h3><h4>1. Sign Up on OpenRouter</h4><p>Head over to <a href="https://openrouter.ai/">OpenRouter.ai</a> and create a free account.</p><h4>2. Generate Your API Key</h4><ul><li>Go to <strong>Settings &gt; Keys</strong></li><li>Click <strong>Create Key</strong></li><li>Copy the generated API key</li></ul><p><em>👉 Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g36IWvavVef4HbhScF32hg.png" /><figcaption>openRouter api key</figcaption></figure><h4>3. Paste API Key into Cline</h4><p>Open Cline in your VS Code extension settings or configuration UI, and paste the API key under the <strong>OpenRouter integration section</strong>.</p><p><em>👉 Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*qGSSmahJURWH8JM0cbA4CA.png" /><figcaption>Cline api key config</figcaption></figure><h3>🤖 Choosing the Right Free Model</h3><p>OpenRouter supports <strong>many free models</strong>, but one of the most impressive (as of now) is:</p><blockquote><em>google/gemini-2.0-flash-exp:free</em></blockquote><p>This model is fast, capable, and perfect for coding tasks, making it a great choice for most users. Of course, you’re free to explore and test other free models available on the platform.</p><h3>✅ You’re All Set!</h3><p>Once you’ve selected your model and clicked <strong>“Done”</strong>, you’re ready to use <strong>Cline’s AI code agent</strong> — completely free.</p><p>Now, you can enjoy:</p><ul><li>Code generation</li><li>Terminal commands</li><li>File modifications<br> … all powered by AI — without paying a cent.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b2d83000cbe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Electron.js:]]></title>
            <link>https://medium.com/@kushanpabasara78/mastering-electron-js-febe7b421a35?source=rss-fe1f7fa26a5a------2</link>
            <guid isPermaLink="false">https://medium.com/p/febe7b421a35</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[electronjs]]></category>
            <category><![CDATA[desktop-app]]></category>
            <category><![CDATA[cross-platform]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Kushan Pabasara]]></dc:creator>
            <pubDate>Mon, 27 Nov 2023 14:55:35 GMT</pubDate>
            <atom:updated>2023-11-28T17:06:35.505Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mastering Electron.js: A Comprehensive Guide to Cross-Platform Desktop App Development with React.js Integration</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*madwIJJTLj8vZNGobc1nGA.png" /><figcaption>React + Electron</figcaption></figure><h3>Introduction</h3><p>Electron.js is an open-source runtime framework designed for building cross-platform desktop applications using web technologies such as HTML, CSS, and JavaScript. Developed and maintained by GitHub, Electron.js combines the Chromium rendering engine with the Node.js runtime environment, providing a powerful platform for creating feature-rich desktop applications.</p><h4>Key Features</h4><ol><li>Cross-Platform Compatibility: Electron.js enables the development of applications that run seamlessly on multiple operating systems, including Mac, Windows, and Linux. This cross-platform support ensures a consistent user experience across different environments.</li><li>Web Technologies Integration: Developers can leverage their expertise in web technologies like HTML, CSS, and JavaScript to build desktop applications. Electron.js facilitates the use of familiar tools and frameworks, making the development process more accessible and efficient.</li><li>Chromium Rendering Engine: Electron.js utilizes the Chromium rendering engine, the same engine that powers the Google Chrome browser. This ensures excellent rendering performance and compatibility with modern web standards, allowing developers to create visually appealing and responsive user interfaces.</li><li>Node.js Runtime Environment: With the integration of Node.js, Electron.js enables access to a wide range of server-side functionalities. Developers can use Node.js modules to handle tasks such as file system operations, network communication, and more, extending the capabilities of their desktop applications.</li></ol><h4>Developed Using Electron.js</h4><p>Electron.js, with its versatility and cross-platform capabilities, has been employed in the creation of a diverse range of applications. Some notable examples include:</p><ul><li>Slack:</li></ul><p>Utilizing Electron.js, Slack, a widely adopted collaboration platform, ensures a consistent and seamless messaging experience across Mac, Windows, and Linux operating systems.</p><ul><li>Atom:</li></ul><p>GitHub’s Atom, a feature-rich text editor, is built upon the Electron.js framework. Its flexibility and performance are enriched by the capabilities offered by Electron.</p><ul><li>Visual Studio Code (VS Code):</li></ul><p>Microsoft’s Visual Studio Code, a popular source code editor, harnesses the power of Electron.js. Its adaptability and efficiency across various programming languages are facilitated by the Electron framework.</p><ul><li>Postman:</li></ul><p>Postman, a prevalent API development and testing tool, employs Electron.js to provide developers with a unified and reliable environment for their work on different operating systems.</p><ul><li>WordPress App:</li></ul><p>The desktop application for WordPress, developed using Electron.js, delivers a native desktop experience for efficiently managing and interacting with WordPress websites.</p><ul><li>GitHub App:</li></ul><p>GitHub’s desktop application is built with Electron.js, offering users an intuitive interface for managing repositories and collaborating on projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3DoOm_bXlhayFGva" /><figcaption>Built with electron</figcaption></figure><h4>Cross-Platform Compatibility</h4><p>With Electron, developers can maintain a unified codebase that seamlessly caters to various operating systems, including:</p><ul><li>macOS</li><li>Windows</li><li>Linux</li></ul><p>This simplifies the development process, allowing for efficient creation and maintenance of applications across diverse platforms.</p><h4>Understanding Electron’s Architecture</h4><p>Electron operates through a dual-process model consisting of the main process and renderer process, each serving distinct roles:</p><h4>Main Process</h4><p>The main process is responsible for managing the entire application. Key functionalities include:</p><ul><li>Browser Window Creation:</li></ul><p>Initiates and manages instances of browser windows, the graphical user interfaces for the application.</p><ul><li>Inter-Window Communication:</li></ul><p>Facilitates communication by sending requests between different windows and managing data transfer.</p><ul><li>File System Access:</li></ul><p>Manages access to the file system, allowing the application to interact with files and directories.</p><ul><li>Compiled Module Support:</li></ul><p>Supports the use of compiled modules, enhancing the efficiency and performance of the application.</p><ul><li>CommonJS Modules:</li></ul><p>Implements CommonJS modules, providing a modular and organized structure for code.</p><h4>Renderer Process</h4><p>The renderer process is responsible for rendering the application’s user interface. Key functionalities include:</p><ul><li>HTML &amp; CSS Renderer:</li></ul><p>Renders the graphical user interface using HTML and CSS, creating the visual elements seen by the user.</p><ul><li>Document Object Model (DOM) Access:</li></ul><p>Manages the Document Object Model, enabling dynamic updates and interactions within the user interface.</p><ul><li>Web API:</li></ul><p>Implements various Web APIs, allowing the renderer process to access additional functionalities and interact with external resources.</p><p>In summary, Electron’s main process acts as the application manager, orchestrating window creation, communication, and file system access. On the other hand, the renderer process focuses on rendering the user interface, utilizing HTML, CSS, and the DOM for a seamless and interactive user experience. This dual-process architecture allows for efficient development and management of cross-platform desktop applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*w6rq7JZqm67ZG-BW.png" /><figcaption><a href="https://www.kirupa.com/apps/what_is_electron.htm">https://www.kirupa.com/apps/what_is_electron.htm</a></figcaption></figure><h3>Getting Started with Electron.js — Step-by-Step Guide</h3><p>Before diving into Electron.js development, ensure that Node.js is installed on your machine.</p><h4>1. Initialize Your Project</h4><p>Create a package.json file by running the following command in your project directory:</p><pre>npm init -y</pre><h4>2. Install Electron</h4><p>Run the following command to install Electron as a devDependency:</p><pre>npm install electron --save-dev</pre><p>Edit the package.json file to include the main.js file as main and set up the start script:</p><pre>{<br>  &quot;name&quot;: &quot;electron&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;main.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;electron .&quot;<br>  },<br>  &quot;keywords&quot;: [],<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;devDependencies&quot;: {<br>    &quot;electron&quot;: &quot;^11.1.0&quot;<br>  }<br>}</pre><h4>3. Create the Main Process — main.js</h4><p>Create a main.js file in your project directory with the following content:</p><pre>const { app, BrowserWindow } = require(&quot;electron&quot;);<br><br>// Create the browser window.<br>function createWindow() {<br>  const mainWindow = new BrowserWindow({<br>    width: 800,<br>    height: 600,<br>    webPreferences: {<br>      nodeIntegration: true,<br>    },<br>  });<br>  mainWindow.loadFile(&quot;index.html&quot;);<br><br>  // If you want to open the DevTools use this.<br>  mainWindow.webContents.openDevTools();<br>}<br><br>// This method will be called when Electron has finished<br>// initialization and is ready to create browser windows.<br>// Some APIs can only be used after this event occurs.<br>app.whenReady().then(createWindow);<br><br>// Quit when all windows are closed, except on macOS. There, it&#39;s common<br>// for applications and their menu bar to stay active until the user quits<br>// explicitly with Cmd + Q.<br>app.on(&quot;window-all-closed&quot;, () =&gt; {<br>  if (process.platform !== &quot;darwin&quot;) {<br>    app.quit();<br>  }<br>});<br><br>app.on(&quot;activate&quot;, () =&gt; {<br>  // On macOS it&#39;s common to re-create a window in the app when the<br>  // dock icon is clicked and there are no other windows open.<br>  if (BrowserWindow.getAllWindows().length === 0) {<br>    createWindow();<br>  }<br>});</pre><h4>4. Create the Renderer Process — index.html</h4><p>Create an index.html file in your project directory with the following content:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;Hello World!&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body style=&quot;background-color: black;&quot;&gt;<br>    &lt;h1 style=&quot;color: aqua;&quot;&gt;Hello World!&lt;/h1&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><h4>5. Run Your Electron Application</h4><p>In the command line, run the following command to start your Electron application:</p><pre>npm start</pre><p>Congratulations! You’ve successfully set up a basic Electron.js application that displays “Hello World!” in a window. Feel free to explore and expand upon this foundation for your desktop application development.</p><blockquote>Let’s now move on to learning about the main concepts and functional features of Electron.</blockquote><h3>Understanding Electron IPC Flow</h3><h4>Introduction</h4><p>In Electron, Inter-Process Communication (IPC) plays a crucial role in facilitating communication between the main process and the renderer process. This communication becomes essential when the renderer process needs to invoke native desktop APIs, such as displaying error messages or utilizing dialog boxes for file-related operations.</p><h4>IPC Flow Overview</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*Q4_iv2cLTuk-LmM1rYMryA.png" /><figcaption>IPC Flow</figcaption></figure><p>The basic IPC flow involves the following steps:</p><ol><li>Renderer Process Initiates Request:</li></ol><ul><li>The renderer process initiates the IPC communication by sending an open-error-dialog event to the main process.</li></ul><p>2. Main Process Listens for Event:</p><ul><li>The main process is designed to listen for the open-error-dialog event. It acts as a central hub for handling various requests from renderer processes.</li></ul><p>3. Main Process Calls Native Desktop API:</p><ul><li>Upon receiving the event, the main process calls the native desktop API, such as displaying an error dialog box.</li></ul><p>4. Main Process Replies to Renderer Process:</p><ul><li>After performing the necessary operation, the main process sends a reply to the renderer process through the opened-error-dialog event. This reply may include relevant information or an acknowledgment.</li></ul><p>5. Renderer Process Listens for Reply:</p><ul><li>The renderer process, having initiated the request, listens for the opened-error-dialog event to receive the reply from the main process.</li></ul><p>6. Logging the Reply:</p><ul><li>The renderer process can log or process the received reply. This step allows for updating the user interface or taking further actions based on the main process’s response.</li></ul><h4>Project Setup</h4><p>To illustrate this IPC flow, let’s set up a new Electron project:</p><ol><li>Create Project Structure:</li></ol><ul><li>Initialize a new project using npm init -y.</li><li>Create the following structure:</li></ul><pre>- your_project/<br>  - index.js<br>  - preload.js<br>  - index.html</pre><p>2. Install Electron:</p><ul><li>Install Electron as a devDependency:</li></ul><pre>npm install electron --save-dev</pre><p>3. Implement Main Process — main.js:</p><ul><li>Set up the main process to handle the IPC flow in index.js.</li></ul><pre>// main.js<br>const { app, BrowserWindow, ipcMain, dialog } = require(&#39;electron&#39;);<br>const path = require(&#39;path&#39;);<br><br>function createWindow() {<br>  const mainWindow = new BrowserWindow({<br>    width: 800,<br>    height: 600,<br>    webPreferences: {<br>      preload: path.join(__dirname, &#39;preload.js&#39;),<br>    },<br>  });<br><br>  mainWindow.loadFile(&#39;index.html&#39;);<br><br>  ipcMain.on(&#39;open-error-dialog&#39;, (event, errorMessage) =&gt; {<br>    // Call native desktop API (e.g., dialog box)<br>    dialog.showErrorBox(&#39;An error message&#39;, errorMessage);<br><br>    // Reply to the renderer process<br>    event.sender.send(&#39;opened-error-dialog&#39;, `Error dialog displayed: ${errorMessage}`);<br>  });<br>}<br><br>app.whenReady().then(createWindow);</pre><p>4. Implement Preload Script — preload.js:</p><ul><li>Create a preload script to expose IPC-related APIs.</li></ul><pre>// preload.js<br>const { contextBridge, ipcRenderer } = require(&#39;electron&#39;);<br><br>contextBridge.exposeInMainWorld(&#39;electronAPI&#39;, {<br>  openErrorDialog: (errorMessage) =&gt; ipcRenderer.send(&#39;open-error-dialog&#39;, errorMessage),<br>  receiveErrorDialogResponse: (callback) =&gt;<br>    ipcRenderer.on(&#39;opened-error-dialog&#39;, callback),<br>});</pre><p>5. Implement Renderer Process — index.js:</p><ul><li>Set up the renderer process to handle user interactions and listen for responses.</li></ul><pre>// index.js<br>const showErrorBtn = document.getElementById(&#39;showErrorBtn&#39;);<br>const errorMessageInput = document.getElementById(&#39;errorMessage&#39;);<br>const responseContainer = document.getElementById(&#39;response&#39;);<br><br>showErrorBtn.addEventListener(&#39;click&#39;, function () {<br>  const errorMessage = errorMessageInput.value;<br>  window.electronAPI.openErrorDialog(errorMessage);<br>});<br><br>window.electronAPI.receiveErrorDialogResponse((_event, response) =&gt; {<br>  responseContainer.innerText = response;<br>});</pre><p>6. Create HTML — index.html:</p><ul><li>Design an HTML file with input fields and a response container.</li></ul><pre>&lt;!-- index.html --&gt;<br>&lt;body&gt;<br>  &lt;label for=&quot;errorMessage&quot;&gt;Error Message:&lt;/label&gt;<br>  &lt;input type=&quot;text&quot; id=&quot;errorMessage&quot; /&gt;<br>  &lt;button id=&quot;showErrorBtn&quot;&gt;Show Error&lt;/button&gt;<br><br>  &lt;div id=&quot;responseContainer&quot;&gt;<br>    &lt;strong&gt;Response:&lt;/strong&gt;<br>    &lt;span id=&quot;response&quot;&gt;&lt;/span&gt;<br>  &lt;/div&gt;<br><br>  &lt;script src=&quot;./index.js&quot;&gt;&lt;/script&gt;<br>&lt;/body&gt;</pre><p>7. Run the Application:</p><ul><li>Execute the following command to run the Electron application:</li></ul><pre>npm start</pre><p>8. Test the IPC Flow:</p><ul><li>Enter an error message in the input field, click the “Show Error” button, and observe the displayed error dialog and the response in the UI.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*R__K_q1VJMOKVzDWh_Gr0Q.png" /><figcaption>IPC Flow - error message show</figcaption></figure><p>This example illustrates a basic Electron IPC flow for displaying error messages using native desktop APIs, fostering communication between the main and renderer processes.</p><h3>Features</h3><h3><strong>Application Menu</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*uWXXCj2fztM5CLgPJB4XuQ.png" /><figcaption>Application menu</figcaption></figure><p>To add items to the native application menus in Electron, follow these steps in the main.js file:</p><ol><li>Import Menu Module:</li></ol><ul><li>Import the Menu module from the Electron library at the top of your file.</li></ul><pre>const { app, BrowserWindow, Menu } = require(&#39;electron&#39;);</pre><p>2. Create Menu Inside createWindow Function:</p><ul><li>Define your menu template array inside the createWindow function.</li></ul><pre>function createWindow() {<br>  // ... existing code<br><br>  const template = [<br>    // Your menu items will be added here<br>  ];<br><br>  const menu = Menu.buildFromTemplate(template);<br>  Menu.setApplicationMenu(menu);<br><br>  // ... existing code<br>}</pre><p>3. Define Menu Template:</p><ul><li>Create an array of objects to define your menu items. Each object represents a menu or submenu.</li></ul><pre>const template = [<br>  {<br>    label: &#39;File&#39;,<br>    submenu: [<br>      { label: &#39;Open&#39;, click: () =&gt; console.log(&#39;Open clicked&#39;) },<br>      { type: &#39;separator&#39; },<br>      { role: &#39;undo&#39; },<br>      { role: &#39;redo&#39; },<br>    ],<br>  },<br>  // Add more menu items as needed<br>];</pre><p>4. Use Predefined Roles:</p><ul><li>Electron provides predefined roles for common actions like undo, redo, cut, and copy. You can use them directly in your submenu.</li></ul><pre>{ role: &#39;undo&#39; },<br>{ role: &#39;redo&#39; },</pre><p>5. Open External Web Page:</p><ul><li>If you need to open an external web page when clicking a menu item, use the shell method. (Details about the Shell module will be explained later.)</li></ul><pre>{ label: &#39;Visit Website&#39;, click: () =&gt; require(&#39;electron&#39;).shell.openExternal(&#39;https://example.com&#39;) },</pre><p>6. Set Menu and Attach to Application:</p><ul><li>Set the menu using Menu.buildFromTemplate and attach it to the application.</li></ul><pre>const menu = Menu.buildFromTemplate(template);<br>Menu.setApplicationMenu(menu);</pre><p>7. Result:</p><ul><li>Now, when you start your application, you’ll see the defined menu at the top of your application.</li></ul><p>This structure allows you to customize your application’s menu with various items and actions.</p><h3>Context Menu</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*jBaJnm8AN7GX5cU1RHGo1Q.png" /><figcaption>Context menu</figcaption></figure><p>To implement a context menu in an Electron application, you can create a function within the createWindow function, let&#39;s call it contextMenu, and pass the mainWindow as a parameter. Inside this function, you&#39;ll create a new instance of the Menu class. You can then append menu items to this context menu, specifying actions for each item.</p><p>To make this context menu visible upon a right-click on the application window, you’ll attach the context menu to the context-menu event of the mainWindow.webContents. This event is triggered when a right-click occurs, and it opens the context menu at the specified coordinates.</p><p>By following these steps, you enhance the user experience by providing context-specific actions accessible through a right-click within your Electron application.</p><pre>const { app, BrowserWindow, Menu, MenuItem } = require(&#39;electron&#39;);<br><br>function createWindow() {<br>  const mainWindow = new BrowserWindow({<br>    width: 800,<br>    height: 600,<br>    webPreferences: {<br>      nodeIntegration: true,<br>    },<br>  });<br><br>  // ... existing code<br><br>  // New function for creating a context menu<br>  function contextMenu(event) {<br>    // Create a new instance of the Menu class<br>    const contextMenu = new Menu();<br><br>    // Append menu items to the context menu<br>    contextMenu.append(new MenuItem({ label: &#39;Cut&#39;, role: &#39;cut&#39; }));<br>    contextMenu.append(new MenuItem({ label: &#39;Copy&#39;, role: &#39;copy&#39; }));<br>    contextMenu.append(new MenuItem({ label: &#39;Paste&#39;, role: &#39;paste&#39; }));<br><br>    // Show the context menu at the specified coordinates<br>    contextMenu.popup({ window: mainWindow, x: event.x, y: event.y });<br>  }<br><br>  // Attach context menu to mainWindow webContents context-menu event<br>  mainWindow.webContents.on(&#39;context-menu&#39;, (event, params) =&gt; {<br>    contextMenu(params);<br>  });<br><br>  // ... existing code<br>}<br><br>app.whenReady().then(createWindow);<br><br>app.on(&#39;window-all-closed&#39;, () =&gt; {<br>  if (process.platform !== &#39;darwin&#39;) {<br>    app.quit();<br>  }<br>});<br><br>app.on(&#39;activate&#39;, () =&gt; {<br>  if (BrowserWindow.getAllWindows().length === 0) {<br>    createWindow();<br>  }<br>});</pre><h3><strong>Accelerators and Global Shortcuts</strong></h3><p>Accelerators are strings that can contain multiple modifiers and a single key code, combined by the ‘+’ character. They are used to define keyboard shortcuts throughout your application.</p><pre>const { app, BrowserWindow, Menu, globalShortcut, shell } = require(&#39;electron&#39;);<br><br>function createWindow() {<br>  const mainWindow = new BrowserWindow({<br>    width: 800,<br>    height: 600,<br>    webPreferences: {<br>      nodeIntegration: true,<br>    },<br>  });<br><br>  // ... existing code<br><br>  // New function for creating the application menu<br>  function applicationMenu() {<br>    // Create a template for the menu<br>    const template = [<br>      {<br>        label: &#39;File&#39;,<br>        submenu: [<br>          {<br>            label: &#39;Open External Website&#39;,<br>            click: () =&gt; shell.openExternal(&#39;https://example.com&#39;),<br>            accelerator: &#39;CmdOrCtrl+Shift+H&#39;,<br>          },<br>        ],<br>      },<br>      // Add more menu items as needed<br>    ];<br><br>    // Attach the template to the menu<br>    const menu = Menu.buildFromTemplate(template);<br>    Menu.setApplicationMenu(menu);<br>  }<br><br>  // Call the applicationMenu function<br>  applicationMenu();<br><br>  // Register global shortcuts<br>  globalShortcut.register(&#39;CmdOrCtrl+Shift+H&#39;, () =&gt; {<br>    console.log(&#39;Global shortcut activated!&#39;);<br>    // Add your action for the global shortcut here<br>  });<br><br>  // ... existing code<br>}<br><br>app.whenReady().then(createWindow);<br><br>app.on(&#39;window-all-closed&#39;, () =&gt; {<br>  if (process.platform !== &#39;darwin&#39;) {<br>    app.quit();<br>  }<br>});<br><br>app.on(&#39;activate&#39;, () =&gt; {<br>  if (BrowserWindow.getAllWindows().length === 0) {<br>    createWindow();<br>  }<br>});<br><br>// Unregister global shortcuts when quitting the app<br>app.on(&#39;will-quit&#39;, () =&gt; {<br>  globalShortcut.unregisterAll();<br>});</pre><p>In this completed code, the applicationMenu function creates a menu template with an item that opens an external website using the shell module. The accelerator &#39;CmdOrCtrl+Shift+H&#39; is set for this menu item. Global shortcuts are registered using globalShortcut.register, and they are unregistered when the app is about to quit to prevent conflicts.</p><h3>Shell</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LaHTenpA9-Et_G7-Ij831A.png" /><figcaption>Shell module</figcaption></figure><p>The Shell module is used to open a folder or file within a folder or open an external URL in the default browser.</p><p>For example, we are creating a button, and when it is clicked, it will show the folder location of a particular file, open an image file, and finally, open an external URL in our default browser.</p><h4>1. Renderer Process Files</h4><p>renderer.html</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>  &lt;meta charset=&quot;UTF-8&quot;&gt;<br>  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>  &lt;title&gt;Shell Module Example&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;button id=&quot;openButton&quot;&gt;Open File and URL&lt;/button&gt;<br>  &lt;script src=&quot;./renderer.js&quot;&gt;&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>This HTML file (renderer.html) contains a button with the id &#39;openButton&#39;.</p><p>renderer.js</p><pre>// renderer.js<br>const { ipcRenderer } = require(&#39;electron&#39;);<br><br>document.getElementById(&#39;openButton&#39;).addEventListener(&#39;click&#39;, () =&gt; {<br>  // Trigger the &#39;open&#39; event to signal the main process<br>  ipcRenderer.send(&#39;open&#39;);<br>});</pre><p>In this JavaScript file (renderer.js), a click event listener is added to the button. When the button is clicked, it sends an &#39;open&#39; event to the main process using ipcRenderer.</p><h4>2. Preload Script</h4><p>preload.js</p><pre>// preload.js<br>const { contextBridge, ipcRenderer } = require(&#39;electron&#39;);<br><br>contextBridge.exposeInMainWorld(&#39;electronAPI&#39;, {<br>  open: () =&gt; ipcRenderer.send(&#39;open&#39;),<br>});</pre><p>This preload script (preload.js) exposes an &#39;electronAPI&#39; object to the window, allowing the renderer process to call the open method, which in turn triggers the &#39;open&#39; event.</p><h4>3. Main Process</h4><p>main.js</p><pre>// main.js<br>const { app, BrowserWindow, ipcMain, shell } = require(&#39;electron&#39;);<br><br>function createWindow() {<br>  const mainWindow = new BrowserWindow({<br>    width: 800,<br>    height: 600,<br>    webPreferences: {<br>      nodeIntegration: false,<br>      contextIsolation: true,<br>      preload: path.join(__dirname, &#39;preload.js&#39;),<br>    },<br>  });<br><br>  mainWindow.loadFile(&#39;renderer.html&#39;);<br><br>  // Catch the &#39;open&#39; event from the renderer process<br>  ipcMain.on(&#39;open&#39;, () =&gt; {<br>    // Use shell module to show folder, open file, and open external URL<br>    shell.showItemInFolder(&#39;/path/to/your/file.txt&#39;);<br>    shell.openPath(&#39;/path/to/your/file.txt&#39;);<br>    shell.openExternal(&#39;https://example.com&#39;);<br>  });<br>}<br><br>app.whenReady().then(createWindow);<br><br>app.on(&#39;window-all-closed&#39;, () =&gt; {<br>  if (process.platform !== &#39;darwin&#39;) {<br>    app.quit();<br>  }<br>});<br><br>app.on(&#39;activate&#39;, () =&gt; {<br>  if (BrowserWindow.getAllWindows().length === 0) {<br>    createWindow();<br>  }<br>});</pre><p>In the main process (main.js), a createWindow function sets up the Electron window. It loads the renderer.html file and listens for the &#39;open&#39; event triggered by the renderer process. When the &#39;open&#39; event is received, the shell module is used to show a folder, open a file, and open an external URL. The preload script (preload.js) facilitates communication between the main and renderer processes.</p><p>This example demonstrates how to use the shell module to interact with the file system and open external URLs from the renderer process with proper IPC communication and security measures.</p><h3>Tray</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*JEgbA_7Z-_nKSOlFwxbJFQ.png" /><figcaption>Tray</figcaption></figure><p>This guide will walk you through the process of creating a Tray icon with its own context menu in the system’s notification area.</p><p>On macOS and Ubuntu, the Tray will be located in the top right corner of your screen, adjacent to your battery and Wi-Fi icons. On Windows, the Tray is typically located in the bottom right corner.</p><p>Below is an example code snippet to create a Tray icon with its own context menu in an Electron application:</p><pre>// main.js<br>const { app, BrowserWindow, Tray, Menu } = require(&#39;electron&#39;);<br>const path = require(&#39;path&#39;);<br><br>let tray = null;<br><br>function createTray() {<br>  // Create a new instance of the Tray with a path to your tray icon<br>  tray = new Tray(path.join(__dirname, &#39;path/to/tray-icon.png&#39;));<br><br>  // Create a context menu for the tray<br>  const contextMenu = Menu.buildFromTemplate([<br>    { label: &#39;Item 1&#39;, type: &#39;normal&#39;, click: () =&gt; console.log(&#39;Clicked Item 1&#39;) },<br>    { label: &#39;Item 2&#39;, type: &#39;normal&#39;, click: () =&gt; console.log(&#39;Clicked Item 2&#39;) },<br>    { type: &#39;separator&#39; },<br>    { label: &#39;Quit&#39;, type: &#39;normal&#39;, role: &#39;quit&#39; },<br>  ]);<br><br>  // Set the context menu for the tray<br>  tray.setContextMenu(contextMenu);<br><br>  // Set tooltip for the tray icon<br>  tray.setToolTip(&#39;My Electron App&#39;);<br>}<br><br>app.whenReady().then(() =&gt; {<br>  createTray();<br><br>  app.on(&#39;activate&#39;, () =&gt; {<br>    if (BrowserWindow.getAllWindows().length === 0) {<br>      createTray();<br>    }<br>  });<br>});<br><br>app.on(&#39;window-all-closed&#39;, () =&gt; {<br>  if (process.platform !== &#39;darwin&#39;) {<br>    app.quit();<br>  }<br>});</pre><p>Explanation:</p><ol><li>Create Tray:</li></ol><ul><li>The createTray function creates a new instance of the Tray class and sets the path to the tray icon.</li></ul><p>2. Context Menu:</p><ul><li>A context menu is created using the Menu.buildFromTemplate method. It includes items like &quot;Item 1,&quot; &quot;Item 2,&quot; and a separator. The &quot;Quit&quot; item uses the role: &#39;quit&#39; to handle the quitting action.</li></ul><p>3. Set Context Menu and Tooltip:</p><ul><li>The context menu is set for the tray using tray.setContextMenu(contextMenu).</li><li>The tooltip for the tray icon is set using tray.setToolTip(&#39;My Electron App&#39;</li></ul><p>This code will create a Tray icon with a context menu containing “Item 1,” “Item 2,” and a “Quit” option, and it will display the tooltip “My Electron App” when hovered over.</p><h3>Elevate Your Electron App: Unleashing the Power of React.js as the Renderer Process</h3><p>If you are most familiar with a JavaScript framework or library, you can use it as the renderer process in your Electron application. In this example, we will use React.js as the renderer process. Let’s proceed step by step.</p><p>First, scaffold the application using create-react-app:</p><pre>npx create-react-app electron-react-app</pre><p>Now, go to the public folder and create main.js file:</p><pre>// public/main.js<br>const { app, BrowserWindow } = require(&#39;electron&#39;);<br><br>function createWindow() {<br>  const win = new BrowserWindow({<br>    width: 800,<br>    height: 600,<br>    webPreferences: {<br>      nodeIntegration: true,<br>    },<br>  });<br><br>  win.loadURL(&#39;http://localhost:3000&#39;);<br>  win.webContents.openDevTools();<br>}<br><br>app.whenReady().then(createWindow);<br><br>app.on(&#39;window-all-closed&#39;, () =&gt; {<br>  if (process.platform !== &#39;darwin&#39;) {<br>    app.quit();<br>  }<br>});<br><br>app.on(&#39;activate&#39;, () =&gt; {<br>  if (BrowserWindow.getAllWindows().length === 0) {<br>    createWindow();<br>  }<br>});</pre><p>Open your package.json file and add the main entry pointing to public/main.js:</p><pre>// package.json<br>{<br>  &quot;main&quot;: &quot;public/main.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;react-scripts start&quot;,<br>    &quot;build&quot;: &quot;react-scripts build&quot;,<br>    &quot;test&quot;: &quot;react-scripts test&quot;,<br>    &quot;eject&quot;: &quot;react-scripts eject&quot;,<br>    &quot;electron-dev&quot;: &quot;electron .&quot;<br>  }<br>}</pre><p>Now, install Electron:</p><pre>npm install electron</pre><p>To run the Electron app, add an entry to the scripts section:</p><pre>// package.json<br>&quot;scripts&quot;: {<br>  &quot;start&quot;: &quot;react-scripts start&quot;,<br>  &quot;build&quot;: &quot;react-scripts build&quot;,<br>  &quot;test&quot;: &quot;react-scripts test&quot;,<br>  &quot;eject&quot;: &quot;react-scripts eject&quot;,<br>  &quot;electron-dev&quot;: &quot;electron .&quot;<br>}</pre><p>Now, start the React app in one terminal:</p><pre>npm start</pre><p>In another terminal, run the Electron app:</p><pre>npm run electron-dev</pre><p>You should see a native desktop window running your Electron app alongside the React app.</p><h3>Conclusion</h3><p>In this article, I aim to elucidate the concept of building Electron.js applications and simplifying the renderer process through the utilization of various JavaScript libraries and frameworks. My aspiration is that you can develop more productive applications by referencing the insights presented in this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=febe7b421a35" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Drag & Drop Image up-loader and image sorting Component (No NPM Packages)]]></title>
            <link>https://medium.com/@kushanpabasara78/react-drag-drop-image-up-loader-and-image-sorting-component-no-npm-packages-b816030fc8f0?source=rss-fe1f7fa26a5a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b816030fc8f0</guid>
            <category><![CDATA[drag-and-drop]]></category>
            <category><![CDATA[no-npm]]></category>
            <category><![CDATA[drag-and-sort]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Kushan Pabasara]]></dc:creator>
            <pubDate>Tue, 17 Aug 2021 07:04:34 GMT</pubDate>
            <atom:updated>2021-08-18T05:51:49.332Z</atom:updated>
            <content:encoded><![CDATA[<p>When I was dealing with my project clients, I received a task to build components for drag and drop image up-loader and image sorting. Here I have drafted it as a simple project. I used React to build that and if you’re a beginner, it’s better to learn the main concepts of React before starting this.</p><p>This is the behavior of component</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W6M9pt7BmPqkQBiijohkdQ.gif" /><figcaption><em>(Don’t think about UI. I’m little bit poor with CSS</em>)</figcaption></figure><p>Here I drafted the functionality of the component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bI9UQ1DtBOKMonn8w0m_lw.jpeg" /><figcaption>Drafted image of component behavior</figcaption></figure><h4><strong>Let’s Start</strong></h4><p>First of all Create react app</p><blockquote><em>npx create-react-app drag-and-drop</em></blockquote><blockquote><em>cd drag-and-drop</em></blockquote><blockquote><em>npm start</em></blockquote><p>And install font awesome. Because we use font awesome icon for image delete button</p><blockquote><em>npm install — save @fortawesome/fontawesome-svg-core</em></blockquote><blockquote><em>npm install — save @fortawesome/free-solid-svg-icons</em></blockquote><blockquote><em>npm install — save @fortawesome/react-fontawesome</em></blockquote><h4>Here my App component</h4><p>There are two child components and App.css imported.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tfm9Lg08aZ_eymamD0vE-g.png" /><figcaption>Image of App.jsx</figcaption></figure><h4>Uploader component</h4><p>First implement html file uploader to upload component and add <em>onChange</em> function. After that, read the uploaded file in the function and pass images one by one into the App component <em>(using imagesPreviewUrls prop)</em>.</p><p>And <em>checkMimeType</em> function is used to check image type.If you want to check file size and maximum files of upload images, you can create new functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yVwjVBEYxE1YBHeHaUPW3A.png" /><figcaption>Image of uploader.jsx</figcaption></figure><h4><strong>Preview Component</strong></h4><p>Here we store all uploaded images to <em>previewImages</em> state.We use <em>onDrop, onDragStart, onDragOver</em> for image sorting. At the <em>onDragOver</em> we recognize <em>dragId</em> and <em>dropId</em>, after that we can change image positions using splice() method. <em>(check handleDrop() and moveItem() )</em></p><p>When deleting an image, find the image id and that passes to the App component using <em>deleteImage</em> prop.The app component can filter the array using deleted image id.</p><p>In the console we can see a sorted image array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kcxFeoMW5AnvizPYNF82mg.png" /><figcaption>Image of preview.jsx</figcaption></figure><h4><strong>App.css</strong></h4><p>You can change CSS as you wish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*p0IhHakLfI-5D7aO3srkrQ.png" /><figcaption>Image of app.css</figcaption></figure><h4>Check Preview : <a href="https://codesandbox.io/s/late-lake-tjhw3">https://codesandbox.io/s/late-lake-tjhw3</a></h4><h4>GitHub : <a href="https://github.com/kushan1992/Drag-N-Drop">https://github.com/kushan1992/Drag-N-Drop</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b816030fc8f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>