Skip to content

Instantly share code, notes, and snippets.

View thatisuday's full-sized avatar
🤖

Uday Hiwarale thatisuday

🤖
View GitHub Profile
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
</head>
<body style="background-color: #eee;">
<div id='app'></div>
</body>
</html>
import path from 'path';
import fs from 'fs';
// get application version from `static/version.txt`
export const getVersion = () => {
const versionFilePath = path.resolve( __static, 'version.txt' );
return fs.readFileSync( versionFilePath, {
encoding: 'utf-8',
} );
};
@thatisuday
thatisuday / index.js
Created January 5, 2021 07:49
electron-webpack entrypoint for the main process
import { app, BrowserWindow } from 'electron';
import path from 'path';
// local dependencies
import { getVersion } from 'common/util';
// get environment type
const isDevelopment = process.env.NODE_ENV !== 'production';
// open a window
@thatisuday
thatisuday / electron-webpack.json
Last active January 5, 2021 05:15
A sample electron-webpack configuration file.
{
"title": "My React App",
"main": {
"sourceDirectory": "app/main"
},
"renderer": {
"sourceDirectory": "app/renderer",
"template": "app/renderer/index.html"
},
"commonSourceDirectory": "app/common",
@thatisuday
thatisuday / dom.js
Created December 29, 2020 21:54
Handles DOM related operations of an Electron application.
const { ipcRenderer } = require( 'electron' );
// copy file
window.copyFile = function ( event, itemId ) {
event.preventDefault();
// get path of the file
const itemNode = document.getElementById( itemId );
const filepath = itemNode.getAttribute( 'data-filepath' );
@thatisuday
thatisuday / renderer.js
Created December 29, 2020 21:41
The renderer process entrypoint for an Electron application.
const dragDrop = require( 'drag-drop' );
const { ipcRenderer } = require( 'electron' );
// local dependencies
const dom = require( './dom' );
/*****************************/
// get list of files from the `main` process
ipcRenderer.invoke( 'app:get-files' ).then( ( files = [] ) => {
@thatisuday
thatisuday / index.html
Created December 29, 2020 21:31
An Electron application HTML file.
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
<title>Files Manager</title>
<!-- import fonts -->
<link rel="preconnect" href="https://fonts.gstatic.com">
@thatisuday
thatisuday / notification.js
Created December 29, 2020 20:44
A sample JavaScript file to display notifications in an Electron app.
const { Notification } = require( 'electron' );
// display files added notification
exports.filesAdded = ( size ) => {
const notif = new Notification( {
title: 'Files added',
body: `${ size } file(s) has been successfully added.`
} );
notif.show();
@thatisuday
thatisuday / io.js
Last active October 18, 2022 23:39
A sample JavaScript program to manage application files.
const { ipcMain } = require( 'electron' );
const path = require( 'path' );
const fs = require( 'fs-extra' );
const os = require( 'os' );
const open = require( 'open' );
const chokidar = require( 'chokidar' );
// local dependencies
const notification = require( './notification' );
@thatisuday
thatisuday / index.js
Last active December 29, 2020 20:27
A sample Electron entry point script.
const { app, BrowserWindow, ipcMain, dialog } = require( 'electron' );
const path = require( 'path' );
// local dependencies
const io = require( './main/io' );
``
// open a window
const openWindow = () => {
const win = new BrowserWindow( {
width: 800,