init
This commit is contained in:
		
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					node_modules
 | 
				
			||||||
 | 
					dist
 | 
				
			||||||
 | 
					app-dist
 | 
				
			||||||
							
								
								
									
										14
									
								
								index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								index.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					<!DOCTYPE html>
 | 
				
			||||||
 | 
					<html lang="en">
 | 
				
			||||||
 | 
					<head>
 | 
				
			||||||
 | 
					    <meta charset="UTF-8" />
 | 
				
			||||||
 | 
					    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 | 
				
			||||||
 | 
					    <title>Package Manager</title>
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					    <div id="app">
 | 
				
			||||||
 | 
					        <h1>Package Manager</h1>
 | 
				
			||||||
 | 
					        <div id="package-list" class="package-list"></div>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
							
								
								
									
										32
									
								
								package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								package.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "name": "silky-assistant",
 | 
				
			||||||
 | 
					  "version": "0.0.1",
 | 
				
			||||||
 | 
					  "description": "",
 | 
				
			||||||
 | 
					  "main": "dist/main/main.js",
 | 
				
			||||||
 | 
					  "scripts": {
 | 
				
			||||||
 | 
					    "dev": "vite --config vite.config.ts",
 | 
				
			||||||
 | 
					    "build": "vite build --config vite.config.ts",
 | 
				
			||||||
 | 
					    "build:watch": "vite build --config vite.config.ts -w",
 | 
				
			||||||
 | 
					    "build:electron": "vite build --config vite.config.ts",
 | 
				
			||||||
 | 
					    "start": "electron ."
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "keywords": [],
 | 
				
			||||||
 | 
					  "author": "abearxiong <xiongxiao@xiongxiao.me>",
 | 
				
			||||||
 | 
					  "license": "MIT",
 | 
				
			||||||
 | 
					  "type": "module",
 | 
				
			||||||
 | 
					  "devDependencies": {
 | 
				
			||||||
 | 
					    "@types/electron": "^1.6.12",
 | 
				
			||||||
 | 
					    "@types/node": "^22.13.9",
 | 
				
			||||||
 | 
					    "electron-log": "^5.3.2",
 | 
				
			||||||
 | 
					    "electron-updater": "^6.3.9",
 | 
				
			||||||
 | 
					    "typescript": "^5.8.2",
 | 
				
			||||||
 | 
					    "vite": "^6.2.1",
 | 
				
			||||||
 | 
					    "vite-plugin-electron": "^0.29.0",
 | 
				
			||||||
 | 
					    "vite-plugin-static-copy": "^2.3.0"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "dependencies": {
 | 
				
			||||||
 | 
					    "@kevisual/assistant-module": "^0.0.3",
 | 
				
			||||||
 | 
					    "@kevisual/router": "^0.0.9",
 | 
				
			||||||
 | 
					    "electron": "^35.0.0"
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										1657
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										1657
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										1
									
								
								router-app/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								router-app/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					node_modules
 | 
				
			||||||
							
								
								
									
										15
									
								
								router-app/pem/https-cert.pem
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								router-app/pem/https-cert.pem
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					-----BEGIN CERTIFICATE-----
 | 
				
			||||||
 | 
					MIICXTCCAcagAwIBAgIJHsP036vqWER/MA0GCSqGSIb3DQEBBQUAMF8xCjAIBgNV
 | 
				
			||||||
 | 
					BAMTASoxCzAJBgNVBAYTAkNOMREwDwYDVQQIEwhaaGVKaWFuZzERMA8GA1UEBxMI
 | 
				
			||||||
 | 
					SGFuZ3pob3UxETAPBgNVBAoTCEVudmlzaW9uMQswCQYDVQQLEwJJVDAeFw0yNTAz
 | 
				
			||||||
 | 
					MDcxNDIwMTJaFw0yNjAzMDcxNDIwMTJaMF8xCjAIBgNVBAMTASoxCzAJBgNVBAYT
 | 
				
			||||||
 | 
					AkNOMREwDwYDVQQIEwhaaGVKaWFuZzERMA8GA1UEBxMISGFuZ3pob3UxETAPBgNV
 | 
				
			||||||
 | 
					BAoTCEVudmlzaW9uMQswCQYDVQQLEwJJVDCBnzANBgkqhkiG9w0BAQEFAAOBjQAw
 | 
				
			||||||
 | 
					gYkCgYEAquA2XnwduVSJHvnTW4r5yodz/joTPUi+r8kS/KJyR/NQ5xovtDY2gJoO
 | 
				
			||||||
 | 
					nJk8qekcLKuofskIIu4HFsCE7AYBkQGaYmc+0cCQCmEpwivesbeMB0ydz+6NwLQn
 | 
				
			||||||
 | 
					32HVjtMtx3gUcywGdMntiQb/P9FIhtE132wOmW9PeSl0dx/nyrUCAwEAAaMhMB8w
 | 
				
			||||||
 | 
					HQYDVR0RBBYwFIIBKoIJbG9jYWxob3N0hwR/AAABMA0GCSqGSIb3DQEBBQUAA4GB
 | 
				
			||||||
 | 
					AJsjIZgb6iE4OTXoEDiBPmHM+byWs20K2eCvi79V9/vns90IroBQfGirIsovv923
 | 
				
			||||||
 | 
					SqjmdAFsZkRUbZvX99lBX0mmZK9KTE4K9YUm7bv+d8+fBPxAgNFSTRiSNBeNh0Lh
 | 
				
			||||||
 | 
					HdJUiI/tzIfI6RRg1pFDC1tOG083Cl/YElN879w3Iipi
 | 
				
			||||||
 | 
					-----END CERTIFICATE-----
 | 
				
			||||||
							
								
								
									
										15
									
								
								router-app/pem/https-key.pem
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								router-app/pem/https-key.pem
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					-----BEGIN RSA PRIVATE KEY-----
 | 
				
			||||||
 | 
					MIICXAIBAAKBgQCq4DZefB25VIke+dNbivnKh3P+OhM9SL6vyRL8onJH81DnGi+0
 | 
				
			||||||
 | 
					NjaAmg6cmTyp6Rwsq6h+yQgi7gcWwITsBgGRAZpiZz7RwJAKYSnCK96xt4wHTJ3P
 | 
				
			||||||
 | 
					7o3AtCffYdWO0y3HeBRzLAZ0ye2JBv8/0UiG0TXfbA6Zb095KXR3H+fKtQIDAQAB
 | 
				
			||||||
 | 
					AoGADDEbL/qjFEoXzoH8tpdf4zdu60CxhrneASTTmfrtNH0D1LlllfIYSWy0hi/Y
 | 
				
			||||||
 | 
					yDa9r+I/j2xAjF13XAQ4d66mBdjCRATLx/aL495o+e6NkIBEAgdP88hHm13F6gg+
 | 
				
			||||||
 | 
					h8iMixs5mkwU41sghnCYeBqlziKPi8fsoTmhK0VETFUtDQECQQDT0kZ7OCEVNcz0
 | 
				
			||||||
 | 
					LAUPO7ukeHAYnGYns+Q3F3kgonzHPGflClH5dsg0NS1HFQj6Ny2oyUupjNePOCJK
 | 
				
			||||||
 | 
					88zNehIlAkEAzoO9zrE+AoTPleVpe7TAUlZB1YMa7W1C5owjyEkv4TjIe8mpwWM/
 | 
				
			||||||
 | 
					9vVe+SGUnc6DZy6xkk5zWmA2w18SexXJUQJBAJQbcyy1EmzCMYyJOwBrw8g8biTH
 | 
				
			||||||
 | 
					NqaMIgZjY05uTtEAa6S6kpbbdyEKDZ6mFqDd9A8QsNbco9yAY3oE/i6uLAECQHOt
 | 
				
			||||||
 | 
					a9aphZiXmEfYl3uJxejZFEtrAtxXxY+qlCiOhllcG0Drt0DyPVQyIZ7fZoX2tbhI
 | 
				
			||||||
 | 
					eYMAmrDXEBXj3VBA5eECQCLGpQKqo06QwP2qZ9mEaPB9KvVcABo97b9Lf7VUqcJx
 | 
				
			||||||
 | 
					tFWRSlpeICpDQZHqX92nwoD/2fGCH3br3o94k1oyApI=
 | 
				
			||||||
 | 
					-----END RSA PRIVATE KEY-----
 | 
				
			||||||
							
								
								
									
										21
									
								
								router-app/src/app.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								router-app/src/app.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					import { App } from '@kevisual/router';
 | 
				
			||||||
 | 
					import { httpsConfig } from './modules/config';
 | 
				
			||||||
 | 
					export const app = new App({
 | 
				
			||||||
 | 
					  serverOptions: {
 | 
				
			||||||
 | 
					    httpType: 'https',
 | 
				
			||||||
 | 
					    httpsCert: httpsConfig.cert.toString(),
 | 
				
			||||||
 | 
					    httpsKey: httpsConfig.key.toString(),
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					app
 | 
				
			||||||
 | 
					  .route({
 | 
				
			||||||
 | 
					    path: 'demo',
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					  .define(async (ctx) => {
 | 
				
			||||||
 | 
					    ctx.body = 'hello world';
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					  .addTo(app);
 | 
				
			||||||
 | 
					console.log('httpsConfig', `https://localhost:51015/api/router?path=demo`);
 | 
				
			||||||
 | 
					app.listen(51015, () => {
 | 
				
			||||||
 | 
					  console.log('Router App is running on https://localhost:51015');
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
							
								
								
									
										9
									
								
								router-app/src/modules/config.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								router-app/src/modules/config.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					import fs from 'fs';
 | 
				
			||||||
 | 
					import path from 'path';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const pemDir = path.join(process.cwd(), 'router-app', 'pem');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const httpsConfig = {
 | 
				
			||||||
 | 
					  key: fs.readFileSync(path.join(pemDir, 'https-key.pem')),
 | 
				
			||||||
 | 
					  cert: fs.readFileSync(path.join(pemDir, 'https-cert.pem')),
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										108
									
								
								router-app/src/modules/config/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										108
									
								
								router-app/src/modules/config/index.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,108 @@
 | 
				
			|||||||
 | 
					import path from 'path';
 | 
				
			||||||
 | 
					import { homedir } from 'os';
 | 
				
			||||||
 | 
					import fs from 'fs';
 | 
				
			||||||
 | 
					import { checkFileExists, createDir } from '../file';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const kevisualUrl = 'https://kevisual.xiongxiao.me';
 | 
				
			||||||
 | 
					const configDir = createDir(path.join(homedir(), '.config/envision'));
 | 
				
			||||||
 | 
					export const configPath = path.join(configDir, 'assistant-config.json');
 | 
				
			||||||
 | 
					export const appConfigPath = path.join(configDir, 'assistant-app-config.json');
 | 
				
			||||||
 | 
					export const appDir = createDir(path.join(configDir, 'assistant-app/frontend'));
 | 
				
			||||||
 | 
					export const LocalElectronAppUrl = 'https://assistant.app/user/tiptap/';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type AssistantConfig = {
 | 
				
			||||||
 | 
					  pageApi?: string; // https://kevisual.silkyai.cn
 | 
				
			||||||
 | 
					  loadURL?: string; // https://assistant.app/user/tiptap/
 | 
				
			||||||
 | 
					  proxy?: { user: string; key: string; path: string }[];
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					let assistantConfig: AssistantConfig;
 | 
				
			||||||
 | 
					export const getConfig = () => {
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    if (!checkFileExists(configPath)) {
 | 
				
			||||||
 | 
					      fs.writeFileSync(configPath, JSON.stringify({ proxy: [] }, null, 2));
 | 
				
			||||||
 | 
					      return {
 | 
				
			||||||
 | 
					        loadURL: LocalElectronAppUrl,
 | 
				
			||||||
 | 
					        pageApi: '',
 | 
				
			||||||
 | 
					        proxy: [],
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    assistantConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'));
 | 
				
			||||||
 | 
					    return assistantConfig;
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    console.error(error);
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					      loadURL: LocalElectronAppUrl,
 | 
				
			||||||
 | 
					      pageApi: '',
 | 
				
			||||||
 | 
					      proxy: [],
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					export const getCacheAssistantConfig = () => {
 | 
				
			||||||
 | 
					  if (assistantConfig) {
 | 
				
			||||||
 | 
					    return assistantConfig;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return getConfig();
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const setConfig = (config?: AssistantConfig) => {
 | 
				
			||||||
 | 
					  if (!config) {
 | 
				
			||||||
 | 
					    return assistantConfig;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  assistantConfig = config;
 | 
				
			||||||
 | 
					  fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
 | 
				
			||||||
 | 
					  return assistantConfig;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					type AppConfig = {
 | 
				
			||||||
 | 
					  list: any[];
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 应用配置
 | 
				
			||||||
 | 
					 * @returns
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export const getAppConfig = (): AppConfig => {
 | 
				
			||||||
 | 
					  if (!checkFileExists(appConfigPath)) {
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					      list: [],
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return JSON.parse(fs.readFileSync(appConfigPath, 'utf8'));
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const setAppConfig = (config: AppConfig) => {
 | 
				
			||||||
 | 
					  fs.writeFileSync(appConfigPath, JSON.stringify(config, null, 2));
 | 
				
			||||||
 | 
					  return config;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const addAppConfig = (app: any) => {
 | 
				
			||||||
 | 
					  const config = getAppConfig();
 | 
				
			||||||
 | 
					  const assistantConfig = getCacheAssistantConfig();
 | 
				
			||||||
 | 
					  const _apps = config.list;
 | 
				
			||||||
 | 
					  const _proxy = assistantConfig.proxy || [];
 | 
				
			||||||
 | 
					  const { user, key } = app;
 | 
				
			||||||
 | 
					  const newProxyInfo = {
 | 
				
			||||||
 | 
					    user,
 | 
				
			||||||
 | 
					    key,
 | 
				
			||||||
 | 
					    path: `/${user}/${key}`,
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					  const _proxyIndex = _proxy.findIndex((_proxy: any) => _proxy.path === newProxyInfo.path);
 | 
				
			||||||
 | 
					  if (_proxyIndex !== -1) {
 | 
				
			||||||
 | 
					    _proxy[_proxyIndex] = newProxyInfo;
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    _proxy.push(newProxyInfo);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const _app = _apps.findIndex((_app: any) => _app.id === app.id);
 | 
				
			||||||
 | 
					  if (_app !== -1) {
 | 
				
			||||||
 | 
					    _apps[_app] = app;
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    _apps.push(app);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  setAppConfig({ ...config, list: _apps });
 | 
				
			||||||
 | 
					  setConfig({ ...assistantConfig, proxy: _proxy });
 | 
				
			||||||
 | 
					  return config;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const getAppList = () => {
 | 
				
			||||||
 | 
					  const config = getAppConfig();
 | 
				
			||||||
 | 
					  return config.list || [];
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										20
									
								
								router-app/src/modules/file/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								router-app/src/modules/file/index.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
				
			|||||||
 | 
					import fs from 'fs';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const checkFileExists = (filePath: string, checkIsFile = false) => {
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    fs.accessSync(filePath);
 | 
				
			||||||
 | 
					    if (checkIsFile) {
 | 
				
			||||||
 | 
					      return fs.statSync(filePath).isFile();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return true;
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const createDir = (dirPath: string) => {
 | 
				
			||||||
 | 
					  if (!checkFileExists(dirPath)) {
 | 
				
			||||||
 | 
					    fs.mkdirSync(dirPath, { recursive: true });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return dirPath;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										5
									
								
								router-app/src/proxy/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								router-app/src/proxy/index.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					import http from 'http';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const handleRequest = async (req: http.IncomingMessage, res: http.ServerResponse) => {
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										18
									
								
								router-app/src/scripts/create-sign.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								router-app/src/scripts/create-sign.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					import { createCert } from '@kevisual/router/sign';
 | 
				
			||||||
 | 
					import { writeFileSync } from 'fs';
 | 
				
			||||||
 | 
					import path from 'path';
 | 
				
			||||||
 | 
					const pemDir = path.join(process.cwd(), 'router-app', 'pem');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const { key, cert } = createCert([
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    name: 'commonName',
 | 
				
			||||||
 | 
					    value: 'localhost',
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    name: 'organizationName',
 | 
				
			||||||
 | 
					    value: 'kevisual',
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					writeFileSync(path.join(pemDir, 'https-key.pem'), key);
 | 
				
			||||||
 | 
					writeFileSync(path.join(pemDir, 'https-cert.pem'), cert);
 | 
				
			||||||
							
								
								
									
										18
									
								
								router-app/static/download.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								router-app/static/download.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					import fs from 'fs';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const apps = [
 | 
				
			||||||
 | 
					  { user: 'root', key: 'enter', version: '1.0.0' }, //
 | 
				
			||||||
 | 
					  { user: 'root', key: 'packages', version: '1.0.0' },
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const baseURL = 'https://kevisual.silkyai.cn';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const downloadApps = () => {
 | 
				
			||||||
 | 
					  //
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const downloadLink = async (url: string, path: string) => {
 | 
				
			||||||
 | 
					  const res = await fetch(url);
 | 
				
			||||||
 | 
					  const blob = await res.blob();
 | 
				
			||||||
 | 
					  fs.writeFileSync(path, Buffer.from(await blob.arrayBuffer()));
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										23
									
								
								router-app/static/enter/electron.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								router-app/static/enter/electron.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					export const checkIsElectron = () => {
 | 
				
			||||||
 | 
					  return typeof window !== 'undefined' && typeof window.electron === 'object';
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					export const getElectron = () => {
 | 
				
			||||||
 | 
					  return window.electron;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					export const saveAppConfig = async (config) => {
 | 
				
			||||||
 | 
					  const check = checkIsElectron();
 | 
				
			||||||
 | 
					  if (!check) {
 | 
				
			||||||
 | 
					    console.log('not electron');
 | 
				
			||||||
 | 
					    return [];
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  const electron = getElectron();
 | 
				
			||||||
 | 
					  const saveResult = await electron.ipcRenderer.invoke('save-app-config', config);
 | 
				
			||||||
 | 
					  return saveResult;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					export const relunch = async () => {
 | 
				
			||||||
 | 
					  const check = checkIsElectron();
 | 
				
			||||||
 | 
					  if (!check) {
 | 
				
			||||||
 | 
					    console.log('not electron');
 | 
				
			||||||
 | 
					    return [];
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										214
									
								
								router-app/static/enter/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										214
									
								
								router-app/static/enter/index.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,214 @@
 | 
				
			|||||||
 | 
					<!DOCTYPE html>
 | 
				
			||||||
 | 
					<html lang="en">
 | 
				
			||||||
 | 
					<head>
 | 
				
			||||||
 | 
					    <meta charset="UTF-8">
 | 
				
			||||||
 | 
					    <meta name="viewport" content="width=device-width, initial-scale=1.0">
 | 
				
			||||||
 | 
					    <title>Page Enter Configuration</title>
 | 
				
			||||||
 | 
					    <style>
 | 
				
			||||||
 | 
					        * {
 | 
				
			||||||
 | 
					            margin: 0;
 | 
				
			||||||
 | 
					            padding: 0;
 | 
				
			||||||
 | 
					            box-sizing: border-box;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        body {
 | 
				
			||||||
 | 
					            min-height: 100vh;
 | 
				
			||||||
 | 
					            background: linear-gradient(135deg, #fef3c7 0%, #fffbeb 100%);
 | 
				
			||||||
 | 
					            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
 | 
				
			||||||
 | 
					            padding: 1.5rem;
 | 
				
			||||||
 | 
					            position: relative;
 | 
				
			||||||
 | 
					            overflow-x: hidden;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        .container {
 | 
				
			||||||
 | 
					            max-width: 42rem;
 | 
				
			||||||
 | 
					            margin: 0 auto;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        .header {
 | 
				
			||||||
 | 
					            display: flex;
 | 
				
			||||||
 | 
					            align-items: center;
 | 
				
			||||||
 | 
					            gap: 0.75rem;
 | 
				
			||||||
 | 
					            margin-bottom: 2rem;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        .header svg {
 | 
				
			||||||
 | 
					            width: 2rem;
 | 
				
			||||||
 | 
					            height: 2rem;
 | 
				
			||||||
 | 
					            color: #d97706;
 | 
				
			||||||
 | 
					            animation: spin 8s linear infinite;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        .header h1 {
 | 
				
			||||||
 | 
					            font-size: 1.875rem;
 | 
				
			||||||
 | 
					            font-weight: bold;
 | 
				
			||||||
 | 
					            color: #92400e;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        .form-container {
 | 
				
			||||||
 | 
					            background: rgba(255, 255, 255, 0.8);
 | 
				
			||||||
 | 
					            backdrop-filter: blur(8px);
 | 
				
			||||||
 | 
					            border-radius: 1rem;
 | 
				
			||||||
 | 
					            box-shadow: 0 4px 6px rgba(217, 119, 6, 0.1);
 | 
				
			||||||
 | 
					            padding: 2rem;
 | 
				
			||||||
 | 
					            transition: all 0.3s ease;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        .form-container:hover {
 | 
				
			||||||
 | 
					            box-shadow: 0 8px 12px rgba(217, 119, 6, 0.15);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        .form-group {
 | 
				
			||||||
 | 
					            margin-bottom: 1.5rem;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        label {
 | 
				
			||||||
 | 
					            display: block;
 | 
				
			||||||
 | 
					            font-size: 0.875rem;
 | 
				
			||||||
 | 
					            font-weight: 500;
 | 
				
			||||||
 | 
					            color: #92400e;
 | 
				
			||||||
 | 
					            margin-bottom: 0.25rem;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        input[type="text"] {
 | 
				
			||||||
 | 
					            width: 100%;
 | 
				
			||||||
 | 
					            padding: 0.75rem 1rem;
 | 
				
			||||||
 | 
					            border: 1px solid #fbbf24;
 | 
				
			||||||
 | 
					            border-radius: 0.5rem;
 | 
				
			||||||
 | 
					            font-size: 1rem;
 | 
				
			||||||
 | 
					            transition: all 0.2s;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        input[type="text"]:focus {
 | 
				
			||||||
 | 
					            outline: none;
 | 
				
			||||||
 | 
					            border-color: #d97706;
 | 
				
			||||||
 | 
					            box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.2);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        button {
 | 
				
			||||||
 | 
					            width: 100%;
 | 
				
			||||||
 | 
					            display: flex;
 | 
				
			||||||
 | 
					            align-items: center;
 | 
				
			||||||
 | 
					            justify-content: center;
 | 
				
			||||||
 | 
					            gap: 0.5rem;
 | 
				
			||||||
 | 
					            background-color: #d97706;
 | 
				
			||||||
 | 
					            color: white;
 | 
				
			||||||
 | 
					            padding: 0.75rem 1.5rem;
 | 
				
			||||||
 | 
					            border: none;
 | 
				
			||||||
 | 
					            border-radius: 0.5rem;
 | 
				
			||||||
 | 
					            font-size: 1rem;
 | 
				
			||||||
 | 
					            font-weight: 500;
 | 
				
			||||||
 | 
					            cursor: pointer;
 | 
				
			||||||
 | 
					            transition: background-color 0.2s;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        button:hover {
 | 
				
			||||||
 | 
					            background-color: #b45309;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        .particles {
 | 
				
			||||||
 | 
					            position: absolute;
 | 
				
			||||||
 | 
					            inset: 0;
 | 
				
			||||||
 | 
					            pointer-events: none;
 | 
				
			||||||
 | 
					            overflow: hidden;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        .particle {
 | 
				
			||||||
 | 
					            position: absolute;
 | 
				
			||||||
 | 
					            color: #fbbf24;
 | 
				
			||||||
 | 
					            opacity: 0.3;
 | 
				
			||||||
 | 
					            animation: float 5s ease-in-out infinite;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        @keyframes spin {
 | 
				
			||||||
 | 
					            from {
 | 
				
			||||||
 | 
					                transform: rotate(0deg);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            to {
 | 
				
			||||||
 | 
					                transform: rotate(360deg);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        @keyframes float {
 | 
				
			||||||
 | 
					            0%, 100% {
 | 
				
			||||||
 | 
					                transform: translateY(0) rotate(0deg);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            50% {
 | 
				
			||||||
 | 
					                transform: translateY(-20px) rotate(10deg);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    </style>
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					    <div class="particles" id="particles"></div>
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    <div class="container">
 | 
				
			||||||
 | 
					        <div class="header">
 | 
				
			||||||
 | 
					            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
 | 
				
			||||||
 | 
					                <path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/>
 | 
				
			||||||
 | 
					                <circle cx="12" cy="12" r="3"/>
 | 
				
			||||||
 | 
					            </svg>
 | 
				
			||||||
 | 
					            <h1>Page Enter Configuration</h1>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <div class="form-container">
 | 
				
			||||||
 | 
					            <form id="configForm">
 | 
				
			||||||
 | 
					                <div class="form-group">
 | 
				
			||||||
 | 
					                    <label for="pageApi">Page Enter Api</label>
 | 
				
			||||||
 | 
					                    <input type="text" id="pageApi" placeholder="Enter page api configuration">
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                <button type="submit" id="save-button">
 | 
				
			||||||
 | 
					                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
 | 
				
			||||||
 | 
					                        <path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/>
 | 
				
			||||||
 | 
					                        <polyline points="17 21 17 13 7 13 7 21"/>
 | 
				
			||||||
 | 
					                        <polyline points="7 3 7 8 15 8"/>
 | 
				
			||||||
 | 
					                    </svg>
 | 
				
			||||||
 | 
					                    Save Configuration
 | 
				
			||||||
 | 
					                </button>
 | 
				
			||||||
 | 
					            </form>
 | 
				
			||||||
 | 
					            <div id="save-result"></div>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <script>
 | 
				
			||||||
 | 
					        // Create floating particles
 | 
				
			||||||
 | 
					        function createParticles() {
 | 
				
			||||||
 | 
					            const particles = document.getElementById('particles');
 | 
				
			||||||
 | 
					            const particleCount = 20;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for (let i = 0; i < particleCount; i++) {
 | 
				
			||||||
 | 
					                const particle = document.createElement('div');
 | 
				
			||||||
 | 
					                particle.className = 'particle';
 | 
				
			||||||
 | 
					                particle.innerHTML = `
 | 
				
			||||||
 | 
					                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
 | 
				
			||||||
 | 
					                        <path d="m12 3-1.912 5.813a2 2 0 0 1-1.275 1.275L3 12l5.813 1.912a2 2 0 0 1 1.275 1.275L12 21l1.912-5.813a2 2 0 0 1 1.275-1.275L21 12l-5.813-1.912a2 2 0 0 1-1.275-1.275L12 3Z"/>
 | 
				
			||||||
 | 
					                        <path d="M5 3v4"/>
 | 
				
			||||||
 | 
					                        <path d="M19 17v4"/>
 | 
				
			||||||
 | 
					                        <path d="M3 5h4"/>
 | 
				
			||||||
 | 
					                        <path d="M17 19h4"/>
 | 
				
			||||||
 | 
					                    </svg>
 | 
				
			||||||
 | 
					                `;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                const size = 10 + Math.random() * 20;
 | 
				
			||||||
 | 
					                particle.style.width = `${size}px`;
 | 
				
			||||||
 | 
					                particle.style.height = `${size}px`;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                particle.style.left = `${Math.random() * 100}%`;
 | 
				
			||||||
 | 
					                particle.style.top = `${Math.random() * 100}%`;
 | 
				
			||||||
 | 
					                particle.style.animationDuration = `${5 + Math.random() * 5}s`;
 | 
				
			||||||
 | 
					                particle.style.animationDelay = `${Math.random() * 5}s`;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                particles.appendChild(particle);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Initialize particles
 | 
				
			||||||
 | 
					        createParticles();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Form handling
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					    </script>
 | 
				
			||||||
 | 
					    <script src="./main.js" type="module"></script>
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
							
								
								
									
										28
									
								
								router-app/static/enter/main.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								router-app/static/enter/main.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					import { saveAppConfig } from './electron.js';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					window.onload = async () => {
 | 
				
			||||||
 | 
					  const config = await saveAppConfig();
 | 
				
			||||||
 | 
					  const pageApi = document.getElementById('pageApi');
 | 
				
			||||||
 | 
					  const saveResult = document.getElementById('save-result');
 | 
				
			||||||
 | 
					  pageApi.value = config?.pageApi || 'https://kevisual.silkyai.cn';
 | 
				
			||||||
 | 
					  console.log('config', config);
 | 
				
			||||||
 | 
					  const form = document.getElementById('configForm');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Handle form submission
 | 
				
			||||||
 | 
					  form.addEventListener('submit', async (e) => {
 | 
				
			||||||
 | 
					    e.preventDefault();
 | 
				
			||||||
 | 
					    const config = {
 | 
				
			||||||
 | 
					      pageApi: pageApi.value,
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    const result = await saveAppConfig(config);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const newPageApi = result?.pageApi || '';
 | 
				
			||||||
 | 
					    saveResult.innerHTML = `<h1>保存成功</h1>
 | 
				
			||||||
 | 
					    <p>new pageApi: ${newPageApi}</p>
 | 
				
			||||||
 | 
					    <button id="relunch">重启</button>`;
 | 
				
			||||||
 | 
					    const relunchButton = document.getElementById('relunch');
 | 
				
			||||||
 | 
					    relunchButton.addEventListener('click', () => {
 | 
				
			||||||
 | 
					      window.electron.ipcRenderer.invoke('relunch');
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										21
									
								
								router-app/static/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								router-app/static/index.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					<!DOCTYPE html>
 | 
				
			||||||
 | 
					<html>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<head>
 | 
				
			||||||
 | 
					  <meta charset="UTF-8" />
 | 
				
			||||||
 | 
					  <title>Config Page</title>
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					  <h1>配置完成后重启</h1>
 | 
				
			||||||
 | 
					  <button id="restart">重启</button>
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script>
 | 
				
			||||||
 | 
					  const restart = document.getElementById('restart');
 | 
				
			||||||
 | 
					  restart.addEventListener('click', () => {
 | 
				
			||||||
 | 
					    window.electron.ipcRenderer.invoke('relunch');
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
							
								
								
									
										3
									
								
								router-app/static/packages/config.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								router-app/static/packages/config.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					export const config = {
 | 
				
			||||||
 | 
					  appListUrl: 'http://localhost:4005/api/router?path=app&key=public-list',
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										45
									
								
								router-app/static/packages/electron.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								router-app/static/packages/electron.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,45 @@
 | 
				
			|||||||
 | 
					export const checkIsElectron = () => {
 | 
				
			||||||
 | 
					  return typeof window !== 'undefined' && typeof window.electron === 'object';
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					export const getElectron = () => {
 | 
				
			||||||
 | 
					  return window.electron;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					export const getAppList = async () => {
 | 
				
			||||||
 | 
					  const check = checkIsElectron();
 | 
				
			||||||
 | 
					  if (!check) {
 | 
				
			||||||
 | 
					    console.log('not electron');
 | 
				
			||||||
 | 
					    return [];
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  const electron = getElectron();
 | 
				
			||||||
 | 
					  console.log('electron', electron);
 | 
				
			||||||
 | 
					  const appList = await electron.ipcRenderer.invoke('get-app-list');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  console.log('appList', appList);
 | 
				
			||||||
 | 
					  return appList;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const installApp = async (app) => {
 | 
				
			||||||
 | 
					  const check = checkIsElectron();
 | 
				
			||||||
 | 
					  if (!check) {
 | 
				
			||||||
 | 
					    console.log('not electron');
 | 
				
			||||||
 | 
					    return [];
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  const electron = getElectron();
 | 
				
			||||||
 | 
					  console.log('installApp', app);
 | 
				
			||||||
 | 
					  const result = await electron.ipcRenderer.invoke('install-app', app);
 | 
				
			||||||
 | 
					  console.log('installApp result', result);
 | 
				
			||||||
 | 
					  return result;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const uninstallApp = async (app) => {
 | 
				
			||||||
 | 
					  const check = checkIsElectron();
 | 
				
			||||||
 | 
					  if (!check) {
 | 
				
			||||||
 | 
					    console.log('not electron');
 | 
				
			||||||
 | 
					    return [];
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  const electron = getElectron();
 | 
				
			||||||
 | 
					  console.log('uninstallApp', app);
 | 
				
			||||||
 | 
					  const result = await electron.ipcRenderer.invoke('uninstall-app', app);
 | 
				
			||||||
 | 
					  console.log('uninstallApp result', result);
 | 
				
			||||||
 | 
					  return result;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										17
									
								
								router-app/static/packages/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								router-app/static/packages/index.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					<!DOCTYPE html>
 | 
				
			||||||
 | 
					<html lang="en">
 | 
				
			||||||
 | 
					<head>
 | 
				
			||||||
 | 
					    <meta charset="UTF-8" />
 | 
				
			||||||
 | 
					    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 | 
				
			||||||
 | 
					    <title>Package Manager</title>
 | 
				
			||||||
 | 
					    <link rel="stylesheet" href="./style.css">
 | 
				
			||||||
 | 
					    <script type="module" src="./electron.js"></script>
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					    <div id="app">
 | 
				
			||||||
 | 
					        <h1>Package Manager</h1>
 | 
				
			||||||
 | 
					        <div id="package-list" class="package-list"></div>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					    <script type="module" src="./main.js"></script>
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
							
								
								
									
										158
									
								
								router-app/static/packages/main.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										158
									
								
								router-app/static/packages/main.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,158 @@
 | 
				
			|||||||
 | 
					import { config } from './config.js';
 | 
				
			||||||
 | 
					import { getAppList, installApp, uninstallApp } from './electron.js';
 | 
				
			||||||
 | 
					let installedPackages = [];
 | 
				
			||||||
 | 
					let allPackages = [];
 | 
				
			||||||
 | 
					// Store for installed packages
 | 
				
			||||||
 | 
					// const installedPackages = [
 | 
				
			||||||
 | 
					//   { user: 'test', key: 'test-key', version: '1.0.0' },
 | 
				
			||||||
 | 
					//   { user: 'demo', key: 'demo-package', version: '1.2.0' },
 | 
				
			||||||
 | 
					// ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Function to fetch packages from API
 | 
				
			||||||
 | 
					async function fetchPackages() {
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    // Currently using mock data
 | 
				
			||||||
 | 
					    // TODO: Uncomment the following code when API is ready
 | 
				
			||||||
 | 
					    const response = await fetch(config.appListUrl);
 | 
				
			||||||
 | 
					    const result = await response.json();
 | 
				
			||||||
 | 
					    if (result.code === 200) {
 | 
				
			||||||
 | 
					      return result.data;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    throw new Error('Failed to fetch packages');
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    console.error('Error fetching packages:', error);
 | 
				
			||||||
 | 
					    return [];
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Mock data for testing
 | 
				
			||||||
 | 
					const mockPackages = [
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    id: '1',
 | 
				
			||||||
 | 
					    title: 'Demo Package 1',
 | 
				
			||||||
 | 
					    description: 'A test package for demonstration',
 | 
				
			||||||
 | 
					    version: '1.0.0',
 | 
				
			||||||
 | 
					    user: 'test',
 | 
				
			||||||
 | 
					    key: 'test-key',
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    id: '2',
 | 
				
			||||||
 | 
					    title: 'Demo Package 2',
 | 
				
			||||||
 | 
					    description: 'Another test package with updates',
 | 
				
			||||||
 | 
					    version: '2.0.0',
 | 
				
			||||||
 | 
					    user: 'demo',
 | 
				
			||||||
 | 
					    key: 'demo-package',
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    id: '3',
 | 
				
			||||||
 | 
					    title: 'New Package',
 | 
				
			||||||
 | 
					    description: "A package that hasn't been installed yet",
 | 
				
			||||||
 | 
					    version: '1.0.0',
 | 
				
			||||||
 | 
					    user: 'demo',
 | 
				
			||||||
 | 
					    key: 'new-package',
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Function to check if a package is installed
 | 
				
			||||||
 | 
					async function getPackageStatus(pkg) {
 | 
				
			||||||
 | 
					  const installed = installedPackages.find((p) => p.user === pkg.user && p.key === pkg.key);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (!installed) return 'not-installed';
 | 
				
			||||||
 | 
					  if (installed.version !== pkg.version) return 'update-available';
 | 
				
			||||||
 | 
					  return 'installed';
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Function to create a package card
 | 
				
			||||||
 | 
					async function createPackageCard(pkg) {
 | 
				
			||||||
 | 
					  const status = await getPackageStatus(pkg);
 | 
				
			||||||
 | 
					  const card = document.createElement('div');
 | 
				
			||||||
 | 
					  card.className = 'package-card';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  card.innerHTML = `
 | 
				
			||||||
 | 
					      <h2>${pkg.title}</h2>
 | 
				
			||||||
 | 
					      <p class="description">${pkg.description}</p>
 | 
				
			||||||
 | 
					      <div class="package-info">
 | 
				
			||||||
 | 
					          <span>Version: ${pkg.version}</span>
 | 
				
			||||||
 | 
					          <span>User: ${pkg.user}</span>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					      <div class="actions">
 | 
				
			||||||
 | 
					          ${getActionButton(status, pkg)}
 | 
				
			||||||
 | 
					          ${status !== 'not-installed' ? `<button class="button button-uninstall" onclick="handleUninstall('${pkg.id}')">Uninstall</button>` : ''}
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					  `;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return card;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Function to get the appropriate action button based on status
 | 
				
			||||||
 | 
					function getActionButton(status, pkg) {
 | 
				
			||||||
 | 
					  switch (status) {
 | 
				
			||||||
 | 
					    case 'not-installed':
 | 
				
			||||||
 | 
					      return `<button class="button button-install" onclick="handleInstall('${pkg.id}')">Install</button>`;
 | 
				
			||||||
 | 
					    case 'update-available':
 | 
				
			||||||
 | 
					      return `<button class="button button-update" onclick="handleUpdate('${pkg.id}')">Update</button>`;
 | 
				
			||||||
 | 
					    case 'installed':
 | 
				
			||||||
 | 
					      return `<button class="button button-reinstall" onclick="handleReinstall('${pkg.id}')">Reinstall</button>`;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Action handlers
 | 
				
			||||||
 | 
					window.handleInstall = async (id) => {
 | 
				
			||||||
 | 
					  console.log('Installing package:', id);
 | 
				
			||||||
 | 
					  const pkg = allPackages.find((p) => p.id === id);
 | 
				
			||||||
 | 
					  if (pkg) {
 | 
				
			||||||
 | 
					    await installApp(pkg);
 | 
				
			||||||
 | 
					    renderPackages();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					window.handleUpdate = async (id) => {
 | 
				
			||||||
 | 
					  console.log('Updating package:', id);
 | 
				
			||||||
 | 
					  const pkg = allPackages.find((p) => p.id === id);
 | 
				
			||||||
 | 
					  if (pkg) {
 | 
				
			||||||
 | 
					    await installApp(pkg);
 | 
				
			||||||
 | 
					    renderPackages();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					window.handleReinstall = async (id) => {
 | 
				
			||||||
 | 
					  console.log('Reinstalling package:', id);
 | 
				
			||||||
 | 
					  const pkg = allPackages.find((p) => p.id === id);
 | 
				
			||||||
 | 
					  if (pkg) {
 | 
				
			||||||
 | 
					    await installApp(pkg);
 | 
				
			||||||
 | 
					    renderPackages();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					window.handleUninstall = async (id) => {
 | 
				
			||||||
 | 
					  console.log('Uninstalling package:', id);
 | 
				
			||||||
 | 
					  // const pkg = mockPackages.find((p) => p.id === id);
 | 
				
			||||||
 | 
					  const pkg = allPackages.find((p) => p.id === id);
 | 
				
			||||||
 | 
					  if (pkg) {
 | 
				
			||||||
 | 
					    // TODO: Replace with actual API call
 | 
				
			||||||
 | 
					    const index = installedPackages.findIndex((p) => p.user === pkg.user && p.key === pkg.key);
 | 
				
			||||||
 | 
					    await uninstallApp(pkg);
 | 
				
			||||||
 | 
					    if (index !== -1) {
 | 
				
			||||||
 | 
					      installedPackages.splice(index, 1);
 | 
				
			||||||
 | 
					      renderPackages();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Render packages
 | 
				
			||||||
 | 
					async function renderPackages() {
 | 
				
			||||||
 | 
					  const packageList = document.getElementById('package-list');
 | 
				
			||||||
 | 
					  packageList.innerHTML = '';
 | 
				
			||||||
 | 
					  const installed = await getAppList();
 | 
				
			||||||
 | 
					  installedPackages = installed;
 | 
				
			||||||
 | 
					  for (const pkg of allPackages) {
 | 
				
			||||||
 | 
					    packageList.appendChild(await createPackageCard(pkg));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Initialize the application
 | 
				
			||||||
 | 
					document.addEventListener('DOMContentLoaded', async () => {
 | 
				
			||||||
 | 
					  const packages = await fetchPackages();
 | 
				
			||||||
 | 
					  allPackages = packages;
 | 
				
			||||||
 | 
					  renderPackages();
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
							
								
								
									
										115
									
								
								router-app/static/packages/style.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										115
									
								
								router-app/static/packages/style.css
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,115 @@
 | 
				
			|||||||
 | 
					:root {
 | 
				
			||||||
 | 
					  font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
 | 
				
			||||||
 | 
					  line-height: 1.5;
 | 
				
			||||||
 | 
					  font-weight: 400;
 | 
				
			||||||
 | 
					  color-scheme: light dark;
 | 
				
			||||||
 | 
					  background-color: #fff8e1;
 | 
				
			||||||
 | 
					  color: #213547;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					body {
 | 
				
			||||||
 | 
					  margin: 0;
 | 
				
			||||||
 | 
					  min-width: 320px;
 | 
				
			||||||
 | 
					  min-height: 100vh;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#app {
 | 
				
			||||||
 | 
					  max-width: 1280px;
 | 
				
			||||||
 | 
					  margin: 0 auto;
 | 
				
			||||||
 | 
					  padding: 2rem;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					h1 {
 | 
				
			||||||
 | 
					  text-align: center;
 | 
				
			||||||
 | 
					  color: #ff8f00;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.package-list {
 | 
				
			||||||
 | 
					  display: grid;
 | 
				
			||||||
 | 
					  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
 | 
				
			||||||
 | 
					  gap: 1rem;
 | 
				
			||||||
 | 
					  padding: 1rem;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.package-card {
 | 
				
			||||||
 | 
					  background: white;
 | 
				
			||||||
 | 
					  border-radius: 8px;
 | 
				
			||||||
 | 
					  padding: 1.5rem;
 | 
				
			||||||
 | 
					  box-shadow: 0 2px 4px rgba(255, 143, 0, 0.1);
 | 
				
			||||||
 | 
					  border: 1px solid #ffe0b2;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.package-card h2 {
 | 
				
			||||||
 | 
					  margin: 0 0 0.5rem 0;
 | 
				
			||||||
 | 
					  color: #f57c00;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.package-card .description {
 | 
				
			||||||
 | 
					  color: #666;
 | 
				
			||||||
 | 
					  margin-bottom: 1rem;
 | 
				
			||||||
 | 
					  font-size: 0.9rem;
 | 
				
			||||||
 | 
					  display: -webkit-box;
 | 
				
			||||||
 | 
					  -webkit-line-clamp: 4;
 | 
				
			||||||
 | 
					  -webkit-box-orient: vertical;
 | 
				
			||||||
 | 
					  overflow: hidden;
 | 
				
			||||||
 | 
					  text-overflow: ellipsis;
 | 
				
			||||||
 | 
					  line-height: 1.5;
 | 
				
			||||||
 | 
					  max-height: 6em;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.package-info {
 | 
				
			||||||
 | 
					  display: flex;
 | 
				
			||||||
 | 
					  justify-content: space-between;
 | 
				
			||||||
 | 
					  align-items: center;
 | 
				
			||||||
 | 
					  margin-bottom: 1rem;
 | 
				
			||||||
 | 
					  font-size: 0.9rem;
 | 
				
			||||||
 | 
					  color: #666;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.button {
 | 
				
			||||||
 | 
					  padding: 0.5rem 1rem;
 | 
				
			||||||
 | 
					  border-radius: 4px;
 | 
				
			||||||
 | 
					  border: none;
 | 
				
			||||||
 | 
					  cursor: pointer;
 | 
				
			||||||
 | 
					  font-weight: 500;
 | 
				
			||||||
 | 
					  transition: background-color 0.2s;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.button-install {
 | 
				
			||||||
 | 
					  background-color: #ffa000;
 | 
				
			||||||
 | 
					  color: white;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.button-update {
 | 
				
			||||||
 | 
					  background-color: #ff8f00;
 | 
				
			||||||
 | 
					  color: white;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.button-reinstall {
 | 
				
			||||||
 | 
					  background-color: #ffb300;
 | 
				
			||||||
 | 
					  color: white;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.button-uninstall {
 | 
				
			||||||
 | 
					  background-color: #ff6f00;
 | 
				
			||||||
 | 
					  color: white;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.button:hover {
 | 
				
			||||||
 | 
					  opacity: 0.9;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.button:disabled {
 | 
				
			||||||
 | 
					  background-color: #ffe0b2;
 | 
				
			||||||
 | 
					  cursor: not-allowed;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.error-message {
 | 
				
			||||||
 | 
					  text-align: center;
 | 
				
			||||||
 | 
					  color: #ff6f00;
 | 
				
			||||||
 | 
					  padding: 2rem;
 | 
				
			||||||
 | 
					  background: white;
 | 
				
			||||||
 | 
					  border-radius: 8px;
 | 
				
			||||||
 | 
					  box-shadow: 0 2px 4px rgba(255, 143, 0, 0.1);
 | 
				
			||||||
 | 
					  grid-column: 1 / -1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										35
									
								
								src/main/handle/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/main/handle/index.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
				
			|||||||
 | 
					import { ipcMain } from 'electron';
 | 
				
			||||||
 | 
					import { getAppList, getCacheAssistantConfig, setConfig } from '@/modules/config';
 | 
				
			||||||
 | 
					import { installApp, uninstallApp } from '../proxy/install';
 | 
				
			||||||
 | 
					import { relunch } from '../window/relunch';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const handle = () => {
 | 
				
			||||||
 | 
					  ipcMain.handle('get-app-list', (event, data) => {
 | 
				
			||||||
 | 
					    // 获取应用路径
 | 
				
			||||||
 | 
					    const appList = getAppList();
 | 
				
			||||||
 | 
					    return appList;
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  ipcMain.handle('install-app', (event, data) => {
 | 
				
			||||||
 | 
					    console.log('install-app', data.user, data.key, data.version);
 | 
				
			||||||
 | 
					    return installApp(data);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  ipcMain.handle('uninstall-app', (event, data) => {
 | 
				
			||||||
 | 
					    console.log('uninstall-app', data.user, data.key, data.version);
 | 
				
			||||||
 | 
					    return uninstallApp(data);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  ipcMain.handle('save-app-config', (event, data) => {
 | 
				
			||||||
 | 
					    console.log('save-app-config', data);
 | 
				
			||||||
 | 
					    if (!data) {
 | 
				
			||||||
 | 
					      return getCacheAssistantConfig();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    const config = getCacheAssistantConfig();
 | 
				
			||||||
 | 
					    return setConfig({ ...config, ...data });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  ipcMain.handle('relunch', () => {
 | 
				
			||||||
 | 
					    relunch();
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										47
									
								
								src/main/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								src/main/index.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,47 @@
 | 
				
			|||||||
 | 
					import { app, BrowserWindow, ipcMain, session } from 'electron';
 | 
				
			||||||
 | 
					import * as path from 'path';
 | 
				
			||||||
 | 
					import { fileURLToPath } from 'url';
 | 
				
			||||||
 | 
					import { LocalElectronAppUrl } from '../modules/config';
 | 
				
			||||||
 | 
					import { createSession } from './session';
 | 
				
			||||||
 | 
					import { handle } from './handle';
 | 
				
			||||||
 | 
					import { loadMenu } from './menu';
 | 
				
			||||||
 | 
					import { checkShowPage } from './window/page';
 | 
				
			||||||
 | 
					import { createIntroducePage } from './window/page/introduce';
 | 
				
			||||||
 | 
					const __filename = fileURLToPath(import.meta.url);
 | 
				
			||||||
 | 
					const __dirname = path.dirname(__filename);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					let mainWindow: BrowserWindow | null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async function createWindow() {
 | 
				
			||||||
 | 
					  const _session = createSession();
 | 
				
			||||||
 | 
					  mainWindow = new BrowserWindow({
 | 
				
			||||||
 | 
					    width: 800,
 | 
				
			||||||
 | 
					    height: 600,
 | 
				
			||||||
 | 
					    webPreferences: {
 | 
				
			||||||
 | 
					      preload: path.join(__dirname, 'preload.js'), // 如果有 preload 脚本
 | 
				
			||||||
 | 
					      session: _session,
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  loadMenu();
 | 
				
			||||||
 | 
					  await checkShowPage(mainWindow);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  mainWindow.on('closed', () => {
 | 
				
			||||||
 | 
					    mainWindow = null;
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app.on('ready', createWindow);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app.on('window-all-closed', () => {
 | 
				
			||||||
 | 
					  if (process.platform !== 'darwin') {
 | 
				
			||||||
 | 
					    app.quit();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app.on('activate', () => {
 | 
				
			||||||
 | 
					  if (mainWindow === null) {
 | 
				
			||||||
 | 
					    createWindow();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					handle();
 | 
				
			||||||
							
								
								
									
										6
									
								
								src/main/logger.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/main/logger.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					import log from 'electron-log';
 | 
				
			||||||
 | 
					// $Home/Library/Logs/ads-desktop-electron/main.log
 | 
				
			||||||
 | 
					log.initialize({ preload: true });
 | 
				
			||||||
 | 
					export { log };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const getLogPath = () => log.transports.file.getFile().path;
 | 
				
			||||||
							
								
								
									
										117
									
								
								src/main/menu/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										117
									
								
								src/main/menu/index.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,117 @@
 | 
				
			|||||||
 | 
					import { createEnterPage } from '../window/page/enter';
 | 
				
			||||||
 | 
					import { BrowserWindow, Menu, app } from 'electron';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import path from 'path';
 | 
				
			||||||
 | 
					import { getLogPath, log } from '../logger';
 | 
				
			||||||
 | 
					import { createAppPackagesPage } from '../window/page/app-packages';
 | 
				
			||||||
 | 
					import { relunch } from '../window/relunch';
 | 
				
			||||||
 | 
					export const loadMenu = () => {
 | 
				
			||||||
 | 
					  const template = [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      label: app.name,
 | 
				
			||||||
 | 
					      submenu: [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          label: '关于',
 | 
				
			||||||
 | 
					          role: 'about',
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          label: '退出',
 | 
				
			||||||
 | 
					          click: () => {
 | 
				
			||||||
 | 
					            if (process.platform !== 'darwin') {
 | 
				
			||||||
 | 
					              app.quit();
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					              app.exit();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        // {
 | 
				
			||||||
 | 
					        //   label: '检查更新',
 | 
				
			||||||
 | 
					        //   click: () => {
 | 
				
			||||||
 | 
					        //     autoUpdater.checkForUpdatesAndNotify();
 | 
				
			||||||
 | 
					        //   },
 | 
				
			||||||
 | 
					        // },
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      label: '编辑',
 | 
				
			||||||
 | 
					      submenu: [
 | 
				
			||||||
 | 
					        { label: '复制', accelerator: 'CmdOrCtrl+C', selector: 'copy:' },
 | 
				
			||||||
 | 
					        { label: '粘贴', accelerator: 'CmdOrCtrl+V', selector: 'paste:' },
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      label: '查看',
 | 
				
			||||||
 | 
					      role: 'view',
 | 
				
			||||||
 | 
					      submenu: [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          label: '刷新',
 | 
				
			||||||
 | 
					          role: 'reload',
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          label: '强制刷新',
 | 
				
			||||||
 | 
					          role: 'forcereload',
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          label: '重启',
 | 
				
			||||||
 | 
					          click: () => {
 | 
				
			||||||
 | 
					            relunch();
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          label: '打开开发者工具',
 | 
				
			||||||
 | 
					          click: () => {
 | 
				
			||||||
 | 
					            const mainWindow = BrowserWindow.getFocusedWindow();
 | 
				
			||||||
 | 
					            if (mainWindow) {
 | 
				
			||||||
 | 
					              openDevTools(mainWindow);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      label: '帮助',
 | 
				
			||||||
 | 
					      role: 'help',
 | 
				
			||||||
 | 
					      submenu: [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          label: '文档',
 | 
				
			||||||
 | 
					          click: async () => {
 | 
				
			||||||
 | 
					            const { shell } = require('electron');
 | 
				
			||||||
 | 
					            // shell.openExternal('http://adstudio.nisar.ai/docs/');
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          label: '打开日志',
 | 
				
			||||||
 | 
					          click: async () => {
 | 
				
			||||||
 | 
					            const { shell } = require('electron');
 | 
				
			||||||
 | 
					            log.transports.file.fileName;
 | 
				
			||||||
 | 
					            shell.openExternal('file://' + path.join(getLogPath()));
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          label: '打开配置',
 | 
				
			||||||
 | 
					          click: async () => {
 | 
				
			||||||
 | 
					            createEnterPage();
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          label: '打开应用市场',
 | 
				
			||||||
 | 
					          click: async () => {
 | 
				
			||||||
 | 
					            createAppPackagesPage();
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  ];
 | 
				
			||||||
 | 
					  // @ts-ignore
 | 
				
			||||||
 | 
					  const menu = Menu.buildFromTemplate(template);
 | 
				
			||||||
 | 
					  Menu.setApplicationMenu(menu);
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const openDevTools = (mainWindow: BrowserWindow) => {
 | 
				
			||||||
 | 
					  let window = mainWindow.getBrowserView() ? mainWindow.getBrowserView() : mainWindow;
 | 
				
			||||||
 | 
					  if (window.webContents.isDevToolsOpened()) {
 | 
				
			||||||
 | 
					    window.webContents.closeDevTools();
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    window.webContents.openDevTools();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										19
									
								
								src/main/preload.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/main/preload.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					const { contextBridge, ipcRenderer } = require('electron');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const windowChannels = ['relunch'];
 | 
				
			||||||
 | 
					const validChannels = ['get-app-list', 'install-app', 'uninstall-app', 'save-app-config', ...windowChannels];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					contextBridge.exposeInMainWorld('electron', {
 | 
				
			||||||
 | 
					  ipcRenderer: {
 | 
				
			||||||
 | 
					    on(channel, func) {
 | 
				
			||||||
 | 
					      if (validChannels.includes(channel)) {
 | 
				
			||||||
 | 
					        ipcRenderer.on(channel, func);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    invoke(channel, ...args) {
 | 
				
			||||||
 | 
					      if (validChannels.includes(channel)) {
 | 
				
			||||||
 | 
					        return ipcRenderer.invoke(channel, ...args);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
							
								
								
									
										12
									
								
								src/main/proxy/api-proxy.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/main/proxy/api-proxy.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					export const apiProxyList = [
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    path: '/v1',
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    path: '/v2',
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    path: '/api',
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										0
									
								
								src/main/proxy/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/main/proxy/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										141
									
								
								src/main/proxy/install.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										141
									
								
								src/main/proxy/install.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,141 @@
 | 
				
			|||||||
 | 
					import path from 'path';
 | 
				
			||||||
 | 
					import fs from 'fs';
 | 
				
			||||||
 | 
					import { appDir, kevisualUrl, addAppConfig, getAppConfig, setAppConfig, getCacheAssistantConfig, setConfig } from '../../modules/config';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const demoData = {
 | 
				
			||||||
 | 
					  id: '471ee96f-d7d8-4da1-b84f-4a34f4732f16',
 | 
				
			||||||
 | 
					  title: 'tiptap',
 | 
				
			||||||
 | 
					  description: '',
 | 
				
			||||||
 | 
					  data: {
 | 
				
			||||||
 | 
					    files: [
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        name: 'README.md',
 | 
				
			||||||
 | 
					        path: 'user/tiptap/0.0.1/README.md',
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        name: 'app.css',
 | 
				
			||||||
 | 
					        path: 'user/tiptap/0.0.1/app.css',
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        name: 'app.js',
 | 
				
			||||||
 | 
					        path: 'user/tiptap/0.0.1/app.js',
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        name: 'create-BxEwtceK.js',
 | 
				
			||||||
 | 
					        path: 'user/tiptap/0.0.1/create-BxEwtceK.js',
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        name: 'index.CrTXFMOJ.js',
 | 
				
			||||||
 | 
					        path: 'user/tiptap/0.0.1/index.CrTXFMOJ.js',
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        name: 'index.html',
 | 
				
			||||||
 | 
					        path: 'user/tiptap/0.0.1/index.html',
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  version: '0.0.1',
 | 
				
			||||||
 | 
					  domain: '',
 | 
				
			||||||
 | 
					  appType: '',
 | 
				
			||||||
 | 
					  key: 'tiptap',
 | 
				
			||||||
 | 
					  type: '',
 | 
				
			||||||
 | 
					  uid: '2bebe6a0-3c64-4a64-89f9-cc47fd082a07',
 | 
				
			||||||
 | 
					  pid: null,
 | 
				
			||||||
 | 
					  proxy: false,
 | 
				
			||||||
 | 
					  user: 'user',
 | 
				
			||||||
 | 
					  status: 'running',
 | 
				
			||||||
 | 
					  createdAt: '2024-12-14T15:39:30.684Z',
 | 
				
			||||||
 | 
					  updatedAt: '2024-12-14T15:39:55.714Z',
 | 
				
			||||||
 | 
					  deletedAt: null,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type DownloadTask = {
 | 
				
			||||||
 | 
					  downloadPath: string;
 | 
				
			||||||
 | 
					  downloadUrl: string;
 | 
				
			||||||
 | 
					  user: string;
 | 
				
			||||||
 | 
					  key: string;
 | 
				
			||||||
 | 
					  version: string;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					export const installApp = async (app: any) => {
 | 
				
			||||||
 | 
					  // const _app = demoData;
 | 
				
			||||||
 | 
					  const _app = app;
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    let files = _app.data.files || [];
 | 
				
			||||||
 | 
					    const version = _app.version;
 | 
				
			||||||
 | 
					    const user = _app.user;
 | 
				
			||||||
 | 
					    const key = _app.key;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const downFiles = files.map((file: any) => {
 | 
				
			||||||
 | 
					      const noVersionPath = file.path.replace(`/${version}`, '');
 | 
				
			||||||
 | 
					      return {
 | 
				
			||||||
 | 
					        ...file,
 | 
				
			||||||
 | 
					        downloadPath: path.join(appDir, noVersionPath),
 | 
				
			||||||
 | 
					        downloadUrl: `${kevisualUrl}/${noVersionPath}`,
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    const downloadTasks: DownloadTask[] = downFiles as any;
 | 
				
			||||||
 | 
					    for (const file of downloadTasks) {
 | 
				
			||||||
 | 
					      const downloadPath = file.downloadPath;
 | 
				
			||||||
 | 
					      const downloadUrl = file.downloadUrl;
 | 
				
			||||||
 | 
					      const dir = path.dirname(downloadPath);
 | 
				
			||||||
 | 
					      if (!fs.existsSync(dir)) {
 | 
				
			||||||
 | 
					        fs.mkdirSync(dir, { recursive: true });
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      const res = await fetch(downloadUrl);
 | 
				
			||||||
 | 
					      const blob = await res.blob();
 | 
				
			||||||
 | 
					      fs.writeFileSync(downloadPath, Buffer.from(await blob.arrayBuffer()));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    let indexHtml = files.find((file: any) => file.name === 'index.html');
 | 
				
			||||||
 | 
					    if (!indexHtml) {
 | 
				
			||||||
 | 
					      files.push({
 | 
				
			||||||
 | 
					        name: 'index.html',
 | 
				
			||||||
 | 
					        path: `${user}/${key}/index.html`,
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					      fs.writeFileSync(path.join(appDir, `${user}/${key}/index.html`), JSON.stringify(app, null, 2));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    _app.data.files = files;
 | 
				
			||||||
 | 
					    addAppConfig(_app);
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					      code: 200,
 | 
				
			||||||
 | 
					      data: _app,
 | 
				
			||||||
 | 
					      message: 'Install app success',
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    console.error(error);
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					      code: 500,
 | 
				
			||||||
 | 
					      message: 'Install app failed',
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const uninstallApp = async (app: any) => {
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    const { user, key } = app;
 | 
				
			||||||
 | 
					    const appConfig = getAppConfig();
 | 
				
			||||||
 | 
					    const index = appConfig.list.findIndex((item: any) => item.user === user && item.key === key);
 | 
				
			||||||
 | 
					    if (index !== -1) {
 | 
				
			||||||
 | 
					      appConfig.list.splice(index, 1);
 | 
				
			||||||
 | 
					      setAppConfig(appConfig);
 | 
				
			||||||
 | 
					      // 删除appDir和文件
 | 
				
			||||||
 | 
					      fs.rmSync(path.join(appDir, user, key), { recursive: true });
 | 
				
			||||||
 | 
					      // 删除proxy
 | 
				
			||||||
 | 
					      const proxyConfig = getCacheAssistantConfig();
 | 
				
			||||||
 | 
					      const proxyIndex = proxyConfig.proxy.findIndex((item: any) => item.user === user && item.key === key);
 | 
				
			||||||
 | 
					      if (proxyIndex !== -1) {
 | 
				
			||||||
 | 
					        proxyConfig.proxy.splice(proxyIndex, 1);
 | 
				
			||||||
 | 
					        setConfig(proxyConfig);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					      code: 200,
 | 
				
			||||||
 | 
					      message: 'Uninstall app success',
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    console.error(error);
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					      code: 500,
 | 
				
			||||||
 | 
					      message: 'Uninstall app failed',
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										6
									
								
								src/main/renderer.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/main/renderer.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					// This file is required by the index.html file and will
 | 
				
			||||||
 | 
					// be executed in the renderer process for that window.
 | 
				
			||||||
 | 
					// No Node.js APIs are available in this process unless
 | 
				
			||||||
 | 
					// nodeIntegration is set to true in webPreferences.
 | 
				
			||||||
 | 
					// Use preload.js to selectively enable features
 | 
				
			||||||
 | 
					// needed in the renderer process.
 | 
				
			||||||
							
								
								
									
										57
									
								
								src/main/session/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								src/main/session/index.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,57 @@
 | 
				
			|||||||
 | 
					import { app, BrowserWindow, ipcMain, session } from 'electron';
 | 
				
			||||||
 | 
					import { getCacheAssistantConfig, appDir, LocalElectronAppUrl } from '../../modules/config';
 | 
				
			||||||
 | 
					import { net } from 'electron';
 | 
				
			||||||
 | 
					import path from 'path';
 | 
				
			||||||
 | 
					import * as url from 'url';
 | 
				
			||||||
 | 
					import { checkFileExists } from '../../modules/file';
 | 
				
			||||||
 | 
					import { apiProxyList } from '../proxy/api-proxy';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					let _session: Electron.Session;
 | 
				
			||||||
 | 
					export const createSession = () => {
 | 
				
			||||||
 | 
					  if (_session) {
 | 
				
			||||||
 | 
					    return _session;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  // 创建一个持久化的会话
 | 
				
			||||||
 | 
					  _session = session.fromPartition('persist:app');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _session.protocol.handle('https', async (req) => {
 | 
				
			||||||
 | 
					    const requrl = req.url;
 | 
				
			||||||
 | 
					    const newReqUrl = new URL(requrl);
 | 
				
			||||||
 | 
					    const localOrigin = new URL(LocalElectronAppUrl).origin;
 | 
				
			||||||
 | 
					    if (newReqUrl.origin !== localOrigin) {
 | 
				
			||||||
 | 
					      // 不拦截
 | 
				
			||||||
 | 
					      return net.fetch(req.url, { bypassCustomProtocolHandlers: true });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    const apiProxy = apiProxyList.find((_proxy: any) => newReqUrl.pathname.startsWith(_proxy.path));
 | 
				
			||||||
 | 
					    if (apiProxy) {
 | 
				
			||||||
 | 
					      const pageApi = getCacheAssistantConfig().pageApi || '';
 | 
				
			||||||
 | 
					      if (!pageApi) {
 | 
				
			||||||
 | 
					        return new Response(`App Page Api Not Set, please set it first`);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      const newPageUrl = new URL(req.url, pageApi);
 | 
				
			||||||
 | 
					      return net.fetch(newPageUrl.toString(), { bypassCustomProtocolHandlers: true });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    const [user, key] = newReqUrl.pathname.split('/').slice(1);
 | 
				
			||||||
 | 
					    const proxyList = getCacheAssistantConfig().proxy || [];
 | 
				
			||||||
 | 
					    const proxy = proxyList.find((_proxy: any) => newReqUrl.pathname.startsWith(_proxy.path));
 | 
				
			||||||
 | 
					    if (proxy) {
 | 
				
			||||||
 | 
					      try {
 | 
				
			||||||
 | 
					        const relativePath = path.join(appDir, newReqUrl.pathname);
 | 
				
			||||||
 | 
					        const indexHtml = path.join(appDir, user, key, 'index.html');
 | 
				
			||||||
 | 
					        console.log('relativePath', relativePath);
 | 
				
			||||||
 | 
					        if (checkFileExists(relativePath, true)) {
 | 
				
			||||||
 | 
					          const res = await net.fetch(url.pathToFileURL(relativePath).toString());
 | 
				
			||||||
 | 
					          return res;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          const res = await net.fetch(url.pathToFileURL(indexHtml).toString());
 | 
				
			||||||
 | 
					          return res;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      } catch (error) {
 | 
				
			||||||
 | 
					        console.error(error);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      return new Response('App is Running Error, please reinstall it or refresh the page');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return new Response(`App Not Install, please install it first,user/app: [${user}/${key}]`);
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  return _session;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										19
									
								
								src/main/window/page/app-packages.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/main/window/page/app-packages.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					import { BrowserWindow } from 'electron';
 | 
				
			||||||
 | 
					import path from 'path';
 | 
				
			||||||
 | 
					import { fileURLToPath } from 'url';
 | 
				
			||||||
 | 
					const __filename = fileURLToPath(import.meta.url);
 | 
				
			||||||
 | 
					const __dirname = path.dirname(__filename);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const createAppPackagesPage = (window?: BrowserWindow) => {
 | 
				
			||||||
 | 
					  const mainWindow =
 | 
				
			||||||
 | 
					    window ||
 | 
				
			||||||
 | 
					    new BrowserWindow({
 | 
				
			||||||
 | 
					      width: 800,
 | 
				
			||||||
 | 
					      height: 600,
 | 
				
			||||||
 | 
					      webPreferences: {
 | 
				
			||||||
 | 
					      preload: path.join(__dirname, 'preload.js'), // 如果有 preload 脚本
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  mainWindow.loadFile(path.join(__dirname, '../renderer/packages/index.html')); // Vite 构建后的文件
 | 
				
			||||||
 | 
					  return mainWindow;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										19
									
								
								src/main/window/page/enter.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/main/window/page/enter.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					import { BrowserWindow } from 'electron';
 | 
				
			||||||
 | 
					import path from 'path';
 | 
				
			||||||
 | 
					import { fileURLToPath } from 'url';
 | 
				
			||||||
 | 
					const __filename = fileURLToPath(import.meta.url);
 | 
				
			||||||
 | 
					const __dirname = path.dirname(__filename);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const createEnterPage = (window?: BrowserWindow) => {
 | 
				
			||||||
 | 
					  const mainWindow =
 | 
				
			||||||
 | 
					    window ||
 | 
				
			||||||
 | 
					    new BrowserWindow({
 | 
				
			||||||
 | 
					      width: 800,
 | 
				
			||||||
 | 
					      height: 600,
 | 
				
			||||||
 | 
					      webPreferences: {
 | 
				
			||||||
 | 
					        preload: path.join(__dirname, 'preload.js'), // 如果有 preload 脚本
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  mainWindow.loadFile(path.join(__dirname, '../renderer/enter/index.html')); // Vite 构建后的文件
 | 
				
			||||||
 | 
					  return mainWindow;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										18
									
								
								src/main/window/page/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/main/window/page/index.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					import { getCacheAssistantConfig, LocalElectronAppUrl } from '@/modules/config';
 | 
				
			||||||
 | 
					import { createEnterPage } from './enter';
 | 
				
			||||||
 | 
					import { createAppPackagesPage } from './app-packages';
 | 
				
			||||||
 | 
					import { BrowserWindow } from 'electron';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const checkShowPage = async (window?: BrowserWindow) => {
 | 
				
			||||||
 | 
					  const assistantConfig = getCacheAssistantConfig();
 | 
				
			||||||
 | 
					  const { pageApi, proxy } = assistantConfig;
 | 
				
			||||||
 | 
					  if (!pageApi) {
 | 
				
			||||||
 | 
					    createEnterPage(window);
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  if (!proxy || proxy.length === 0) {
 | 
				
			||||||
 | 
					    createAppPackagesPage(window);
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return window?.loadURL(LocalElectronAppUrl);
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										19
									
								
								src/main/window/page/introduce.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/main/window/page/introduce.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					import { BrowserWindow } from 'electron';
 | 
				
			||||||
 | 
					import path from 'path';
 | 
				
			||||||
 | 
					import { fileURLToPath } from 'url';
 | 
				
			||||||
 | 
					const __filename = fileURLToPath(import.meta.url);
 | 
				
			||||||
 | 
					const __dirname = path.dirname(__filename);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const createIntroducePage = (window?: BrowserWindow) => {
 | 
				
			||||||
 | 
					  const mainWindow =
 | 
				
			||||||
 | 
					    window ||
 | 
				
			||||||
 | 
					    new BrowserWindow({
 | 
				
			||||||
 | 
					      width: 800,
 | 
				
			||||||
 | 
					      height: 600,
 | 
				
			||||||
 | 
					      webPreferences: {
 | 
				
			||||||
 | 
					        preload: path.join(__dirname, 'preload.js'), // 如果有 preload 脚本
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  mainWindow.loadFile(path.join(__dirname, '../renderer/index.html')); //
 | 
				
			||||||
 | 
					  return mainWindow;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										6
									
								
								src/main/window/relunch.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/main/window/relunch.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					import { app } from 'electron';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const relunch = () => {
 | 
				
			||||||
 | 
					  app.relaunch({});
 | 
				
			||||||
 | 
					  app.quit();
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										11
									
								
								src/main/window/window-manager.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/main/window/window-manager.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					import { BrowserWindow } from 'electron';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export class WindowsManager {
 | 
				
			||||||
 | 
					  static window: BrowserWindow;
 | 
				
			||||||
 | 
					  static setWindow = (window: BrowserWindow) => {
 | 
				
			||||||
 | 
					    WindowsManager.window = window;
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					  static getWindow = () => {
 | 
				
			||||||
 | 
					    return WindowsManager.window;
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										108
									
								
								src/modules/config/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										108
									
								
								src/modules/config/index.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,108 @@
 | 
				
			|||||||
 | 
					import path from 'path';
 | 
				
			||||||
 | 
					import { homedir } from 'os';
 | 
				
			||||||
 | 
					import fs from 'fs';
 | 
				
			||||||
 | 
					import { checkFileExists, createDir } from '../file';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const kevisualUrl = 'https://kevisual.xiongxiao.me';
 | 
				
			||||||
 | 
					const configDir = createDir(path.join(homedir(), '.config/envision'));
 | 
				
			||||||
 | 
					export const configPath = path.join(configDir, 'assistant-config.json');
 | 
				
			||||||
 | 
					export const appConfigPath = path.join(configDir, 'assistant-app-config.json');
 | 
				
			||||||
 | 
					export const appDir = createDir(path.join(configDir, 'assistant-app/frontend'));
 | 
				
			||||||
 | 
					export const LocalElectronAppUrl = 'https://assistant.app/user/tiptap/';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type AssistantConfig = {
 | 
				
			||||||
 | 
					  pageApi?: string; // https://kevisual.silkyai.cn
 | 
				
			||||||
 | 
					  loadURL?: string; // https://assistant.app/user/tiptap/
 | 
				
			||||||
 | 
					  proxy?: { user: string; key: string; path: string }[];
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					let assistantConfig: AssistantConfig;
 | 
				
			||||||
 | 
					export const getConfig = () => {
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    if (!checkFileExists(configPath)) {
 | 
				
			||||||
 | 
					      fs.writeFileSync(configPath, JSON.stringify({ proxy: [] }, null, 2));
 | 
				
			||||||
 | 
					      return {
 | 
				
			||||||
 | 
					        loadURL: LocalElectronAppUrl,
 | 
				
			||||||
 | 
					        pageApi: '',
 | 
				
			||||||
 | 
					        proxy: [],
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    assistantConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'));
 | 
				
			||||||
 | 
					    return assistantConfig;
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    console.error(error);
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					      loadURL: LocalElectronAppUrl,
 | 
				
			||||||
 | 
					      pageApi: '',
 | 
				
			||||||
 | 
					      proxy: [],
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					export const getCacheAssistantConfig = () => {
 | 
				
			||||||
 | 
					  if (assistantConfig) {
 | 
				
			||||||
 | 
					    return assistantConfig;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return getConfig();
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const setConfig = (config?: AssistantConfig) => {
 | 
				
			||||||
 | 
					  if (!config) {
 | 
				
			||||||
 | 
					    return assistantConfig;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  assistantConfig = config;
 | 
				
			||||||
 | 
					  fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
 | 
				
			||||||
 | 
					  return assistantConfig;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					type AppConfig = {
 | 
				
			||||||
 | 
					  list: any[];
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 应用配置
 | 
				
			||||||
 | 
					 * @returns
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export const getAppConfig = (): AppConfig => {
 | 
				
			||||||
 | 
					  if (!checkFileExists(appConfigPath)) {
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					      list: [],
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return JSON.parse(fs.readFileSync(appConfigPath, 'utf8'));
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const setAppConfig = (config: AppConfig) => {
 | 
				
			||||||
 | 
					  fs.writeFileSync(appConfigPath, JSON.stringify(config, null, 2));
 | 
				
			||||||
 | 
					  return config;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const addAppConfig = (app: any) => {
 | 
				
			||||||
 | 
					  const config = getAppConfig();
 | 
				
			||||||
 | 
					  const assistantConfig = getCacheAssistantConfig();
 | 
				
			||||||
 | 
					  const _apps = config.list;
 | 
				
			||||||
 | 
					  const _proxy = assistantConfig.proxy || [];
 | 
				
			||||||
 | 
					  const { user, key } = app;
 | 
				
			||||||
 | 
					  const newProxyInfo = {
 | 
				
			||||||
 | 
					    user,
 | 
				
			||||||
 | 
					    key,
 | 
				
			||||||
 | 
					    path: `/${user}/${key}`,
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					  const _proxyIndex = _proxy.findIndex((_proxy: any) => _proxy.path === newProxyInfo.path);
 | 
				
			||||||
 | 
					  if (_proxyIndex !== -1) {
 | 
				
			||||||
 | 
					    _proxy[_proxyIndex] = newProxyInfo;
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    _proxy.push(newProxyInfo);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const _app = _apps.findIndex((_app: any) => _app.id === app.id);
 | 
				
			||||||
 | 
					  if (_app !== -1) {
 | 
				
			||||||
 | 
					    _apps[_app] = app;
 | 
				
			||||||
 | 
					  } else {
 | 
				
			||||||
 | 
					    _apps.push(app);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  setAppConfig({ ...config, list: _apps });
 | 
				
			||||||
 | 
					  setConfig({ ...assistantConfig, proxy: _proxy });
 | 
				
			||||||
 | 
					  return config;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const getAppList = () => {
 | 
				
			||||||
 | 
					  const config = getAppConfig();
 | 
				
			||||||
 | 
					  return config.list || [];
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										20
									
								
								src/modules/file/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								src/modules/file/index.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
				
			|||||||
 | 
					import fs from 'fs';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const checkFileExists = (filePath: string, checkIsFile = false) => {
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    fs.accessSync(filePath);
 | 
				
			||||||
 | 
					    if (checkIsFile) {
 | 
				
			||||||
 | 
					      return fs.statSync(filePath).isFile();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return true;
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const createDir = (dirPath: string) => {
 | 
				
			||||||
 | 
					  if (!checkFileExists(dirPath)) {
 | 
				
			||||||
 | 
					    fs.mkdirSync(dirPath, { recursive: true });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return dirPath;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								src/renderer/assistant-center.tgz
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/renderer/assistant-center.tgz
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										76
									
								
								src/renderer/assistant-center/package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								src/renderer/assistant-center/package.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,76 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "name": "assistant-center",
 | 
				
			||||||
 | 
					  "version": "0.0.1",
 | 
				
			||||||
 | 
					  "description": "",
 | 
				
			||||||
 | 
					  "main": "index.js",
 | 
				
			||||||
 | 
					  "app": {
 | 
				
			||||||
 | 
					    "key": "assistant-center",
 | 
				
			||||||
 | 
					    "entry": "dist/app.mjs",
 | 
				
			||||||
 | 
					    "type": "system-app",
 | 
				
			||||||
 | 
					    "files": [
 | 
				
			||||||
 | 
					      "dist",
 | 
				
			||||||
 | 
					      "pem",
 | 
				
			||||||
 | 
					      "root"
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "scripts": {
 | 
				
			||||||
 | 
					    "watch": "rollup -c rollup.config.mjs -w",
 | 
				
			||||||
 | 
					    "dev": "cross-env NODE_ENV=development nodemon --delay 2.5 -e js,cjs,mjs --exec node dist/app.mjs",
 | 
				
			||||||
 | 
					    "build": "rollup -c rollup.config.mjs",
 | 
				
			||||||
 | 
					    "test": "tsx  test/**/*.ts",
 | 
				
			||||||
 | 
					    "dev:watch": "cross-env NODE_ENV=development concurrently -n \"Watch,Dev\" -c \"green,blue\" \"npm run watch\" \"sleep 1 && npm run dev\" ",
 | 
				
			||||||
 | 
					    "clean": "rm -rf dist",
 | 
				
			||||||
 | 
					    "prepub": "envision switch root",
 | 
				
			||||||
 | 
					    "pub": "npm run build && envision pack -p -u"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "keywords": [],
 | 
				
			||||||
 | 
					  "author": "abearxiong <xiongxiao@xiongxiao.me>",
 | 
				
			||||||
 | 
					  "license": "MIT",
 | 
				
			||||||
 | 
					  "type": "module",
 | 
				
			||||||
 | 
					  "types": "types/index.d.ts",
 | 
				
			||||||
 | 
					  "files": [
 | 
				
			||||||
 | 
					    "dist",
 | 
				
			||||||
 | 
					    "pem",
 | 
				
			||||||
 | 
					    "root"
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "dependencies": {
 | 
				
			||||||
 | 
					    "@kevisual/code-center-module": "0.0.13",
 | 
				
			||||||
 | 
					    "@kevisual/mark": "0.0.7",
 | 
				
			||||||
 | 
					    "@kevisual/router": "0.0.9",
 | 
				
			||||||
 | 
					    "cookie": "^1.0.2",
 | 
				
			||||||
 | 
					    "dayjs": "^1.11.13",
 | 
				
			||||||
 | 
					    "formidable": "^3.5.2",
 | 
				
			||||||
 | 
					    "json5": "^2.2.3",
 | 
				
			||||||
 | 
					    "lodash-es": "^4.17.21",
 | 
				
			||||||
 | 
					    "ws": "^8.18.1"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "devDependencies": {
 | 
				
			||||||
 | 
					    "@kevisual/assistant-module": "workspace:*",
 | 
				
			||||||
 | 
					    "@kevisual/types": "^0.0.6",
 | 
				
			||||||
 | 
					    "@kevisual/use-config": "^1.0.9",
 | 
				
			||||||
 | 
					    "@rollup/plugin-alias": "^5.1.1",
 | 
				
			||||||
 | 
					    "@rollup/plugin-commonjs": "^28.0.3",
 | 
				
			||||||
 | 
					    "@rollup/plugin-json": "^6.1.0",
 | 
				
			||||||
 | 
					    "@rollup/plugin-node-resolve": "^16.0.0",
 | 
				
			||||||
 | 
					    "@rollup/plugin-replace": "^6.0.2",
 | 
				
			||||||
 | 
					    "@rollup/plugin-typescript": "^12.1.2",
 | 
				
			||||||
 | 
					    "@types/crypto-js": "^4.2.2",
 | 
				
			||||||
 | 
					    "@types/formidable": "^3.4.5",
 | 
				
			||||||
 | 
					    "@types/lodash-es": "^4.17.12",
 | 
				
			||||||
 | 
					    "@types/node": "^22.13.9",
 | 
				
			||||||
 | 
					    "@types/ws": "^8.18.0",
 | 
				
			||||||
 | 
					    "concurrently": "^9.1.2",
 | 
				
			||||||
 | 
					    "cross-env": "^7.0.3",
 | 
				
			||||||
 | 
					    "nodemon": "^3.1.9",
 | 
				
			||||||
 | 
					    "pm2": "^5.4.3",
 | 
				
			||||||
 | 
					    "rimraf": "^6.0.1",
 | 
				
			||||||
 | 
					    "rollup": "^4.34.9",
 | 
				
			||||||
 | 
					    "rollup-plugin-copy": "^3.5.0",
 | 
				
			||||||
 | 
					    "rollup-plugin-dts": "^6.1.1",
 | 
				
			||||||
 | 
					    "rollup-plugin-esbuild": "^6.2.1",
 | 
				
			||||||
 | 
					    "tape": "^5.9.0",
 | 
				
			||||||
 | 
					    "tsx": "^4.19.3",
 | 
				
			||||||
 | 
					    "typescript": "^5.8.2"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "pnpm": {}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										15
									
								
								src/renderer/assistant-center/pem/https-cert.pem
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/renderer/assistant-center/pem/https-cert.pem
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					-----BEGIN CERTIFICATE-----
 | 
				
			||||||
 | 
					MIICXTCCAcagAwIBAgIJHsP036vqWER/MA0GCSqGSIb3DQEBBQUAMF8xCjAIBgNV
 | 
				
			||||||
 | 
					BAMTASoxCzAJBgNVBAYTAkNOMREwDwYDVQQIEwhaaGVKaWFuZzERMA8GA1UEBxMI
 | 
				
			||||||
 | 
					SGFuZ3pob3UxETAPBgNVBAoTCEVudmlzaW9uMQswCQYDVQQLEwJJVDAeFw0yNTAz
 | 
				
			||||||
 | 
					MDcxNDIwMTJaFw0yNjAzMDcxNDIwMTJaMF8xCjAIBgNVBAMTASoxCzAJBgNVBAYT
 | 
				
			||||||
 | 
					AkNOMREwDwYDVQQIEwhaaGVKaWFuZzERMA8GA1UEBxMISGFuZ3pob3UxETAPBgNV
 | 
				
			||||||
 | 
					BAoTCEVudmlzaW9uMQswCQYDVQQLEwJJVDCBnzANBgkqhkiG9w0BAQEFAAOBjQAw
 | 
				
			||||||
 | 
					gYkCgYEAquA2XnwduVSJHvnTW4r5yodz/joTPUi+r8kS/KJyR/NQ5xovtDY2gJoO
 | 
				
			||||||
 | 
					nJk8qekcLKuofskIIu4HFsCE7AYBkQGaYmc+0cCQCmEpwivesbeMB0ydz+6NwLQn
 | 
				
			||||||
 | 
					32HVjtMtx3gUcywGdMntiQb/P9FIhtE132wOmW9PeSl0dx/nyrUCAwEAAaMhMB8w
 | 
				
			||||||
 | 
					HQYDVR0RBBYwFIIBKoIJbG9jYWxob3N0hwR/AAABMA0GCSqGSIb3DQEBBQUAA4GB
 | 
				
			||||||
 | 
					AJsjIZgb6iE4OTXoEDiBPmHM+byWs20K2eCvi79V9/vns90IroBQfGirIsovv923
 | 
				
			||||||
 | 
					SqjmdAFsZkRUbZvX99lBX0mmZK9KTE4K9YUm7bv+d8+fBPxAgNFSTRiSNBeNh0Lh
 | 
				
			||||||
 | 
					HdJUiI/tzIfI6RRg1pFDC1tOG083Cl/YElN879w3Iipi
 | 
				
			||||||
 | 
					-----END CERTIFICATE-----
 | 
				
			||||||
							
								
								
									
										15
									
								
								src/renderer/assistant-center/pem/https-key.pem
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/renderer/assistant-center/pem/https-key.pem
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					-----BEGIN RSA PRIVATE KEY-----
 | 
				
			||||||
 | 
					MIICXAIBAAKBgQCq4DZefB25VIke+dNbivnKh3P+OhM9SL6vyRL8onJH81DnGi+0
 | 
				
			||||||
 | 
					NjaAmg6cmTyp6Rwsq6h+yQgi7gcWwITsBgGRAZpiZz7RwJAKYSnCK96xt4wHTJ3P
 | 
				
			||||||
 | 
					7o3AtCffYdWO0y3HeBRzLAZ0ye2JBv8/0UiG0TXfbA6Zb095KXR3H+fKtQIDAQAB
 | 
				
			||||||
 | 
					AoGADDEbL/qjFEoXzoH8tpdf4zdu60CxhrneASTTmfrtNH0D1LlllfIYSWy0hi/Y
 | 
				
			||||||
 | 
					yDa9r+I/j2xAjF13XAQ4d66mBdjCRATLx/aL495o+e6NkIBEAgdP88hHm13F6gg+
 | 
				
			||||||
 | 
					h8iMixs5mkwU41sghnCYeBqlziKPi8fsoTmhK0VETFUtDQECQQDT0kZ7OCEVNcz0
 | 
				
			||||||
 | 
					LAUPO7ukeHAYnGYns+Q3F3kgonzHPGflClH5dsg0NS1HFQj6Ny2oyUupjNePOCJK
 | 
				
			||||||
 | 
					88zNehIlAkEAzoO9zrE+AoTPleVpe7TAUlZB1YMa7W1C5owjyEkv4TjIe8mpwWM/
 | 
				
			||||||
 | 
					9vVe+SGUnc6DZy6xkk5zWmA2w18SexXJUQJBAJQbcyy1EmzCMYyJOwBrw8g8biTH
 | 
				
			||||||
 | 
					NqaMIgZjY05uTtEAa6S6kpbbdyEKDZ6mFqDd9A8QsNbco9yAY3oE/i6uLAECQHOt
 | 
				
			||||||
 | 
					a9aphZiXmEfYl3uJxejZFEtrAtxXxY+qlCiOhllcG0Drt0DyPVQyIZ7fZoX2tbhI
 | 
				
			||||||
 | 
					eYMAmrDXEBXj3VBA5eECQCLGpQKqo06QwP2qZ9mEaPB9KvVcABo97b9Lf7VUqcJx
 | 
				
			||||||
 | 
					tFWRSlpeICpDQZHqX92nwoD/2fGCH3br3o94k1oyApI=
 | 
				
			||||||
 | 
					-----END RSA PRIVATE KEY-----
 | 
				
			||||||
@@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					import{u as h,r as o,j as e}from"./index-OAiiq-Mf.js";const m=()=>{const{config:s,getConfig:l,saveConfig:r}=h();o.useEffect(()=>{c(),l()},[]),o.useEffect(()=>{if(s.pageApi){const a=document.getElementById("pageApi");a.value=s.pageApi}},[s]);const c=()=>{const a=document.getElementById("particles"),p=20;if(a)for(let i=0;i<p;i++){const t=document.createElement("div");t.className="particle",t.innerHTML=`
 | 
				
			||||||
 | 
					                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
 | 
				
			||||||
 | 
					                        <path d="m12 3-1.912 5.813a2 2 0 0 1-1.275 1.275L3 12l5.813 1.912a2 2 0 0 1 1.275 1.275L12 21l1.912-5.813a2 2 0 0 1 1.275-1.275L21 12l-5.813-1.912a2 2 0 0 1-1.275-1.275L12 3Z"/>
 | 
				
			||||||
 | 
					                        <path d="M5 3v4"/>
 | 
				
			||||||
 | 
					                        <path d="M19 17v4"/>
 | 
				
			||||||
 | 
					                        <path d="M3 5h4"/>
 | 
				
			||||||
 | 
					                        <path d="M17 19h4"/>
 | 
				
			||||||
 | 
					                    </svg>
 | 
				
			||||||
 | 
					                `;const n=10+Math.random()*20;t.style.width=`${n}px`,t.style.height=`${n}px`,t.style.left=`${Math.random()*100}%`,t.style.top=`${Math.random()*100}%`,t.style.animationDuration=`${5+Math.random()*5}s`,t.style.animationDelay=`${Math.random()*5}s`,a.appendChild(t)}},d=()=>{const a=document.getElementById("pageApi");r(a.value)};return e.jsxs("div",{className:"h-full w-full p-4 pt-10",children:[e.jsx("div",{className:"particles",id:"particles"}),e.jsxs("div",{className:"container",children:[e.jsxs("div",{className:"header",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),e.jsx("h1",{children:"Page Enter Configuration"})]}),e.jsxs("div",{className:"form-container",children:[e.jsxs("form",{id:"configForm",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"pageApi",children:"Page Enter Api"}),e.jsx("input",{type:"text",id:"pageApi",placeholder:"Enter page api configuration"})]}),e.jsxs("button",{type:"submit",id:"save-button",onClick:d,children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"}),e.jsx("polyline",{points:"17 21 17 13 7 13 7 21"}),e.jsx("polyline",{points:"7 3 7 8 15 8"})]}),"Save Configuration"]})]}),e.jsx("div",{id:"save-result"})]})]})]})};export{m as default};
 | 
				
			||||||
@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					*{box-sizing:border-box}body{min-height:100vh;background:linear-gradient(135deg,#fef3c7,#fffbeb);font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;position:relative;overflow-x:hidden}.container{max-width:42rem;margin:0 auto}.header{display:flex;align-items:center;gap:.75rem;margin-bottom:2rem}.header svg{width:2rem;height:2rem;color:#d97706;animation:spin 8s linear infinite}.header h1{font-size:1.875rem;font-weight:700;color:#92400e}.form-container{background:#fffc;backdrop-filter:blur(8px);border-radius:1rem;box-shadow:0 4px 6px #d977061a;padding:2rem;transition:all .3s ease}.form-container:hover{box-shadow:0 8px 12px #d9770626}.form-group{margin-bottom:1.5rem}label{display:block;font-size:.875rem;font-weight:500;color:#92400e;margin-bottom:.25rem}input[type=text]{width:100%;padding:.75rem 1rem;border:1px solid #fbbf24;border-radius:.5rem;font-size:1rem;transition:all .2s}input[type=text]:focus{outline:none;border-color:#d97706;box-shadow:0 0 0 3px #d9770633}button{width:100%;display:flex;align-items:center;justify-content:center;gap:.5rem;background-color:#d97706;color:#fff;padding:.75rem 1.5rem;border:none;border-radius:.5rem;font-size:1rem;font-weight:500;cursor:pointer;transition:background-color .2s}button:hover{background-color:#b45309}.particles{position:absolute;inset:0;pointer-events:none;overflow:hidden}.particle{position:absolute;color:#fbbf24;opacity:.3;animation:float 5s ease-in-out infinite}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}@keyframes float{0%,to{transform:translateY(0) rotate(0)}50%{transform:translateY(-20px) rotate(10deg)}}
 | 
				
			||||||
@@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					import{c as v,y as d,a as f,q as N,r as u,u as C,j as n}from"./index-OAiiq-Mf.js";const $=v((t,i)=>({installedPackages:[],shopPackages:[],setInstalledPackages:s=>t({installedPackages:s}),setShopPackages:s=>t({shopPackages:s}),getInstalledPackages:async()=>{const s=await f.post({path:"shop",key:"list-installed"});return s.code===200&&t({installedPackages:s.data}),s.data},getShopPackages:async()=>{const s=await N.post({path:"app",key:"public-list"});return s.code===200&&t({shopPackages:s.data}),s.data},uninstallPackage:async s=>{const c=await f.post({path:"shop",key:"uninstall",data:{pkg:s}});c.code===200?(i().getInstalledPackages(),d.success("Package uninstalled successfully")):d.error(c.message||"Failed to uninstall package"),console.log("uninstallPackage",c)},installPackage:async s=>{const c=d.loading("Installing package..."),o=await f.post({path:"shop",key:"install",data:{pkg:s}});d.dismiss(c),o.code===200?(i().getInstalledPackages(),d.success("Package installed successfully")):d.error(o.message||"Failed to install package"),console.log("installPackage",o)}}));/**
 | 
				
			||||||
 | 
					 * @license lucide-react v0.479.0 - ISC
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This source code is licensed under the ISC license.
 | 
				
			||||||
 | 
					 * See the LICENSE file in the root directory of this source tree.
 | 
				
			||||||
 | 
					 */const I=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),x=(...t)=>t.filter((i,s,c)=>!!i&&i.trim()!==""&&c.indexOf(i)===s).join(" ").trim();/**
 | 
				
			||||||
 | 
					 * @license lucide-react v0.479.0 - ISC
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This source code is licensed under the ISC license.
 | 
				
			||||||
 | 
					 * See the LICENSE file in the root directory of this source tree.
 | 
				
			||||||
 | 
					 */var A={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
 | 
				
			||||||
 | 
					 * @license lucide-react v0.479.0 - ISC
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This source code is licensed under the ISC license.
 | 
				
			||||||
 | 
					 * See the LICENSE file in the root directory of this source tree.
 | 
				
			||||||
 | 
					 */const U=u.forwardRef(({color:t="currentColor",size:i=24,strokeWidth:s=2,absoluteStrokeWidth:c,className:o="",children:r,iconNode:h,...p},k)=>u.createElement("svg",{ref:k,...A,width:i,height:i,stroke:t,strokeWidth:c?Number(s)*24/Number(i):s,className:x("lucide",o),...p},[...h.map(([g,m])=>u.createElement(g,m)),...Array.isArray(r)?r:[r]]));/**
 | 
				
			||||||
 | 
					 * @license lucide-react v0.479.0 - ISC
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This source code is licensed under the ISC license.
 | 
				
			||||||
 | 
					 * See the LICENSE file in the root directory of this source tree.
 | 
				
			||||||
 | 
					 */const b=(t,i)=>{const s=u.forwardRef(({className:c,...o},r)=>u.createElement(U,{ref:r,iconNode:i,className:x(`lucide-${I(t)}`,c),...o}));return s.displayName=`${t}`,s};/**
 | 
				
			||||||
 | 
					 * @license lucide-react v0.479.0 - ISC
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This source code is licensed under the ISC license.
 | 
				
			||||||
 | 
					 * See the LICENSE file in the root directory of this source tree.
 | 
				
			||||||
 | 
					 */const S=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],q=b("Link2",S);/**
 | 
				
			||||||
 | 
					 * @license lucide-react v0.479.0 - ISC
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This source code is licensed under the ISC license.
 | 
				
			||||||
 | 
					 * See the LICENSE file in the root directory of this source tree.
 | 
				
			||||||
 | 
					 */const R=[["path",{d:"M21 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h6",key:"y09zxi"}],["path",{d:"m21 3-9 9",key:"mpx6sq"}],["path",{d:"M15 3h6v6",key:"1q9fwt"}]],E=b("SquareArrowOutUpRight",R),M=()=>{const{shopPackages:t,installedPackages:i,getInstalledPackages:s,getShopPackages:c,uninstallPackage:o,installPackage:r}=$(),{pageApi:h}=C();u.useEffect(()=>{s(),c()},[]);const p=e=>{const a=i.find(l=>l.user===e.user&&l.key===e.key);return a?a.version!==e.version?"update-available":"installed":"not-installed"},k=e=>{const a=t.find(l=>l.id===e);a&&r(a)},g=e=>{const a=t.find(l=>l.id===e);a&&r(a)},m=e=>{const a=t.find(l=>l.id===e);a&&r(a)},y=e=>{const a=t.find(l=>l.id===e);a&&o(a)},P=(e,a)=>{switch(e){case"not-installed":return n.jsx("button",{className:"button button-install",onClick:()=>k(a.id),children:"Install"});case"update-available":return n.jsx("button",{className:"button button-update",onClick:()=>g(a.id),children:"Update"});case"installed":return n.jsx("button",{className:"button button-reinstall",onClick:()=>m(a.id),children:"Reinstall"})}},w=e=>{const a="https://kevisual.silkyai.cn",l=`/${e.user}/${e.key}`;window.open(`${a}${l}`,"_blank")},j=e=>{if(!h)return;const a=h,l=`/${e.user}/${e.key}`;window.open(`${a}${l}`,"_blank")};return n.jsxs("div",{id:"app",children:[n.jsx("h1",{children:"Package Manager"}),n.jsx("div",{className:"package-list",children:t.map(e=>{const a=p(e),l=a!=="not-installed";return n.jsxs("div",{className:"package-card",children:[n.jsx("h2",{children:e.title}),n.jsx("p",{className:"description",children:e.description}),n.jsxs("div",{className:"package-info",children:[n.jsxs("span",{children:["Version: ",e.version]}),n.jsxs("span",{children:["User: ",e.user]})]}),n.jsxs("div",{className:"actions",children:[P(a,e),a!=="not-installed"&&n.jsx("button",{className:"button button-uninstall",onClick:()=>y(e.id),children:"Uninstall"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("div",{className:"cursor-pointer p-2 rounded-md bg-amber-500 text-white",children:n.jsx(E,{onClick:()=>w(e)})}),h&&l&&n.jsx("div",{className:"cursor-pointer p-2 rounded-md bg-amber-500 text-white",children:n.jsx(q,{onClick:()=>j(e)})})]})]})]},e.id)})})]})};export{M as PackageManager,M as default};
 | 
				
			||||||
@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					:root{font-family:Inter,system-ui,Avenir,Helvetica,Arial,sans-serif;line-height:1.5;font-weight:400;color-scheme:light dark;background-color:#fff8e1;color:#213547}body{margin:0;min-width:320px;min-height:100vh}#app{max-width:1280px;margin:0 auto;padding:2rem}h1{text-align:center;color:#ff8f00}.package-list{display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));gap:1rem;padding:1rem}.package-card{background:#fff;border-radius:8px;padding:1.5rem;box-shadow:0 2px 4px #ff8f001a;border:1px solid #ffe0b2}.package-card h2{margin:0 0 .5rem;color:#f57c00}.package-card .description{color:#666;margin-bottom:1rem;font-size:.9rem;display:-webkit-box;-webkit-line-clamp:4;-webkit-box-orient:vertical;overflow:hidden;text-overflow:ellipsis;line-height:1.5;max-height:6em}.package-info{display:flex;justify-content:space-between;align-items:center;margin-bottom:1rem;font-size:.9rem;color:#666}.actions{display:flex;gap:.5rem}.button{padding:.5rem 1rem;border-radius:4px;border:none;cursor:pointer;font-weight:500;transition:background-color .2s}.button-install{background-color:#ffa000;color:#fff}.button-update{background-color:#ff8f00;color:#fff}.button-reinstall{background-color:#ffb300;color:#fff}.button-uninstall{background-color:#ff6f00;color:#fff}.button:hover{opacity:.9}.button:disabled{background-color:#ffe0b2;cursor:not-allowed}.error-message{text-align:center;color:#ff6f00;padding:2rem;background:#fff;border-radius:8px;box-shadow:0 2px 4px #ff8f001a;grid-column:1 / -1}
 | 
				
			||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					<!doctype html>
 | 
				
			||||||
 | 
					<html lang="en">
 | 
				
			||||||
 | 
					  <head>
 | 
				
			||||||
 | 
					    <meta charset="UTF-8" />
 | 
				
			||||||
 | 
					    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 | 
				
			||||||
 | 
					    <title>Assistant Base App</title>
 | 
				
			||||||
 | 
					    <script type="module" crossorigin src="/root/assistant-base-app/assets/index-OAiiq-Mf.js"></script>
 | 
				
			||||||
 | 
					    <link rel="stylesheet" crossorigin href="/root/assistant-base-app/assets/index-CyYNi-ro.css">
 | 
				
			||||||
 | 
					  </head>
 | 
				
			||||||
 | 
					  <body>
 | 
				
			||||||
 | 
					    <div id="root"></div>
 | 
				
			||||||
 | 
					  </body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
							
								
								
									
										6
									
								
								src/renderer/download-services.mjs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								src/renderer/download-services.mjs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					const name = 'assistant-center-0.0.1.tgz';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const command = `ev micro-app download -i ${name} -o release/assistant-center.tgz -x assistant-center`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					console.log('command:\n')
 | 
				
			||||||
 | 
					console.log(command);
 | 
				
			||||||
							
								
								
									
										21
									
								
								src/renderer/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/renderer/index.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					<!DOCTYPE html>
 | 
				
			||||||
 | 
					<html>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<head>
 | 
				
			||||||
 | 
					  <meta charset="UTF-8" />
 | 
				
			||||||
 | 
					  <title>Config Page</title>
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					  <h1>配置完成后重启</h1>
 | 
				
			||||||
 | 
					  <button id="restart">重启</button>
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script>
 | 
				
			||||||
 | 
					  const restart = document.getElementById('restart');
 | 
				
			||||||
 | 
					  restart.addEventListener('click', () => {
 | 
				
			||||||
 | 
					    window.electron.ipcRenderer.invoke('relunch');
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								src/renderer/release/assistant-center.tgz
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/renderer/release/assistant-center.tgz
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							@@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					import{u as h,r as o,j as e}from"./index-OAiiq-Mf.js";const m=()=>{const{config:s,getConfig:l,saveConfig:r}=h();o.useEffect(()=>{c(),l()},[]),o.useEffect(()=>{if(s.pageApi){const a=document.getElementById("pageApi");a.value=s.pageApi}},[s]);const c=()=>{const a=document.getElementById("particles"),p=20;if(a)for(let i=0;i<p;i++){const t=document.createElement("div");t.className="particle",t.innerHTML=`
 | 
				
			||||||
 | 
					                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
 | 
				
			||||||
 | 
					                        <path d="m12 3-1.912 5.813a2 2 0 0 1-1.275 1.275L3 12l5.813 1.912a2 2 0 0 1 1.275 1.275L12 21l1.912-5.813a2 2 0 0 1 1.275-1.275L21 12l-5.813-1.912a2 2 0 0 1-1.275-1.275L12 3Z"/>
 | 
				
			||||||
 | 
					                        <path d="M5 3v4"/>
 | 
				
			||||||
 | 
					                        <path d="M19 17v4"/>
 | 
				
			||||||
 | 
					                        <path d="M3 5h4"/>
 | 
				
			||||||
 | 
					                        <path d="M17 19h4"/>
 | 
				
			||||||
 | 
					                    </svg>
 | 
				
			||||||
 | 
					                `;const n=10+Math.random()*20;t.style.width=`${n}px`,t.style.height=`${n}px`,t.style.left=`${Math.random()*100}%`,t.style.top=`${Math.random()*100}%`,t.style.animationDuration=`${5+Math.random()*5}s`,t.style.animationDelay=`${Math.random()*5}s`,a.appendChild(t)}},d=()=>{const a=document.getElementById("pageApi");r(a.value)};return e.jsxs("div",{className:"h-full w-full p-4 pt-10",children:[e.jsx("div",{className:"particles",id:"particles"}),e.jsxs("div",{className:"container",children:[e.jsxs("div",{className:"header",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),e.jsx("h1",{children:"Page Enter Configuration"})]}),e.jsxs("div",{className:"form-container",children:[e.jsxs("form",{id:"configForm",children:[e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"pageApi",children:"Page Enter Api"}),e.jsx("input",{type:"text",id:"pageApi",placeholder:"Enter page api configuration"})]}),e.jsxs("button",{type:"submit",id:"save-button",onClick:d,children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"}),e.jsx("polyline",{points:"17 21 17 13 7 13 7 21"}),e.jsx("polyline",{points:"7 3 7 8 15 8"})]}),"Save Configuration"]})]}),e.jsx("div",{id:"save-result"})]})]})]})};export{m as default};
 | 
				
			||||||
@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					*{box-sizing:border-box}body{min-height:100vh;background:linear-gradient(135deg,#fef3c7,#fffbeb);font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;position:relative;overflow-x:hidden}.container{max-width:42rem;margin:0 auto}.header{display:flex;align-items:center;gap:.75rem;margin-bottom:2rem}.header svg{width:2rem;height:2rem;color:#d97706;animation:spin 8s linear infinite}.header h1{font-size:1.875rem;font-weight:700;color:#92400e}.form-container{background:#fffc;backdrop-filter:blur(8px);border-radius:1rem;box-shadow:0 4px 6px #d977061a;padding:2rem;transition:all .3s ease}.form-container:hover{box-shadow:0 8px 12px #d9770626}.form-group{margin-bottom:1.5rem}label{display:block;font-size:.875rem;font-weight:500;color:#92400e;margin-bottom:.25rem}input[type=text]{width:100%;padding:.75rem 1rem;border:1px solid #fbbf24;border-radius:.5rem;font-size:1rem;transition:all .2s}input[type=text]:focus{outline:none;border-color:#d97706;box-shadow:0 0 0 3px #d9770633}button{width:100%;display:flex;align-items:center;justify-content:center;gap:.5rem;background-color:#d97706;color:#fff;padding:.75rem 1.5rem;border:none;border-radius:.5rem;font-size:1rem;font-weight:500;cursor:pointer;transition:background-color .2s}button:hover{background-color:#b45309}.particles{position:absolute;inset:0;pointer-events:none;overflow:hidden}.particle{position:absolute;color:#fbbf24;opacity:.3;animation:float 5s ease-in-out infinite}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}@keyframes float{0%,to{transform:translateY(0) rotate(0)}50%{transform:translateY(-20px) rotate(10deg)}}
 | 
				
			||||||
@@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					import{c as v,y as d,a as f,q as N,r as u,u as C,j as n}from"./index-OAiiq-Mf.js";const $=v((t,i)=>({installedPackages:[],shopPackages:[],setInstalledPackages:s=>t({installedPackages:s}),setShopPackages:s=>t({shopPackages:s}),getInstalledPackages:async()=>{const s=await f.post({path:"shop",key:"list-installed"});return s.code===200&&t({installedPackages:s.data}),s.data},getShopPackages:async()=>{const s=await N.post({path:"app",key:"public-list"});return s.code===200&&t({shopPackages:s.data}),s.data},uninstallPackage:async s=>{const c=await f.post({path:"shop",key:"uninstall",data:{pkg:s}});c.code===200?(i().getInstalledPackages(),d.success("Package uninstalled successfully")):d.error(c.message||"Failed to uninstall package"),console.log("uninstallPackage",c)},installPackage:async s=>{const c=d.loading("Installing package..."),o=await f.post({path:"shop",key:"install",data:{pkg:s}});d.dismiss(c),o.code===200?(i().getInstalledPackages(),d.success("Package installed successfully")):d.error(o.message||"Failed to install package"),console.log("installPackage",o)}}));/**
 | 
				
			||||||
 | 
					 * @license lucide-react v0.479.0 - ISC
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This source code is licensed under the ISC license.
 | 
				
			||||||
 | 
					 * See the LICENSE file in the root directory of this source tree.
 | 
				
			||||||
 | 
					 */const I=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),x=(...t)=>t.filter((i,s,c)=>!!i&&i.trim()!==""&&c.indexOf(i)===s).join(" ").trim();/**
 | 
				
			||||||
 | 
					 * @license lucide-react v0.479.0 - ISC
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This source code is licensed under the ISC license.
 | 
				
			||||||
 | 
					 * See the LICENSE file in the root directory of this source tree.
 | 
				
			||||||
 | 
					 */var A={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
 | 
				
			||||||
 | 
					 * @license lucide-react v0.479.0 - ISC
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This source code is licensed under the ISC license.
 | 
				
			||||||
 | 
					 * See the LICENSE file in the root directory of this source tree.
 | 
				
			||||||
 | 
					 */const U=u.forwardRef(({color:t="currentColor",size:i=24,strokeWidth:s=2,absoluteStrokeWidth:c,className:o="",children:r,iconNode:h,...p},k)=>u.createElement("svg",{ref:k,...A,width:i,height:i,stroke:t,strokeWidth:c?Number(s)*24/Number(i):s,className:x("lucide",o),...p},[...h.map(([g,m])=>u.createElement(g,m)),...Array.isArray(r)?r:[r]]));/**
 | 
				
			||||||
 | 
					 * @license lucide-react v0.479.0 - ISC
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This source code is licensed under the ISC license.
 | 
				
			||||||
 | 
					 * See the LICENSE file in the root directory of this source tree.
 | 
				
			||||||
 | 
					 */const b=(t,i)=>{const s=u.forwardRef(({className:c,...o},r)=>u.createElement(U,{ref:r,iconNode:i,className:x(`lucide-${I(t)}`,c),...o}));return s.displayName=`${t}`,s};/**
 | 
				
			||||||
 | 
					 * @license lucide-react v0.479.0 - ISC
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This source code is licensed under the ISC license.
 | 
				
			||||||
 | 
					 * See the LICENSE file in the root directory of this source tree.
 | 
				
			||||||
 | 
					 */const S=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],q=b("Link2",S);/**
 | 
				
			||||||
 | 
					 * @license lucide-react v0.479.0 - ISC
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This source code is licensed under the ISC license.
 | 
				
			||||||
 | 
					 * See the LICENSE file in the root directory of this source tree.
 | 
				
			||||||
 | 
					 */const R=[["path",{d:"M21 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h6",key:"y09zxi"}],["path",{d:"m21 3-9 9",key:"mpx6sq"}],["path",{d:"M15 3h6v6",key:"1q9fwt"}]],E=b("SquareArrowOutUpRight",R),M=()=>{const{shopPackages:t,installedPackages:i,getInstalledPackages:s,getShopPackages:c,uninstallPackage:o,installPackage:r}=$(),{pageApi:h}=C();u.useEffect(()=>{s(),c()},[]);const p=e=>{const a=i.find(l=>l.user===e.user&&l.key===e.key);return a?a.version!==e.version?"update-available":"installed":"not-installed"},k=e=>{const a=t.find(l=>l.id===e);a&&r(a)},g=e=>{const a=t.find(l=>l.id===e);a&&r(a)},m=e=>{const a=t.find(l=>l.id===e);a&&r(a)},y=e=>{const a=t.find(l=>l.id===e);a&&o(a)},P=(e,a)=>{switch(e){case"not-installed":return n.jsx("button",{className:"button button-install",onClick:()=>k(a.id),children:"Install"});case"update-available":return n.jsx("button",{className:"button button-update",onClick:()=>g(a.id),children:"Update"});case"installed":return n.jsx("button",{className:"button button-reinstall",onClick:()=>m(a.id),children:"Reinstall"})}},w=e=>{const a="https://kevisual.silkyai.cn",l=`/${e.user}/${e.key}`;window.open(`${a}${l}`,"_blank")},j=e=>{if(!h)return;const a=h,l=`/${e.user}/${e.key}`;window.open(`${a}${l}`,"_blank")};return n.jsxs("div",{id:"app",children:[n.jsx("h1",{children:"Package Manager"}),n.jsx("div",{className:"package-list",children:t.map(e=>{const a=p(e),l=a!=="not-installed";return n.jsxs("div",{className:"package-card",children:[n.jsx("h2",{children:e.title}),n.jsx("p",{className:"description",children:e.description}),n.jsxs("div",{className:"package-info",children:[n.jsxs("span",{children:["Version: ",e.version]}),n.jsxs("span",{children:["User: ",e.user]})]}),n.jsxs("div",{className:"actions",children:[P(a,e),a!=="not-installed"&&n.jsx("button",{className:"button button-uninstall",onClick:()=>y(e.id),children:"Uninstall"}),n.jsxs("div",{className:"flex gap-2",children:[n.jsx("div",{className:"cursor-pointer p-2 rounded-md bg-amber-500 text-white",children:n.jsx(E,{onClick:()=>w(e)})}),h&&l&&n.jsx("div",{className:"cursor-pointer p-2 rounded-md bg-amber-500 text-white",children:n.jsx(q,{onClick:()=>j(e)})})]})]})]},e.id)})})]})};export{M as PackageManager,M as default};
 | 
				
			||||||
@@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					:root{font-family:Inter,system-ui,Avenir,Helvetica,Arial,sans-serif;line-height:1.5;font-weight:400;color-scheme:light dark;background-color:#fff8e1;color:#213547}body{margin:0;min-width:320px;min-height:100vh}#app{max-width:1280px;margin:0 auto;padding:2rem}h1{text-align:center;color:#ff8f00}.package-list{display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));gap:1rem;padding:1rem}.package-card{background:#fff;border-radius:8px;padding:1.5rem;box-shadow:0 2px 4px #ff8f001a;border:1px solid #ffe0b2}.package-card h2{margin:0 0 .5rem;color:#f57c00}.package-card .description{color:#666;margin-bottom:1rem;font-size:.9rem;display:-webkit-box;-webkit-line-clamp:4;-webkit-box-orient:vertical;overflow:hidden;text-overflow:ellipsis;line-height:1.5;max-height:6em}.package-info{display:flex;justify-content:space-between;align-items:center;margin-bottom:1rem;font-size:.9rem;color:#666}.actions{display:flex;gap:.5rem}.button{padding:.5rem 1rem;border-radius:4px;border:none;cursor:pointer;font-weight:500;transition:background-color .2s}.button-install{background-color:#ffa000;color:#fff}.button-update{background-color:#ff8f00;color:#fff}.button-reinstall{background-color:#ffb300;color:#fff}.button-uninstall{background-color:#ff6f00;color:#fff}.button:hover{opacity:.9}.button:disabled{background-color:#ffe0b2;cursor:not-allowed}.error-message{text-align:center;color:#ff6f00;padding:2rem;background:#fff;border-radius:8px;box-shadow:0 2px 4px #ff8f001a;grid-column:1 / -1}
 | 
				
			||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										13
									
								
								src/renderer/root/assistant-base-app/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/renderer/root/assistant-base-app/index.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
				
			|||||||
 | 
					<!doctype html>
 | 
				
			||||||
 | 
					<html lang="en">
 | 
				
			||||||
 | 
					  <head>
 | 
				
			||||||
 | 
					    <meta charset="UTF-8" />
 | 
				
			||||||
 | 
					    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 | 
				
			||||||
 | 
					    <title>Assistant Base App</title>
 | 
				
			||||||
 | 
					    <script type="module" crossorigin src="/root/assistant-base-app/assets/index-OAiiq-Mf.js"></script>
 | 
				
			||||||
 | 
					    <link rel="stylesheet" crossorigin href="/root/assistant-base-app/assets/index-CyYNi-ro.css">
 | 
				
			||||||
 | 
					  </head>
 | 
				
			||||||
 | 
					  <body>
 | 
				
			||||||
 | 
					    <div id="root"></div>
 | 
				
			||||||
 | 
					  </body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
							
								
								
									
										3
									
								
								src/scripts/run-save-files.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/scripts/run-save-files.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					import { installApp, demoData } from '../main/proxy/install';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					installApp(demoData);
 | 
				
			||||||
							
								
								
									
										30
									
								
								tsconfig.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								tsconfig.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "compilerOptions": {
 | 
				
			||||||
 | 
					    "module": "commonjs",
 | 
				
			||||||
 | 
					    "noImplicitAny": false,
 | 
				
			||||||
 | 
					    "sourceMap": false,
 | 
				
			||||||
 | 
					    "outDir": "app-dist",
 | 
				
			||||||
 | 
					    "rootDir": "src",
 | 
				
			||||||
 | 
					    "baseUrl": ".",
 | 
				
			||||||
 | 
					    "paths": {
 | 
				
			||||||
 | 
					      "@/*": [
 | 
				
			||||||
 | 
					        "./src/*"
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "allowJs": true,
 | 
				
			||||||
 | 
					    "skipLibCheck": true,
 | 
				
			||||||
 | 
					    "esModuleInterop": true,
 | 
				
			||||||
 | 
					    "allowSyntheticDefaultImports": true,
 | 
				
			||||||
 | 
					    "strict": false,
 | 
				
			||||||
 | 
					    "forceConsistentCasingInFileNames": true,
 | 
				
			||||||
 | 
					    "moduleResolution": "Node",
 | 
				
			||||||
 | 
					    "isolatedModules": false,
 | 
				
			||||||
 | 
					    "resolveJsonModule": true,
 | 
				
			||||||
 | 
					    "types": []
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "include": [
 | 
				
			||||||
 | 
					    "src/**/*"
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "exclude": [
 | 
				
			||||||
 | 
					  ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										48
									
								
								vite.config.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								vite.config.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,48 @@
 | 
				
			|||||||
 | 
					// vite.config.ts
 | 
				
			||||||
 | 
					import path from 'path';
 | 
				
			||||||
 | 
					import { defineConfig } from 'vite';
 | 
				
			||||||
 | 
					import electron from 'vite-plugin-electron';
 | 
				
			||||||
 | 
					import { viteStaticCopy } from 'vite-plugin-static-copy';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default defineConfig({
 | 
				
			||||||
 | 
					  plugins: [
 | 
				
			||||||
 | 
					    electron({
 | 
				
			||||||
 | 
					      entry: {
 | 
				
			||||||
 | 
					        main: 'src/main/index.ts', // 主进程入口文件
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      vite: {
 | 
				
			||||||
 | 
					        resolve: {
 | 
				
			||||||
 | 
					          alias: {
 | 
				
			||||||
 | 
					            '@': path.resolve(__dirname, './src'),
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        build: {
 | 
				
			||||||
 | 
					          rollupOptions: {
 | 
				
			||||||
 | 
					            input: {
 | 
				
			||||||
 | 
					              main: 'src/main/index.ts', // 主进程入口文件
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            output: {
 | 
				
			||||||
 | 
					              format: 'esm', // 设置输出格式为 ESM
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          outDir: 'dist/main', // 主进程输出目录
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    }),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    viteStaticCopy({
 | 
				
			||||||
 | 
					      targets: [
 | 
				
			||||||
 | 
					        { src: 'src/renderer', dest: '' },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          src: 'src/main/preload.js',
 | 
				
			||||||
 | 
					          dest: 'main',
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
 | 
					    }),
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  define: {},
 | 
				
			||||||
 | 
					  build: {
 | 
				
			||||||
 | 
					    outDir: 'dist', // 渲染进程输出目录
 | 
				
			||||||
 | 
					    rollupOptions: {},
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
		Reference in New Issue
	
	Block a user