feat: electron

This commit is contained in:
cha0s 2022-04-02 12:29:10 -05:00
parent e40ba67c6d
commit 67723d1d35
4 changed files with 227 additions and 0 deletions

116
packages/electron/.gitignore vendored Normal file
View File

@ -0,0 +1,116 @@
# 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
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# 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
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

View File

@ -0,0 +1,24 @@
import {Hooks} from '@flecks/core';
export default {
[Hooks]: {
/**
* Invoked when electron is initializing.
* @param {Electron.App} app The electron app. See: https://www.electronjs.org/docs/latest/api/app
*/
'@flecks/electron.initialize': (app) => {
app.on('will-quit', () => {
// ...
});
},
/**
* Invoked when a window is created
* @param {Electron.BrowserWindow} win The electron browser window. See: https://www.electronjs.org/docs/latest/api/browser-window
*/
'@flecks/electron.window': (win) => {
win.maximize();
},
},
};

View File

@ -0,0 +1,25 @@
{
"name": "@flecks/electron",
"version": "1.4.1",
"scripts": {
"build": "flecks build",
"clean": "flecks clean",
"lint": "flecks lint",
"postversion": "cp package.json dist",
"test": "flecks test"
},
"files": [
"build",
"server.js",
"server.js.map",
"src",
"test"
],
"dependencies": {
"@flecks/core": "^1.4.1",
"electron": "^18.0.1"
},
"devDependencies": {
"@flecks/fleck": "^1.4.1"
}
}

View File

@ -0,0 +1,62 @@
import {Hooks} from '@flecks/core';
import {
app,
BrowserWindow,
} from 'electron';
let win;
async function createWindow(flecks) {
const {
browserWindowOptions,
} = flecks.get('@flecks/electron/server');
win = new BrowserWindow(browserWindowOptions);
await flecks.invokeSequentialAsync('@flecks/electron.window', win);
}
export default {
[Hooks]: {
'@flecks/core.config': () => ({
/**
* Browser window options.
*
* See: https://www.electronjs.org/docs/latest/api/browser-window
*/
browserWindowOptions: {},
/**
* The URL to load in electron by default.
*
* Defaults to `http://localhost:${flecks.get('@flecks/web/server.port')}`.
*/
url: undefined,
}),
'@flecks/electron.initialize': async (app, flecks) => {
// Apple has to be *special*.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', async () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
await app.whenReady();
await createWindow(flecks);
},
'@flecks/electron.window': async (win, flecks) => {
const {
url = `http://localhost:${flecks.get('@flecks/web/server.port')}`,
} = flecks.get('@flecks/electron/server');
await win.loadURL(url);
},
'@flecks/server.up': async (flecks) => {
// `app` will be undefined if we aren't running in an electron environment. Just bail.
if (!app) {
return;
}
await flecks.invokeSequentialAsync('@flecks/electron.initialize', app);
},
},
};