调整项目结构:前端和 Electron 核心

This commit is contained in:
2025-08-06 07:44:19 +08:00
parent 499f6205fa
commit cbe3f72d1c
19 changed files with 3836 additions and 1329 deletions

149
.gitignore vendored
View File

@ -1,19 +1,144 @@
# 依赖目录
node_modules/
core/build/
# 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/
core/*build*/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.*
!.env.example
.DS_Store
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist/
renderer/dist/
# 环境文件
.env
.DS_Store
# 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
# 日志
*.log
npm-debug.log*
# vuepress build output
.vuepress/dist
# IDE 配置
# vuepress v2.x temp and cache directory
.temp
.cache
# Sveltekit cache directory
.svelte-kit/
# vitepress build output
**/.vitepress/dist
# vitepress cache directory
**/.vitepress/cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# Firebase cache directory
.firebase/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
.vscode/
.idea/
.idea/
# yarn v3
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
# Vite logs files
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

View File

@ -1,3 +0,0 @@
//
// Created by Kisechan on 25-8-6.
//

View File

@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
let mainWindow
@ -10,16 +10,21 @@ function createWindow() {
transparent: true,
frame: false,
webPreferences: {
preload: path.join(__dirname, '../renderer/src/preload.js'),
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true
}
})
mainWindow.loadURL(
process.env.NODE_ENV === 'development'
? 'http://localhost:5173'
: `file://${path.join(__dirname, '../renderer/dist/index.html')}`
)
// 开发模式加载Vite服务器
if (process.env.NODE_ENV === 'development') {
mainWindow.loadURL('http://localhost:5173')
} else {
mainWindow.loadFile(path.join(__dirname, '../renderer/dist/index.html'))
}
mainWindow.setIgnoreMouseEvents(true, {
forward: true
})
}
app.whenReady().then(createWindow)

6
main/preload.js Normal file
View File

@ -0,0 +1,6 @@
const { contextBridge, ipcRenderer } = require('electron')
contextBridge.exposeInMainWorld('electronAPI', {
playSound: (file) => ipcRenderer.send('play-sound', file),
showTooltip: (text) => ipcRenderer.send('show-tooltip', text)
})

2542
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,78 +1,30 @@
{
"name": "@deskpet/pet",
"name": "pet",
"version": "1.0.0",
"main": "main/main.js",
"description": "",
"main": "index.js",
"scripts": {
"start": "electron .",
"build:addon": "cd core && node-gyp rebuild"
"dev": "concurrently \"cd renderer && npm run dev\" \"wait-on http://localhost:5173 && electron .\""
},
"repository": {
"type": "git",
"url": "git+https://github.com/Kisechan/Pet.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"author": "Kisechan",
"license": "MIT",
"bugs": {
"url": "https://github.com/Kisechan/Pet/issues"
},
"homepage": "https://github.com/Kisechan/Pet#readme",
"devDependencies": {
"@vitejs/plugin-vue": "^6.0.1",
"electron": "^37.2.5",
"node-addon-api": "^8.5.0",
"node-gyp": "^11.3.0"
"vue": "^3.5.18"
},
"dependencies": {
"boolean": "^3.2.0",
"buffer-crc32": "^0.2.13",
"cacheable-lookup": "^5.0.4",
"cacheable-request": "^7.0.4",
"clone-response": "^1.0.3",
"debug": "^4.4.1",
"decompress-response": "^6.0.0",
"defer-to-connect": "^2.0.1",
"define-data-property": "^1.1.4",
"define-properties": "^1.2.1",
"detect-node": "^2.1.0",
"end-of-stream": "^1.4.5",
"env-paths": "^2.2.1",
"es-define-property": "^1.0.1",
"es-errors": "^1.3.0",
"es6-error": "^4.1.1",
"escape-string-regexp": "^4.0.0",
"extract-zip": "^2.0.1",
"fd-slicer": "^1.1.0",
"fs-extra": "^8.1.0",
"get-stream": "^5.2.0",
"global-agent": "^3.0.0",
"globalthis": "^1.0.4",
"gopd": "^1.2.0",
"got": "^11.8.6",
"graceful-fs": "^4.2.11",
"has-property-descriptors": "^1.0.2",
"http-cache-semantics": "^4.2.0",
"http2-wrapper": "^1.0.3",
"json-buffer": "^3.0.1",
"json-stringify-safe": "^5.0.1",
"jsonfile": "^4.0.0",
"keyv": "^4.5.4",
"lowercase-keys": "^2.0.0",
"matcher": "^3.0.0",
"mimic-response": "^1.0.1",
"ms": "^2.1.3",
"normalize-url": "^6.1.0",
"object-keys": "^1.1.1",
"once": "^1.4.0",
"p-cancelable": "^2.1.1",
"pend": "^1.2.0",
"progress": "^2.0.3",
"pump": "^3.0.3",
"quick-lru": "^5.1.1",
"resolve-alpn": "^1.2.1",
"responselike": "^2.0.1",
"roarr": "^2.15.4",
"semver": "^6.3.1",
"semver-compare": "^1.0.0",
"serialize-error": "^7.0.1",
"sprintf-js": "^1.1.3",
"sumchecker": "^3.0.1",
"type-fest": "^0.13.1",
"undici-types": "^6.21.0",
"universalify": "^0.1.2",
"wrappy": "^1.0.2",
"yauzl": "^2.10.0"
},
"description": ""
"fs-extra": "^11.3.1",
"howler": "^2.2.4",
"path": "^0.12.7"
}
}

5
renderer/README.md Normal file
View File

@ -0,0 +1,5 @@
# Vue 3 + TypeScript + Vite
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
Learn more about the recommended Project Setup and IDE Support in the [Vue Docs TypeScript Guide](https://vuejs.org/guide/typescript/overview.html#project-setup).

View File

@ -4,10 +4,10 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue</title>
<title>Vite + Vue + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

2163
renderer/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"build": "vue-tsc -b && vite build",
"preview": "vite preview"
},
"dependencies": {
@ -13,6 +13,11 @@
},
"devDependencies": {
"@vitejs/plugin-vue": "^6.0.0",
"vite": "^7.0.4"
"@vue/tsconfig": "^0.7.0",
"concurrently": "^9.2.0",
"typescript": "~5.8.3",
"vite": "^7.0.4",
"vue-tsc": "^2.2.12",
"wait-on": "^8.0.4"
}
}

View File

@ -1,30 +1,77 @@
<script setup>
import HelloWorld from './components/HelloWorld.vue'
import { ref, onMounted } from 'vue'
import petVideo from './assets/pet.mp4'
const tooltips = [
"说的道理",
]
const sounds = [
]
const showTooltip = ref(false)
const currentTooltip = ref('')
const handleClick = () => {
// 随机播放音效
const sound = sounds[Math.floor(Math.random() * sounds.length)]
window.electronAPI.playSound(sound)
// 随机显示提示
showTooltip.value = true
currentTooltip.value = tooltips[Math.floor(Math.random() * tooltips.length)]
setTimeout(() => showTooltip.value = false, 2000)
}
</script>
<template>
<div>
<a href="https://vite.dev" target="_blank">
<img src="/vite.svg" class="logo" alt="Vite logo" />
</a>
<a href="https://vuejs.org/" target="_blank">
<img src="./assets/vue.svg" class="logo vue" alt="Vue logo" />
</a>
<div class="container">
<!-- MP4素材播放 -->
<video
autoplay loop muted
:src="petVideo"
@click="handleClick"
/>
<!-- 文字提示框 -->
<transition name="fade">
<div v-if="showTooltip" class="tooltip">
{{ currentTooltip }}
</div>
</transition>
</div>
<HelloWorld msg="Vite + Vue" />
</template>
<style scoped>
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
.container {
width: 100vw;
height: 100vh;
overflow: hidden;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
video {
width: 100%;
height: 100%;
object-fit: contain;
cursor: pointer;
}
.logo.vue:hover {
filter: drop-shadow(0 0 2em #42b883aa);
.tooltip {
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background: rgba(0, 0, 0, 0.7);
color: white;
padding: 8px 16px;
border-radius: 20px;
font-size: 14px;
}
</style>
.fade-enter-active, .fade-leave-active {
transition: opacity 0.5s;
}
.fade-enter, .fade-leave-to {
opacity: 0;
}
</style>

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>

Before

Width:  |  Height:  |  Size: 496 B

View File

@ -1,43 +0,0 @@
<script setup>
import { ref } from 'vue'
defineProps({
msg: String,
})
const count = ref(0)
</script>
<template>
<h1>{{ msg }}</h1>
<div class="card">
<button type="button" @click="count++">count is {{ count }}</button>
<p>
Edit
<code>components/HelloWorld.vue</code> to test HMR
</p>
</div>
<p>
Check out
<a href="https://vuejs.org/guide/quick-start.html#local" target="_blank"
>create-vue</a
>, the official Vue + Vite starter
</p>
<p>
Learn more about IDE Support for Vue in the
<a
href="https://vuejs.org/guide/scaling-up/tooling.html#ide-support"
target="_blank"
>Vue Docs Scaling up Guide</a
>.
</p>
<p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
</template>
<style scoped>
.read-the-docs {
color: #888;
}
</style>

1
renderer/src/vite-env.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference types="vite/client" />

View File

@ -0,0 +1,15 @@
{
"extends": "@vue/tsconfig/tsconfig.dom.json",
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"]
}

7
renderer/tsconfig.json Normal file
View File

@ -0,0 +1,7 @@
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}

View File

@ -0,0 +1,25 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2023",
"lib": ["ES2023"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["vite.config.ts"]
}