electron integration
This commit is contained in:
BIN
.vite/build/favicon.ico
Normal file
BIN
.vite/build/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
5
.vite/build/main.js
Normal file
5
.vite/build/main.js
Normal file
File diff suppressed because one or more lines are too long
1
.vite/build/preload.js
Normal file
1
.vite/build/preload.js
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";
|
||||
31
README.md
31
README.md
@@ -1,29 +1,16 @@
|
||||
# zeroone
|
||||
|
||||
This template should help get you started developing with Vue 3 in Vite.
|
||||
Haptic configuration utility
|
||||
|
||||
## Recommended IDE Setup
|
||||
## Running the code
|
||||
|
||||
[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).
|
||||
- use VSCode
|
||||
- run `sudo npm -g json-server`
|
||||
- run `npm install`
|
||||
- in another terminal, run `json-server --watch src/data/nanoConfig.json --port 3001`
|
||||
- run `npm start`
|
||||
|
||||
## Customize configuration
|
||||
## Connecting your Nano
|
||||
|
||||
See [Vite Configuration Reference](https://vitejs.dev/config/).
|
||||
TODO
|
||||
|
||||
## Project Setup
|
||||
|
||||
```sh
|
||||
npm install
|
||||
```
|
||||
|
||||
### Compile and Hot-Reload for Development
|
||||
|
||||
```sh
|
||||
npm run dev
|
||||
```
|
||||
|
||||
### Compile and Minify for Production
|
||||
|
||||
```sh
|
||||
npm run build
|
||||
```
|
||||
|
||||
48
forge.config.js
Normal file
48
forge.config.js
Normal file
@@ -0,0 +1,48 @@
|
||||
module.exports = {
|
||||
packagerConfig: {},
|
||||
rebuildConfig: {},
|
||||
makers: [
|
||||
{
|
||||
name: '@electron-forge/maker-squirrel',
|
||||
config: {},
|
||||
},
|
||||
{
|
||||
name: '@electron-forge/maker-zip',
|
||||
platforms: ['darwin'],
|
||||
},
|
||||
{
|
||||
name: '@electron-forge/maker-deb',
|
||||
config: {},
|
||||
},
|
||||
{
|
||||
name: '@electron-forge/maker-rpm',
|
||||
config: {},
|
||||
},
|
||||
],
|
||||
plugins: [
|
||||
{
|
||||
name: '@electron-forge/plugin-vite',
|
||||
config: {
|
||||
// `build` can specify multiple entry builds, which can be Main process, Preload scripts, Worker process, etc.
|
||||
// If you are familiar with Vite configuration, it will look really familiar.
|
||||
build: [
|
||||
{
|
||||
// `entry` is just an alias for `build.lib.entry` in the corresponding file of `config`.
|
||||
entry: 'src/main.js',
|
||||
config: 'vite.main.config.mjs',
|
||||
},
|
||||
{
|
||||
entry: 'src/preload.js',
|
||||
config: 'vite.preload.config.mjs',
|
||||
},
|
||||
],
|
||||
renderer: [
|
||||
{
|
||||
name: 'main_window',
|
||||
config: 'vite.renderer.config.mjs',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -8,6 +8,6 @@
|
||||
</head>
|
||||
<body class="dark bg-background">
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
<script type="module" src="/src/renderer.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
20435
package-lock.json
generated
20435
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
41
package.json
41
package.json
@@ -1,18 +1,18 @@
|
||||
{
|
||||
"name": "zeroone",
|
||||
"version": "0.1.1",
|
||||
"description": "Haptic configuration tool",
|
||||
"private": true,
|
||||
"main": ".vite/build/main.js",
|
||||
"XXtype": "module",
|
||||
"XXmain": "background.js",
|
||||
"scripts": {
|
||||
"build": "vite build",
|
||||
"dev": "vite",
|
||||
"electron:build": "vue-cli-service electron:build",
|
||||
"electron:serve": "vue-cli-service electron:serve",
|
||||
"postinstall": "electron-builder install-app-deps",
|
||||
"postuninstall": "electron-builder install-app-deps",
|
||||
"preview": "vite preview",
|
||||
"serve": "concurrently \"json-server src/data/nanoConfig.json --port=3001\" \"vite\" "
|
||||
"start": "electron-forge start",
|
||||
"package": "electron-forge package",
|
||||
"make": "electron-forge make",
|
||||
"publish": "electron-forge publish",
|
||||
"lint": "echo \"No linting configured\""
|
||||
},
|
||||
"main": "background.js",
|
||||
"dependencies": {
|
||||
"@radix-icons/vue": "^1.0.0",
|
||||
"@radix-ui/react-icons": "^1.3.0",
|
||||
@@ -25,31 +25,37 @@
|
||||
"clsx": "^2.1.0",
|
||||
"color": "^4.2.3",
|
||||
"concurrently": "^8.2.2",
|
||||
"electron-squirrel-startup": "^1.0.0",
|
||||
"lucide-vue-next": "^0.309.0",
|
||||
"radix-vue": "^1.3.0",
|
||||
"tailwind-merge": "^2.2.0",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
"vee-validate": "^4.12.4",
|
||||
"vue": "^3.3.11",
|
||||
"vue": "^3.4.15",
|
||||
"vue-i18n": "^9.9.0",
|
||||
"zod": "^3.22.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@electron-forge/cli": "^7.2.0",
|
||||
"@electron-forge/maker-deb": "^7.2.0",
|
||||
"@electron-forge/maker-rpm": "^7.2.0",
|
||||
"@electron-forge/maker-squirrel": "^7.2.0",
|
||||
"@electron-forge/maker-zip": "^7.2.0",
|
||||
"@electron-forge/plugin-auto-unpack-natives": "^7.2.0",
|
||||
"@electron-forge/plugin-vite": "^7.2.0",
|
||||
"@intlify/eslint-plugin-vue-i18n": "^2.0.0",
|
||||
"@types/node": "^20.11.0",
|
||||
"@vitejs/plugin-vue": "^4.5.2",
|
||||
"autoprefixer": "^10.4.16",
|
||||
"electron": "^13.0.0",
|
||||
"electron-devtools-installer": "^3.1.0",
|
||||
"@vitejs/plugin-vue": "^5.0.3",
|
||||
"autoprefixer": "^10.4.17",
|
||||
"electron": "28.2.0",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-vue": "^9.20.1",
|
||||
"json-server": "^1.0.0-alpha.21",
|
||||
"postcss": "^8.4.33",
|
||||
"postcss-loader": "^8.0.0",
|
||||
"prettier": "3.2.4",
|
||||
"tailwindcss": "^3.4.1",
|
||||
"vite": "^5.0.10",
|
||||
"vue-cli-plugin-electron-builder": "~2.1.1"
|
||||
"tailwindcss": "^3.4.1"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"root": true,
|
||||
@@ -105,6 +111,5 @@
|
||||
"semi": false,
|
||||
"singleQuote": true
|
||||
},
|
||||
"type": "module",
|
||||
"web-types": "./web-types.json"
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export default {
|
||||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
|
||||
88
src/main.js
88
src/main.js
@@ -1,48 +1,54 @@
|
||||
import './assets/main.css'
|
||||
import Axios from 'axios'
|
||||
import { app, BrowserWindow } from 'electron';
|
||||
import path from 'path';
|
||||
import 'electron-squirrel-startup';
|
||||
|
||||
import { createApp } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
// TODO Handle creating/removing shortcuts on Windows when installing/uninstalling.
|
||||
//if (require('electron-squirrel-startup')) {
|
||||
// app.quit();
|
||||
//}
|
||||
|
||||
import en from '@/lang/en.json'
|
||||
const createWindow = () => {
|
||||
// Create the browser window.
|
||||
const mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'preload.js'),
|
||||
},
|
||||
});
|
||||
|
||||
import App from '@/App.vue'
|
||||
|
||||
import { store } from '@/store.js'
|
||||
|
||||
import Ajv from 'ajv'
|
||||
import schema from '@/data/profileSchema.json'
|
||||
|
||||
const ajv = new Ajv()
|
||||
|
||||
Axios.get('http://localhost:3001/profiles').then((res) => {
|
||||
const profiles = res.data
|
||||
console.log(profiles)
|
||||
const ids = new Set()
|
||||
const validate = ajv.compile(schema)
|
||||
store.device.profiles = profiles.filter((profile) => {
|
||||
if (!validate(profile)) {
|
||||
console.error('Failed to validate profile: ' + profile.name, validate.errors)
|
||||
return false
|
||||
// and load the index.html of the app.
|
||||
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
|
||||
mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL);
|
||||
} else {
|
||||
mainWindow.loadFile(path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`));
|
||||
}
|
||||
if (ids.has(profile.id)) {
|
||||
console.error('Duplicate profile id: ' + profile.id + ' for profile: ' + profile.name)
|
||||
return false
|
||||
|
||||
// Open the DevTools.
|
||||
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.on('ready', 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();
|
||||
}
|
||||
ids.add(profile.id)
|
||||
return true
|
||||
})
|
||||
}).catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
});
|
||||
|
||||
// Create VueI18n instance with locales loaded from /lang directory
|
||||
const i18n = createI18n({
|
||||
locale: 'en',
|
||||
fallbackLocale: 'en',
|
||||
messages: { en: en },
|
||||
})
|
||||
app.on('activate', () => {
|
||||
// On OS X 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();
|
||||
}
|
||||
});
|
||||
|
||||
const app = createApp(App)
|
||||
app.use(i18n)
|
||||
app.mount('#app')
|
||||
// In this file you can include the rest of your app's specific main process
|
||||
// code. You can also put them in separate files and import them here.
|
||||
|
||||
2
src/preload.js
Normal file
2
src/preload.js
Normal file
@@ -0,0 +1,2 @@
|
||||
// See the Electron documentation for details on how to use preload scripts:
|
||||
// https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts
|
||||
74
src/renderer.js
Normal file
74
src/renderer.js
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* This file will automatically be loaded by vite and run in the "renderer" context.
|
||||
* To learn more about the differences between the "main" and the "renderer" context in
|
||||
* Electron, visit:
|
||||
*
|
||||
* https://electronjs.org/docs/tutorial/application-architecture#main-and-renderer-processes
|
||||
*
|
||||
* By default, Node.js integration in this file is disabled. When enabling Node.js integration
|
||||
* in a renderer process, please be aware of potential security implications. You can read
|
||||
* more about security risks here:
|
||||
*
|
||||
* https://electronjs.org/docs/tutorial/security
|
||||
*
|
||||
* To enable Node.js integration in this file, open up `main.js` and enable the `nodeIntegration`
|
||||
* flag:
|
||||
*
|
||||
* ```
|
||||
* // Create the browser window.
|
||||
* mainWindow = new BrowserWindow({
|
||||
* width: 800,
|
||||
* height: 600,
|
||||
* webPreferences: {
|
||||
* nodeIntegration: true
|
||||
* }
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
|
||||
|
||||
import { createApp } from 'vue';
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import App from './App.vue'
|
||||
import en from '@/lang/en.json'
|
||||
|
||||
import './assets/index.css'
|
||||
|
||||
import { store } from '@/store.js'
|
||||
import Ajv from 'ajv'
|
||||
import schema from '@/data/profileSchema.json'
|
||||
import Axios from 'axios'
|
||||
|
||||
const ajv = new Ajv()
|
||||
|
||||
Axios.get('http://localhost:3001/profiles').then((res) => {
|
||||
const profiles = res.data
|
||||
console.log(profiles)
|
||||
const ids = new Set()
|
||||
const validate = ajv.compile(schema)
|
||||
store.device.profiles = profiles.filter((profile) => {
|
||||
if (!validate(profile)) {
|
||||
console.error('Failed to validate profile: ' + profile.name, validate.errors)
|
||||
return false
|
||||
}
|
||||
if (ids.has(profile.id)) {
|
||||
console.error('Duplicate profile id: ' + profile.id + ' for profile: ' + profile.name)
|
||||
return false
|
||||
}
|
||||
ids.add(profile.id)
|
||||
return true
|
||||
})
|
||||
}).catch((err) => {
|
||||
console.error(err)
|
||||
})
|
||||
|
||||
// Create VueI18n instance with locales loaded from /lang directory
|
||||
const i18n = createI18n({
|
||||
locale: 'en',
|
||||
fallbackLocale: 'en',
|
||||
messages: { en: en },
|
||||
});
|
||||
|
||||
const app = createApp(App);
|
||||
app.use(i18n)
|
||||
app.mount('#app');
|
||||
11
vite.main.config.mjs
Normal file
11
vite.main.config.mjs
Normal file
@@ -0,0 +1,11 @@
|
||||
import { defineConfig } from 'vite';
|
||||
|
||||
// https://vitejs.dev/config
|
||||
export default defineConfig({
|
||||
resolve: {
|
||||
// Some libs that can run in both Web and Node.js, such as `axios`, we need to tell Vite to build them in Node.js.
|
||||
browserField: false,
|
||||
conditions: ['node'],
|
||||
mainFields: ['module', 'jsnext:main', 'jsnext'],
|
||||
},
|
||||
});
|
||||
4
vite.preload.config.mjs
Normal file
4
vite.preload.config.mjs
Normal file
@@ -0,0 +1,4 @@
|
||||
import { defineConfig } from 'vite';
|
||||
|
||||
// https://vitejs.dev/config
|
||||
export default defineConfig({});
|
||||
@@ -1,16 +1,12 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
vue(),
|
||||
],
|
||||
plugins: [vue()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
Reference in New Issue
Block a user