diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0106758 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +dist +package-lock.json \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6cf60af --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# Electron Blank Application + +This is the blank application for your electron project + +## Requirements + +To use Electron you must have installed node js. For windows it is available on its [official website](https://nodejs.org/en/), for linux you can download the `node` packet from your packet manager + +## Installation + +```sh +git clone https://github.com/krypt0nn/electron-blank-app ./my-app +cd my-app +npm i +``` + +`git clone` will download a blank bundle for your project and save it in the `./my-app` directory *(`my-app` folder in the current opened in the console directory)* + +`cd my-app` will move you to this downloaded bundle + +`npm i` will install requirements + +## Set up + +In the `package.json` you should change these parameters: + +* name - your project name +* version +* description +* keywords - your project keywords +* author + +## Development + +All your development processes will be inside the `src` directory. The default page is `src/html/index.html` + +To run your application - use `npm start` command + +To build it for any systems - `npm run build:all` + +* For Windows only: `npm run build:win` +* For Linux only: `npm run build:linux` +* For MacOS only: `npm run build:darwin` + +All the binaries will appear in the `dist` directory in a folder with name `[app name]-[platform]-[arch]`, for example `electron-blank-app-linux-x64` + +To pack linux binary to the flatpak binary you can run `npm run pack:flatpak`. This operation requires pre-installed `flatpak` and `flatpak-build` packages + +
+ +Author: [Nikita Podvirnyy](https://vk.com/technomindlp) \ No newline at end of file diff --git a/entry.js b/entry.js new file mode 100644 index 0000000..fae089b --- /dev/null +++ b/entry.js @@ -0,0 +1,44 @@ +const { app, BrowserWindow } = require('electron') +const path = require('path') + +function createWindow () +{ + const mainWindow = new BrowserWindow ({ + width: 800, + height: 600, + webPreferences: { + // Is not safety + // Use it to have access to the node modules inside html files + nodeIntegration: true, + contextIsolation: false + } + }); + + mainWindow.loadFile(path.join(__dirname, 'src', 'html', 'index.html')); + + // mainWindow.webContents.openDevTools() +} + +// This method will be called when Electron has finished +// initialization and is ready to create browser windows. +// Some APIs can only be used after this event occurs. + +app.whenReady().then(() => { + createWindow(); + + app.on('activate', () => { + // On macOS it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + if (BrowserWindow.getAllWindows().length === 0) + createWindow(); + }); +}); + +// Quit when all windows are closed, except on macOS. There, it's common +// for applications and their menu bar to stay active until the user quits +// explicitly with Cmd + Q. + +app.on('window-all-closed', () => { + if (process.platform !== 'darwin') + app.quit(); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..4aeb034 --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "electron-blank-app", + "version": "1.0.0", + "description": "Electron Blank Application", + "keywords": [], + "author": "author", + "license": "GPL-3.0", + "main": "entry.js", + "scripts": { + "start": "electron .", + "build:all": "electron-packager . --out=dist --asar --overwrite --all --ignore=dist", + "build:darwin": "electron-packager . --out=dist --asar --overwrite --platform=darwin --arch=x64 --ignore=dist", + "build:linux": "electron-packager . --out=dist --asar --overwrite --platform=linux --arch=x64 --ignore=dist", + "build:win": "electron-packager . --out=dist --asar --overwrite --platform=win32 --arch=x64 --ignore=dist", + "pack:flatpak": "electron-installer-flatpak --src=dist/*-linux-x64 --dest=dist/installers --arch=x64" + }, + "devDependencies": { + "electron": "^14.0.0", + "electron-installer-flatpak": "^0.8.0", + "electron-packager": "^15.4.0" + } +} diff --git a/src/css/index.css b/src/css/index.css new file mode 100644 index 0000000..f2c534d --- /dev/null +++ b/src/css/index.css @@ -0,0 +1,4 @@ +.greeting +{ + text-align: center; +} \ No newline at end of file diff --git a/src/html/index.html b/src/html/index.html new file mode 100644 index 0000000..c4b922d --- /dev/null +++ b/src/html/index.html @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + Hello World + + + +

+ + diff --git a/src/js/index.js b/src/js/index.js new file mode 100644 index 0000000..0f6bb28 --- /dev/null +++ b/src/js/index.js @@ -0,0 +1,5 @@ +// When page is fully loaded +window.addEventListener('DOMContentLoaded', () => { + // Change the text inside tags with greeting class + document.querySelector('.greeting').innerText = 'Hello World'; +}, false); \ No newline at end of file