Skip to content

Commit

Permalink
Add electron example
Browse files Browse the repository at this point in the history
  • Loading branch information
alchemicas committed Mar 30, 2024
1 parent 67f8c3d commit b8b062c
Show file tree
Hide file tree
Showing 24 changed files with 6,414 additions and 13 deletions.
95 changes: 95 additions & 0 deletions examples/electron/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock
.DS_Store

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# Webpack
.webpack/

# Vite
.vite/

# Electron-Forge
out/

# DiskStorage
storage.json
1 change: 1 addition & 0 deletions examples/electron/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node-linker=hoisted
33 changes: 33 additions & 0 deletions examples/electron/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# @aracna/fcm - Electron Example

Please define the following variables inside a .env file.

| Name | Source | Type |
| --------------------------- | ---------------- | ------ |
| VITE_FIREBASE_API_KEY | Firebase Console | string |
| VITE_FIREBASE_APP_ID | Firebase Console | string |
| VITE_FIREBASE_PROJECT_ID | Firebase Console | string |
| VITE_GOOGLE_SERVICE_ACCOUNT | Firebase Console | string |
| VITE_VAPID_KEY | Firebase Console | string |

The `VITE_GOOGLE_SERVICE_ACCOUNT` variable must be base64 encoded.

## Install Dependencies

```
pnpm i
```

## Run

```
pnpm start
```

## Send Test Message

This command will send a test message to the client that is listening when you run `pnpm start`, you should see it appear in its logs once sent.

```
pnpm send-message
```
47 changes: 47 additions & 0 deletions examples/electron/forge.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { MakerDeb } from '@electron-forge/maker-deb'
import { MakerRpm } from '@electron-forge/maker-rpm'
import { MakerSquirrel } from '@electron-forge/maker-squirrel'
import { MakerZIP } from '@electron-forge/maker-zip'
import { FusesPlugin } from '@electron-forge/plugin-fuses'
import { VitePlugin } from '@electron-forge/plugin-vite'
import type { ForgeConfig } from '@electron-forge/shared-types'
import { FuseV1Options, FuseVersion } from '@electron/fuses'

const config: ForgeConfig = {
packagerConfig: {
asar: true
},
rebuildConfig: {},
makers: [new MakerSquirrel({}), new MakerZIP({}, ['darwin']), new MakerRpm({}), new MakerDeb({})],
plugins: [
new VitePlugin({
build: [
{
entry: 'src/main.ts',
config: 'vite.main.config.ts'
},
{
entry: 'src/preload.ts',
config: 'vite.preload.config.ts'
}
],
renderer: [
{
name: 'main_window',
config: 'vite.renderer.config.ts'
}
]
}),
new FusesPlugin({
version: FuseVersion.V1,
[FuseV1Options.RunAsNode]: false,
[FuseV1Options.EnableCookieEncryption]: true,
[FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
[FuseV1Options.EnableNodeCliInspectArguments]: false,
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
[FuseV1Options.OnlyLoadAppFromAsar]: true
})
]
}

export default config
27 changes: 27 additions & 0 deletions examples/electron/forge.env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export {}

declare global {
const MAIN_WINDOW_VITE_DEV_SERVER_URL: string
const MAIN_WINDOW_VITE_NAME: string

namespace NodeJS {
interface Process {
viteDevServers: Record<string, import('vite').ViteDevServer>
}
}

type VitePluginConfig = ConstructorParameters<typeof import('@electron-forge/plugin-vite').VitePlugin>[0]

interface VitePluginRuntimeKeys {
VITE_DEV_SERVER_URL: `${string}_VITE_DEV_SERVER_URL`
VITE_NAME: `${string}_VITE_NAME`
}
}

declare module 'vite' {
interface ConfigEnv<K extends keyof VitePluginConfig = keyof VitePluginConfig> {
root: string
forgeConfig: VitePluginConfig
forgeConfigSelf: VitePluginConfig[K][number]
}
}
12 changes: 12 additions & 0 deletions examples/electron/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>@aracna/fcm - Electron Example</title>
</head>
<body>
<h1>Messages</h1>
<ul id="messages"></ul>
<script type="module" src="/src/renderer.ts"></script>
</body>
</html>
41 changes: 41 additions & 0 deletions examples/electron/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"author": "Dario Sechi",
"dependencies": {
"@aracna/core": "^1.1.81",
"@aracna/fcm": "^1.0.22",
"electron-squirrel-startup": "^1.0.0"
},
"description": "My Electron application description",
"devDependencies": {
"@electron-forge/cli": "^7.3.1",
"@electron-forge/maker-deb": "^7.3.1",
"@electron-forge/maker-rpm": "^7.3.1",
"@electron-forge/maker-squirrel": "^7.3.1",
"@electron-forge/maker-zip": "^7.3.1",
"@electron-forge/plugin-auto-unpack-natives": "^7.3.1",
"@electron-forge/plugin-fuses": "^7.2.0",
"@electron-forge/plugin-vite": "^7.3.1",
"@electron/fuses": "^1.7.0",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"electron": "29.1.6",
"eslint": "^8.0.1",
"eslint-plugin-import": "^2.25.0",
"ts-node": "^10.0.0",
"typescript": "~4.5.4",
"vite": "^5.0.12",
"vite-node": "^1.4.0"
},
"license": "MIT",
"name": "electron",
"main": ".vite/build/main.js",
"productName": "electron",
"scripts": {
"make": "electron-forge make",
"package": "electron-forge package",
"publish": "electron-forge publish",
"send-message": "vite-node scripts/send-message.ts",
"start": "electron-forge start"
},
"version": "1.0.0"
}
Loading

0 comments on commit b8b062c

Please sign in to comment.