Skip to content

Commit

Permalink
Merge branch 'main' into feature/window-menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ylebre authored Jun 12, 2024
2 parents 3c4f8ef + 4e78fc9 commit aa3b8d2
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 30 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# name: Release app
# on:
# workflow_dispatch:
# jobs:
# build:
# strategy:
# matrix:
# os:
# [
# { name: 'linux', image: 'ubuntu-latest' },
# { name: 'windows', image: 'windows-latest' },
# { name: 'macos', image: 'macos-latest' },
# ]
# runs-on: ${{ matrix.os.image }}
# steps:
# - name: Github checkout
# uses: actions/checkout@v4
# - name: Use Node.js
# uses: actions/setup-node@v4
# with:
# node-version: 20
# - run: npm ci
# - name: Publish app
# env:
# GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
# run: npm run publish
129 changes: 122 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,130 @@
# Electron build for Simplycode

To build:
[![SimplyEdit][simplyedit-shield]][simplyedit-site]
[![Project stage: Development][project-stage-badge: Development]][project-stage-page]
[![License][license-shield]][license-link]
[![standard-readme compliant][standard-readme-shield]][standard-readme-link]

Electron environment to create **SimplyCode** applications in.

## Install

Currently, there is no pre-compiled binary available, so the project needs to be built from source.

To do so, clone the repository, install the dependencies, and run the build script:

```sh
git clone https://github.com/SimplyEdit/simplycode-electron.git
npm --prefix simplycode-electron install
npm --prefix simplycode-electron run make
```

The build will create an `out` directory with distributable files (in the `make` directory) and an executable Electron application (in a `simply-code-app-*` directory). For instance, on Linux: `simply-code-app-linux-x64`.

Depending on the platform a package is built for, different dependencies are required. For instance for Debian-based distributions require `dpkg` and `fakeroot`. For Red Hat-based distributions `rpm` is required.

Please refer to [the Electron Forge makers documentation](https://www.electronforge.io/config/makers) for specific requirements.

to run the build in a Docker container, the following command can be used:

```sh
docker run \
--interactive \
--network=host \
--rm \
--tty \
--volume "${PWD}:/app" \
--workdir=/app \
node:lts \
bash -c 'apt update && apt install -y dpkg fakeroot rpm && npm install && npm run make'
```

## Usage

The compiled electron application can be started by opening it from a graphical file manager or by running the executable from the command line. For instance, on Linux:

```sh
./out/simply-code-app-linux-x64/simply-code-app
```
npm install
npm run make

## Contribute

Feedback and contributions are welcome. Please open an issue or create a pull request.

### Development

To develop in Electron, please defer to the [Electron documentation](https://www.electronjs.org/docs/latest/).

To run, packaged and build the app [Electron Forge](https://www.electronforge.io/) is used.

For ease of use, NPM script commands have been added to wrap the most common Electron Forge commands.

For instance to start the application in development mode, instead of running `electron-forge start`, use:

```sh
npm run start
```

Debugging in vscode:
#### Debugging in Visual Studio Code (VS Code)

To debug the application using VS Code, VS Code needs to attach to the main and the renderer processes. This is done by creating a `launch.json` configuration in the `.vscode` folder in the project.

<details><summary markdown="span">Contents of <code>launch.json</code></summary>

Debugging with vscode is possible as documented on [electron documentation](https://www.electronjs.org/docs/latest/tutorial/tutorial-first-app#optional-debugging-from-vs-code)
```json
{
"version": "0.2.0",
"compounds": [
{
"name": "Main + renderer",
"configurations": ["Main", "Renderer"],
"stopAll": true
}
],
"configurations": [
{
"name": "Renderer",
"port": 9222,
"request": "attach",
"type": "chrome",
"webRoot": "${workspaceFolder}"
},
{
"name": "Main",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
},
"args": [".", "--remote-debugging-port=9222"],
"outputCapture": "std",
"console": "integratedTerminal"
}
]
}
```
The "Main + renderer" option will appear when you select "Run and Debug" from the sidebar, allowing you to set breakpoints and inspect all the variables among other things in both the main and renderer processes.
```

For more details about the `launch.js`, visit [the "Debugging from VS Code" section](https://www.electronjs.org/docs/latest/tutorial/tutorial-first-app#optional-debugging-from-vs-code) in the [Building your First App](https://www.electronjs.org/docs/latest/tutorial/tutorial-first-app) tutorial.

</details>

Next, in VS Code, select the "Run and Debug" option from the sidebar.

A "Main + renderer" option will appear. Amongst other things, it is now possible to set breakpoints and inspect variables.

For more information on debugging in VS Code, visit the ["Debugging in VSCode" tutorial](https://www.electronjs.org/docs/latest/tutorial/debugging-vscode).

## License

Created by [SimplyEdit](https://simplyedit.io) under an MIT License.

[license-link]: ./LICENSE
[license-shield]: https://img.shields.io/github/license/simplyedit/simplycode-electron.svg
[simplyedit-shield]: https://img.shields.io/badge/Simply-Edit-F26522?labelColor=939598
[simplyedit-site]: https://simplyedit.io/
[project-stage-badge: Development]: https://img.shields.io/badge/Project%20Stage-Development-yellowgreen.svg
[project-stage-page]: https://blog.pother.ca/project-stages/
[standard-readme-link]: https://github.com/RichardLitt/standard-readme
[standard-readme-shield]: https://img.shields.io/badge/-Standard%20Readme-brightgreen.svg
41 changes: 34 additions & 7 deletions forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,44 @@ const { FuseV1Options, FuseVersion } = require('@electron/fuses');
module.exports = {
packagerConfig: {
asar: true,
icon: '/simplycode/camil_512x512.png',
},
rebuildConfig: {},
makers: [
{
name: '@electron-forge/maker-squirrel',
config: {},
config: {
bin: 'simply-code',
icon:path.join(__dirname, '/simplycode/camil_192x192.png'),
}
},
{
name: '@electron-forge/maker-zip',
platforms: ['darwin'],
name: '@electron-forge/maker-dmg',
config: {
bin: 'simply-code',
icon:path.join(__dirname, '/simplycode/camil_192x192.png'),
},
},
{
name: '@electron-forge/maker-deb',
config: {},
config: {
bin: 'simply-code',
options: {
icon:path.join(__dirname, '/simplycode/camil_192x192.png'),
},
}
},
{
name: '@electron-forge/maker-rpm',
config: {},
},
config: {
bin: 'simply-code',
icon:path.join(__dirname, '/simplycode/camil_192x192.png'),
}
}
],
plugins: [
{
name: '@electron-forge/plugin-auto-unpack-natives',
name: '@SimplyEdit/simplycode-electron/tree/electron-forge-github-actions',
config: {},
},
// Fuses are used to enable/disable various Electron functionality
Expand All @@ -41,4 +56,16 @@ module.exports = {
[FuseV1Options.OnlyLoadAppFromAsar]: true,
}),
],
publishers: [
{
name: 'simply-code',
config: {
repository: {
owner: 'Govert Combée',
name: 'simply-code'
},
prerelease: true
}
}
]
};
34 changes: 20 additions & 14 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const createWindow = () => {
preload: path.join(__dirname, 'preload.js'),
webSecurity: false,
allowRunningInsecureContent : true
}
},
icon: path.join(__dirname, '/simplycode/camil_512x512.png')

})

let defaultMenu = Menu.getApplicationMenu();
Expand Down Expand Up @@ -57,7 +59,8 @@ const createSecondWindow = (dataDir) => {
preload: path.join(__dirname, 'preload.js'),
webSecurity: false,
allowRunningInsecureContent : true
}
},
icon: path.join(__dirname,'/simplycode/camil_512x512.png')
})
let menuTemplate = [
{
Expand Down Expand Up @@ -173,6 +176,8 @@ async function createComponentFile(componentPath, filecontent){
}

app.whenReady().then(() => {
if (require('electron-squirrel-startup') === true) app.quit(); // prevents Squirrel.Windows from launching your app multiple times during the installation/updating/uninstallation.

protocol.handle('simplycode', (request) => {
let componentPath = new URL(request.url).pathname
console.log('[simplycode://]' + componentPath)
Expand Down Expand Up @@ -251,8 +256,6 @@ app.whenReady().then(() => {
break
}
}


})

protocol.handle('simplyapp', (request) => {
Expand All @@ -262,23 +265,28 @@ app.whenReady().then(() => {
componentPath = componentPath.substring(0, (componentPath.length - 1))
}

let pathicles = componentPath.split('\/');
let pathicles = componentPath.split('\/'); // also splits on an empty string

let componentName = pathicles.pop();
let componentDirectory = pathicles.join('/');
pathicles.shift();

if (pathicles[0] == ''){
pathicles.shift()
}

let componentDirectory = pathicles.join('/');

switch (request.method){
default:
if(componentPath.endsWith('\/')){
componentPath = componentPath.substring(0, (componentPath.length - 1))
}
}

if (!componentPath || componentPath === "/") {
const filestuff = fs.readFileSync(dataDir + '/generated.html')
return new Response(filestuff, {
// headers: { 'content-type': 'text/html' }
})

} else {
var target = dataDir + componentDirectory + '\/' + componentName;
if(fs.existsSync(target)) {
Expand All @@ -300,11 +308,8 @@ app.whenReady().then(() => {
}
}
break
}




}
}
})

if (!process.argv[0].match(/electron$/) && process.argv[1]) {
Expand All @@ -320,10 +325,11 @@ app.whenReady().then(() => {
console.log(dataDir);
if (!dataDir.match(/\/$/)) {
dataDir += "/";
console.log(dataDir);
}
createWindow()

app.on('activate', () => {
app.on('activate', () => { // needed for macos
if (BrowserWindow.getAllWindows().length === 0) {
if (!process.argv[0].match(/electron$/) && process.argv[1]) {
dataDir = path.resolve(process.argv[1]);
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make",
"postinstall": "scripts/post-install.sh"
"postinstall": "scripts/post-install.sh",
"publish": "electron-forge publish"
},
"productName": "simply-code",
"keywords": [
"javascript",
"html",
Expand All @@ -25,8 +27,9 @@
"@electron-forge/maker-zip": "^7.4.0",
"@electron-forge/plugin-auto-unpack-natives": "^7.4.0",
"@electron-forge/plugin-fuses": "^7.4.0",
"@electron-forge/publisher-github": "^7.4.0",
"@electron/fuses": "^1.8.0",
"electron": "^30.0.2"
"electron": "^30.0.9"
},
"dependencies": {
"electron-squirrel-startup": "^1.0.1",
Expand Down

0 comments on commit aa3b8d2

Please sign in to comment.