fix: 修改模板

This commit is contained in:
NICE CODE BY DEV 2024-04-09 17:34:58 +08:00
parent 4cf5a6d2f6
commit ae3c4abac2
17 changed files with 2819 additions and 182 deletions

3
.prettierignore Normal file
View File

@ -0,0 +1,3 @@
node_modules
.umi
.umi-production

8
.prettierrc Normal file
View File

@ -0,0 +1,8 @@
{
"printWidth": 80,
"singleQuote": true,
"trailingComma": "all",
"proseWrap": "never",
"overrides": [{ "files": ".prettierrc", "options": { "parser": "json" } }],
"plugins": ["prettier-plugin-organize-imports", "prettier-plugin-packagejson"]
}

View File

@ -1,5 +1,5 @@
import { defineConfig } from 'umi';
import { Platform, createTargets } from '@umijs/plugin-electron';
import { defineConfig } from "umi";
import { Platform, createTargets } from "@umijs/plugin-electron";
// example: mac & windows
const targets = createTargets([Platform.WINDOWS]);
@ -8,14 +8,23 @@ const targets = createTargets([Platform.WINDOWS]);
// const targets = Platform.MAC.createTarget(['dmg'], Arch.arm64);
export default defineConfig({
npmClient: 'yarn',
plugins: ['@umijs/plugin-electron'],
npmClient: "pnpm",
plugins: ["@umijs/plugin-electron", "@umijs/plugins/dist/dva"],
// metas: [
// {
// 'http-equiv': 'Content-Security-Policy',
// content: "default-src 'none'"
// }
// ],
electron: {
builder: {
targets
targets,
config: {}
},
extraDevFiles: {
// 'xxxx.js' : fs.readFileSync('xxxx.js','utf-8'),
}
extraDevFiles: {}
},
define: {
APP_ENV: "dev"
},
dva: {},
});

2
jest-setup.ts Normal file
View File

@ -0,0 +1,2 @@
import '@testing-library/jest-dom';
import 'umi/test-setup'

27
jest.config.ts Normal file
View File

@ -0,0 +1,27 @@
import { Config, configUmiAlias, createConfig } from 'umi/test';
export default async () => {
try{
return (await configUmiAlias({
...createConfig({
target: 'browser',
jsTransformer: 'esbuild',
// config opts for esbuild , it will pass to esbuild directly
jsTransformerOpts: { jsx: 'automatic' },
}),
setupFilesAfterEnv: ['<rootDir>/jest-setup.ts'],
collectCoverageFrom: [
'src/**/*.{ts,js,tsx,jsx}',
'!src/.umi/**',
'!src/.umi-test/**',
'!src/.umi-production/**'
],
// if you require some es-module npm package, please uncomment below line and insert your package name
// transformIgnorePatterns: ['node_modules/(?!.*(lodash-es|your-es-pkg-name)/)']
})) as Config.InitialOptions;
} catch (e) {
console.log(e);
throw e;
}
};

View File

@ -6,11 +6,16 @@
},
"description": "eggKnife-electron的客户端模板",
"scripts": {
"dev": "umi dev",
"build": "umi build",
"postinstall": "umi setup",
"setup": "umi setup",
"start": "npm run dev"
"dev": "cross-env umi dev",
"build": "cross-env NODE_ENV=production umi build",
"postinstall": "cross-env umi setup",
"setup": "cross-env umi setup",
"start": "cross-env npm run dev",
"test": "cross-env TS_NODE_TRANSPILE_ONLY=yes jest --passWithNoTests"
},
"build": {
"productName": "测试",
"appId": "nicecode"
},
"dependencies": {
"antd": "^5.16.1",
@ -25,7 +30,19 @@
"@types/react-dom": "^18.0.0",
"@umijs/plugin-electron": "^0.2.0",
"electron": "29.1.6",
"typescript": "^4.1.2"
"typescript": "^5",
"prettier": "^2.8.8",
"prettier-plugin-organize-imports": "^3.2.2",
"prettier-plugin-packagejson": "^2.4.3",
"jest": "^29",
"@types/jest": "^29",
"ts-node": "^10",
"cross-env": "^7",
"jest-environment-jsdom": "^29",
"@testing-library/jest-dom": "^5",
"@testing-library/react": "^14",
"@types/testing-library__jest-dom": "^5.14.5",
"@umijs/plugins": "^4.1.8"
},
"publishConfig": {
"access": "public",

File diff suppressed because it is too large Load Diff

12
src/index.html Normal file
View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>形体结构化视频数据分析系统</title>
</head>
<body>
<div id="app"></div>
<webview id="" src="http://10.0.0.96:30003/" />
</body>
</html>

View File

@ -2,11 +2,15 @@ import { BrowserWindowConstructorOptions } from 'electron';
export default {
browserWindow: {
titleBarStyle: process.platform === 'win32' ? 'hidden' : 'hiddenInset',
title: 'nicecode 客户端模板',
titleBarOverlay: {
color: '#2f3241',
symbolColor: '#74b1be',
height: 48
},
maximizable: false,
webPreferences: {
contextIsolation: false,
enableRemoteModule: true
enableRemoteModule: true,
}
} as BrowserWindowConstructorOptions
};

1
src/main/forks/init.ts Normal file
View File

@ -0,0 +1 @@
console.log('123', 123)

View File

@ -1 +1,114 @@
getBrowserWindowRuntime().webContents.openDevTools();
import { app, Menu } from 'electron';
if (process.env.NODE_ENV === 'development') {
getBrowserWindowRuntime().webContents.openDevTools();
}
const isMac = process.platform === 'darwin'
const template = [
// { role: 'appMenu' }
...(isMac
? [{
label: app.name,
submenu: [
{ label: '关于', role: 'about' },
{ type: 'separator' },
{ role: 'services' },
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideOthers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' }
]
}]
: []),
// { role: 'fileMenu' }
{
label: '文件',
submenu: [
isMac ? { label: '退出', role: 'close' } : { label: '退出', role: 'quit' }
]
},
// { role: 'editMenu' }
{
label: '编辑',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
...(isMac
? [
{ role: 'pasteAndMatchStyle' },
{ role: 'delete' },
{ role: 'selectAll' },
{ type: 'separator' },
{
label: 'Speech',
submenu: [
{ role: 'startSpeaking' },
{ role: 'stopSpeaking' }
]
}
]
: [
{ role: 'delete' },
{ type: 'separator' },
{ role: 'selectAll' }
])
]
},
// { role: 'viewMenu' }
{
label: '视图',
submenu: [
{ label: '重新加载', role: 'reload' },
{ label: '强制重新加载', role: 'forceReload' },
{ type: 'separator' },
{ role: 'resetZoom' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
]
},
// { role: 'windowMenu' }
{
label: '窗口',
submenu: [
{ role: 'minimize' },
{ role: 'zoom' },
...(isMac
? [
{ type: 'separator' },
{ role: 'front' },
{ type: 'separator' },
{ role: 'window' }
]
: [
{ role: 'close' }
])
]
},
{
role: 'help',
submenu: [
{ label: '控制台', role: 'toggleDevTools' },
{
label: '更多',
click: async () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { shell } = require('electron')
await shell.openExternal('https://electronjs.org')
}
}
]
}
]
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)

View File

@ -1,4 +1,4 @@
import { ipcMain } from 'electron';
import { ipcMain, app } from 'electron';
ipcMain.handle('getPlatform', () => {
return `hi, i'm from ${process.platform}`;

View File

@ -1,19 +1,19 @@
import { app, ipcMain } from 'electron';
import fs from 'fs';
import path from 'node:path';
// import fs from 'fs';
// import path from 'node:path';
ipcMain.on('uploadFile', (event, filePaths: string[]) => {
// 获取用户当前文件夹路径
// console.log('app', app.getPath('userData'))
console.log('app', app.getGPUInfo('basic'))
// const saveDirectoryPath = await app.getPath('downloads');
for (let i = 0; i < filePaths.length; i++) {
const fileName = path.basename(filePaths[i]);
const targetFilePath = path.join(__dirname, fileName);
const fileStream = fs.createWriteStream(targetFilePath);
fileStream.write(fs.readFileSync(filePaths[i]));
fileStream.end();
console.log('Uploaded file saved at:', targetFilePath);
}
// for (let i = 0; i < filePaths.length; i++) {
// const fileName = path.basename(filePaths[i]);
// const targetFilePath = path.join(__dirname, fileName);
// const fileStream = fs.createWriteStream(targetFilePath);
// fileStream.write(fs.readFileSync(filePaths[i]));
// fileStream.end();
// console.log('Uploaded file saved at:', targetFilePath);
// }
// const fileSize = fs.statSync(filePath).size;
// let uploadedSize = 0;

View File

@ -2,4 +2,5 @@ import { BrowserWindow } from 'electron';
declare global {
export function getBrowserWindowRuntime(): BrowserWindow;
const APP_ENV: string
}

21
src/models/count.ts Normal file
View File

@ -0,0 +1,21 @@
const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));
export default {
namespace: 'count',
state: {
num: 0,
},
reducers: {
add(state: any) {
state.num += 1;
},
},
effects: {
*addAsync(_action: any, { put }: any) {
yield delay(1000);
yield put({ type: 'add' });
},
},
};

View File

@ -1,3 +1,4 @@
import { Button } from 'antd';
import avatar from '../assets/avatar.jpg';
export default function HomePage() {
@ -10,13 +11,13 @@ export default function HomePage() {
<p>
To get started, edit <code>pages/index.tsx</code> and save to reload.
</p>
<button
<Button
onClick={async () => {
window.alert(await window.$api.getPlatform());
}}
>
what is my platform?
</button>
</Button>
</div>
);
}

0
src/utils/index.ts Normal file
View File