Skip to content

vikassharmapunj/Envision-Automator

Repository files navigation

Converting HTML to a Desktop Application for API Interaction (Windows) This document outlines the steps required to encapsulate an HTML-based user interface within a desktop application framework (Electron) on a Windows operating system. This will enable the HTML to function similarly to API interaction tools like Postman.

Prerequisites:

Node.js and npm Installation: Ensure that Node.js is installed on your Windows system. The Node.js installation package includes npm (Node Package Manager). Download the appropriate installer from the official website: https://nodejs.org/. Following the installation, it is crucial to restart any active command prompt sessions to ensure the node and npm commands are recognized by the system's environment variables. Procedure:

Project Directory Creation:

Open the Windows command prompt.

Utilize the cd (change directory) command to navigate to the desired location for your project.

Execute the mkdir (make directory) command to create a dedicated project folder. Subsequently, use cd to enter this newly created directory.

DOS

mkdir my-postman-app cd my-postman-app Project Initialization:

Within the project directory (my-postman-app), initialize a Node.js project using the following command. This will generate a package.json file, which serves as a manifest for your project.

DOS

npm init -y Electron Installation:

Install the Electron framework as a development dependency for your project. Electron enables the creation of cross-platform desktop applications using web technologies.

DOS

npm install electron --save-dev Creation of the Main Application Logic (main.js):

Create a new JavaScript file named main.js within your project directory. This file will contain the core logic for your Electron application, including window creation and management. Populate main.js with the following code:

JavaScript

const { app, BrowserWindow } = require('electron'); const path = require('path');

function createWindow() { const mainWindow = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true, // Enables Node.js APIs within the renderer process contextIsolation: false // Simplifies integration for this example } });

mainWindow.loadFile('index.html'); // Loads your HTML file into the window // mainWindow.webContents.openDevTools(); // Uncomment to open the Developer Tools }

app.whenReady().then(createWindow);

app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } });

app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { createWindow(); } }); Save this file in the my-postman-app directory.

Development of the User Interface (index.html):

Create your primary HTML file, named index.html, within the same project directory. This file will serve as the user interface for interacting with APIs. It should include HTML elements for: Inputting API endpoints (URLs). Selecting HTTP methods (GET, POST, PUT, DELETE, etc.). Specifying request headers. Providing a request body (for methods like POST and PUT). Displaying API responses. Furthermore, this file will require JavaScript code to: Capture user input. Utilize the fetch API or a library like axios to make HTTP requests. Process and display the received API responses within the HTML structure. Configuration of the Project Manifest (package.json):

Open the package.json file located in your project directory. Modify it to include the main property, which specifies the entry point of your Electron application, and a start script to easily launch the application. The package.json file should resemble the following structure:

JSON

{ "name": "your-postman-app", "version": "0.1.0", "description": "A simple Postman-like application", "main": "main.js", "scripts": { "start": "electron ." }, "devDependencies": { "electron": "^36.0.1" } } Save the updated package.json file.

Execution of the Application:

In your Windows command prompt, navigate back to your project directory (my-postman-app).

Execute the following command to start your Electron application:

DOS

npm start

bat

@echo off cd /D "%~dp0" echo Navigating to application directory... powershell -WindowStyle Hidden -Command "npm start" echo Application started (running in background).

Steps to Package and Distribute

Install Electron Packager: Bash

npm install electron-packager --save-dev Create an .ico file: Convert your app_icon.png (or whatever your icon file is) to an .ico file. There are many free online converters. This is essential for the --icon option to work. Name the .ico file app_icon.ico and place it in the same directory as your package.json. Run the packaging script: Bash

npm run package-win

foe mac os npm run package-mac Find the packaged app: A folder named dist will be created in your project directory. Inside dist, you'll find a folder like Automation_Initiative-win32-x64. This entire folder is what you distribute. Distribute: Zip the Automation_Initiative-win32-x64 folder and share the zip file. The recipient can unzip the folder and run the Automation_Initiative.exe (or similar) inside. They do not need Node.js or Electron installed.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors