Merge pull request 'yangjie' (#37) from yangjie into master

Reviewed-on: #37
This commit is contained in:
yangqiang 2024-11-26 10:15:05 +08:00
commit a1519a3ad4
21 changed files with 198 additions and 149 deletions

View File

@ -1,6 +1,5 @@
#基础API 绝对的
VITE_BASE_URL_API = 'http://192.168.2.9:5192'
VITE_BASE_URL_DRAW_API = 'http://192.168.2.9:6555'
#当前IP 相对的
VITE_BASE_CURRENT_API = '.'
#开发环境

View File

@ -1,6 +1,5 @@
#基础API 绝对的
VITE_BASE_URL_API = 'https://meeting-api.23544.com/pc'
VITE_BASE_URL_DRAW_API = 'http://192.168.2.9:6555'
#当前IP 相对的
VITE_BASE_CURRENT_API = '.'
#生产环境

View File

@ -1,7 +0,0 @@
#基础API 绝对的
VITE_BASE_URL_API = 'http://192.168.2.9:5192'
VITE_BASE_URL_DRAW_API = 'http://192.168.2.9:6555'
#当前IP 相对的
VITE_BASE_CURRENT_API = '.'
#测试环境
VITE_ENV = 'test'

6
.env.xy Normal file
View File

@ -0,0 +1,6 @@
#基础API 绝对的
VITE_BASE_URL_API = 'https://meeting-api.23544.com/pc'
#当前IP 相对的
VITE_BASE_CURRENT_API = '.'
#测试环境
VITE_ENV = 'xy'

BIN
build/start-xy.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

56
config/build.json Normal file
View File

@ -0,0 +1,56 @@
{
"appId": "agora.io.ElectronApiExample",
"asar": true,
"asarUnpack": [
"node_modules/agora-electron-sdk"
],
"buildDependenciesFromSource": true,
"compression": "normal",
"productName": "智汇享",
"publish": [
{
"provider": "generic",
"url": "https://meeting-api.23544.com/meeting/update"
}
],
"files": [
"!*.log"
],
"win": {
"icon": "build/start.ico",
"requestedExecutionLevel": "highestAvailable",
"target": [
{
"target": "nsis",
"arch": [
"ia32"
]
}
]
},
"directories": {
"output": "electron"
},
"extraResources": [
{
"from": "src/assets/virtualBackground",
"to": "images",
"filter": [
"**/*"
]
}
],
"nsis": {
"oneClick": false,
"installerIcon": "build/install.ico",
"uninstallerIcon": "build/install.ico",
"installerHeaderIcon": "build/install.ico",
"allowToChangeInstallationDirectory": true,
"createDesktopShortcut": true,
"createStartMenuShortcut": true,
"deleteAppDataOnUninstall": true,
"shortcutName": "智汇享",
"allowElevation": true,
"perMachine": true
}
}

56
config/xy.json Normal file
View File

@ -0,0 +1,56 @@
{
"appId": "agora.io.ElectronApiExample",
"asar": true,
"asarUnpack": [
"node_modules/agora-electron-sdk"
],
"buildDependenciesFromSource": true,
"compression": "normal",
"productName": "湖北襄阳四中教研平台",
"publish": [
{
"provider": "generic",
"url": "https://meeting-api.23544.com/meeting/xysz"
}
],
"files": [
"!*.log"
],
"win": {
"icon": "build/start-xy.ico",
"requestedExecutionLevel": "highestAvailable",
"target": [
{
"target": "nsis",
"arch": [
"ia32"
]
}
]
},
"directories": {
"output": "electron"
},
"extraResources": [
{
"from": "src/assets/virtualBackground",
"to": "images",
"filter": [
"**/*"
]
}
],
"nsis": {
"oneClick": false,
"installerIcon": "build/start-xy.ico",
"uninstallerIcon": "build/start-xy.ico",
"installerHeaderIcon": "build/start-xy.ico",
"allowToChangeInstallationDirectory": true,
"createDesktopShortcut": true,
"createStartMenuShortcut": true,
"deleteAppDataOnUninstall": true,
"shortcutName": "湖北襄阳四中教研平台",
"allowElevation": true,
"perMachine": true
}
}

View File

@ -1,58 +0,0 @@
const { FusesPlugin } = require('@electron-forge/plugin-fuses');
const { FuseV1Options, FuseVersion } = require('@electron/fuses');
module.exports = {
packagerConfig: {
"name": "MyElectronApp", // 应用程序的名称
"files": [],
"productName": "My Electron App", // 产品名称(用于生成安装包的名称)
// "icon": "path/to/icon.png", // 应用程序的图标路径
"out": "build/", // 输出目录的路径
"overwrite": true, // 是否覆盖已存在的打包文件
"asar": true, // 是否使用asar打包格式
"version": "0.0.1", // 应用程序版本号
// "copyright": "Copyright © 2023", // 版权信息
// "ignore": [ // 不需要打包的文件和文件夹的路径列表
// ".git",
// ".vscode",
// "node_modules/.cache",
// "src"
// ],
},
rebuildConfig: {},
makers: [
{
name: '@electron-forge/maker-squirrel',
config: {}
},
{
name: '@electron-forge/maker-zip',
platforms: ['darwin'],
},
{
name: '@electron-forge/maker-deb',
config: {},
},
{
name: '@electron-forge/maker-rpm',
config: {},
},
],
plugins: [
{
name: '@electron-forge/plugin-auto-unpack-natives',
config: {},
},
// Fuses are used to enable/disable various Electron functionality
// at package time, before code signing the application
new FusesPlugin({
version: FuseVersion.V1,
[FuseV1Options.RunAsNode]: false,
[FuseV1Options.EnableCookieEncryption]: true,
[FuseV1Options.EnableNodeOptionsEnvironmentVariable]: false,
[FuseV1Options.EnableNodeCliInspectArguments]: false,
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
[FuseV1Options.OnlyLoadAppFromAsar]: true,
}),
],
};

View File

@ -8,7 +8,7 @@
<meta http-equiv="Content-Security-Policy" content="script-src 'self'">
<!-- <meta http-equiv="Content-Security-Policy"
content="script-src 'self' https://www.google-analytics.com; style-src 'self' https://animate.style"> -->
<title>智汇享</title>
<title></title>
</head>
<body>

31
main.js
View File

@ -11,6 +11,7 @@ const {
desktopCapturer,
} = require('electron');
const path = require('node:path')
const updateJs = require('./src/utils/package/update')
const fs = require('fs');
const Registry = require('winreg');
const { autoUpdater, CancellationToken } = require('electron-updater');
@ -23,6 +24,7 @@ let isMaximized = false;
let env;
let regKey;
let connection = null;
let envStr;
class AppWindow extends BrowserWindow {
constructor(config) {
@ -42,7 +44,7 @@ class AppWindow extends BrowserWindow {
};
const finalConfig = { ...basicConfig, ...config };
super(finalConfig);
if (env === 'development') {
if (envStr === 'development') {
// 开发
this.loadURL('http://localhost:3000');
} else {
@ -59,7 +61,7 @@ function quit() {
}
function createTray() {
const iconPath = `${__dirname}/src/assets/icon.png`;
const iconPath = `${__dirname}/src/assets/${updateJs.getIcon(envStr)}.png`;
const trayIcon = nativeImage.createFromPath(iconPath);
const tray = new Tray(trayIcon);
const contextMenu = Menu.buildFromTemplate([
@ -82,7 +84,7 @@ function createTray() {
// icon: iconPath,
},
]);
tray.setToolTip('智汇享');
tray.setToolTip(updateJs.getTitle(envStr));
tray.setContextMenu(contextMenu);
tray.on('click', () => {
mainWindow.webContents.send('isOpenWindows');
@ -107,11 +109,6 @@ app.on('ready', () => {
autoUpdater.updateConfigPath = path.join('latest.yml')
}
createWindow()
updateHandle() // 检查更新
setInterval(() => {
updateHandle() // 每一小时检查更新
}, 1000 * 60 * 60)
createTray()
regKey = new Registry({
hive: Registry.HKCU,
key: '\\Software\\ZhiHuiXiang'
@ -127,11 +124,9 @@ app.on('ready', () => {
}
// 监听f12打开控制台
mainWindow.webContents.on('before-input-event', (event, input) => {
// if (env === 'development') {
if (input.key === 'F12') {
mainWindow.webContents.openDevTools()
}
// }
});
// 监听移动
mainWindow.on('move', () => {
@ -144,6 +139,14 @@ app.on('ready', () => {
isMaximized = true;
}
});
ipcMain.handle('setEnv', (event, str) => {
envStr = str;
updateHandle() // 检查更新
setInterval(() => {
updateHandle() // 每一小时检查更新
}, 1000 * 60 * 60)
createTray()
});
// socket
ipcMain.handle('startSignalr', (event, user) => {
startSignalr(user)
@ -518,7 +521,7 @@ app.on('ready', () => {
width: config.width,
height: config.height,
})
if (env === 'development') {
if (envStr === 'development') {
// 开发
child.loadURL(config.url)
} else {
@ -535,11 +538,9 @@ app.on('ready', () => {
windowOperation(config)
})
child.webContents.on('before-input-event', (event, input) => {
// if (env === 'development') {
if (input.key === 'F12') {
child.webContents.openDevTools()
}
// }
});
});
// 关闭子窗口
@ -627,7 +628,7 @@ function updateHandle() {
updateAva: '检测到新版本,正在下载……',
updateNotAva: '已经是最新版本,不用更新'
}
autoUpdater.setFeedURL('https://meeting-api.23544.com/meeting/update')
autoUpdater.setFeedURL(updateJs.getUpdateUrl(envStr))
autoUpdater.autoDownload = false // 不自动下载安装包
autoUpdater.autoInstallOnAppQuit = false // 不自动安装
autoUpdater.on('error', function (error) {
@ -719,7 +720,7 @@ function mainWindowCenter() {
const startSignalr = async (user) => {
connection = new signalR.HubConnectionBuilder()
.withUrl(`${env === 'development' ? 'http://192.168.2.9:5192' : 'https://meeting-api.23544.com/pc'}/session-manage`, {
.withUrl(`${envStr === 'development' ? 'http://192.168.2.9:5192' : 'https://meeting-api.23544.com/pc'}/session-manage`, {
skipNegotiation: true,
transport: signalR.HttpTransportType.WebSockets,
accessTokenFactory: () => user.token

View File

@ -7,15 +7,15 @@
"description": "智汇享",
"scripts": {
"dev": "concurrently \"electron . --env=development\" \"cross-env BROWSER=none vite\"",
"test": "concurrently \"electron . --env=test\" \"cross-env BROWSER=none vite\"",
"prod": "concurrently \"electron . --env=production\" \"cross-env BROWSER=none vite\"",
"xy": "concurrently \"electron . --env=xy\" \"cross-env BROWSER=none vite\"",
"build": "vite build --mode development",
"build:test": "vite build --mode test",
"build:prod": "vite build --mode production",
"build:xy": "vite build --mode xy",
"preview": "vite preview",
"build:dev-win": "vite build --mode development & electron-builder -w",
"build:test-win": "vite build --mode test & electron-builder -w",
"build:prod-win": "vite build --mode production & electron-builder -w"
"build:dev-win": "vite build --mode development & electron-builder -w --config=./config/build.json",
"build:prod-win": "vite build --mode production & electron-builder -w --config=./config/build.json",
"build:prod-win-xy": "vite build --mode xy & electron-builder -w --config=./config/xy.json"
},
"agora_electron": {
"platform": "win32",
@ -57,61 +57,5 @@
"typescript": "^4.5.4",
"vite": "^2.8.0",
"vite-plugin-resolve": "^2.5.1"
},
"build": {
"appId": "agora.io.ElectronApiExample",
"asar": true,
"asarUnpack": [
"node_modules/agora-electron-sdk"
],
"buildDependenciesFromSource": true,
"compression": "normal",
"productName": "智汇享",
"publish": [
{
"provider": "generic",
"url": "https://meeting-api.23544.com/meeting/update"
}
],
"files": [
"!*.log"
],
"win": {
"icon": "build/start.ico",
"requestedExecutionLevel": "highestAvailable",
"target": [
{
"target": "nsis",
"arch": [
"ia32"
]
}
]
},
"directories": {
"output": "electron"
},
"extraResources": [
{
"from": "src/assets/virtualBackground",
"to": "images",
"filter": [
"**/*"
]
}
],
"nsis": {
"oneClick": false,
"installerIcon": "build/install.ico",
"uninstallerIcon": "build/install.ico",
"installerHeaderIcon": "build/install.ico",
"allowToChangeInstallationDirectory": true,
"createDesktopShortcut": true,
"createStartMenuShortcut": true,
"deleteAppDataOnUninstall": true,
"shortcutName": "智汇享",
"allowElevation": true,
"perMachine": true
}
}
}
}

View File

@ -87,6 +87,10 @@ window.electron = {
isOpenWindows: (callback) => {
ipcRenderer.on('isOpenWindows', callback)
},
// 设置环境变量
setEnv: (str) => {
ipcRenderer.invoke('setEnv', str)
},
// 通知下载最新的包
onDownload: (type) => {
ipcRenderer.invoke('updateDownload', type)

View File

@ -21,7 +21,7 @@ import UserListWindow from "@/page/Meeting/UserListWindow";
import ChatSmallWindow from "@/page/Meeting/ChatSmallWindow";
import ChatBigWindow from "@/page/Meeting/ChatBigWindow";
import NoticeWindow from "@/page/Meeting/NoticeWindow";
import { getKeyOpenChildWindow, setKeyOpenChildWindow, storageSeeting } from "./utils/package/public";
import { getKeyOpenChildWindow, getTitle, setKeyOpenChildWindow, storageSeeting } from "./utils/package/public";
const fs = require('fs').promises;
const { exec } = require('child_process');
const App: React.FC = () => {
@ -41,6 +41,7 @@ const App: React.FC = () => {
useEffect(() => {
let userInfo = JSON.parse(storage.getItem('user') as string)
let loginInfo = JSON.parse(storage.getItem('login') as string)
window.electron.setEnv(import.meta.env.VITE_ENV);
if (userInfo && !userInfo.isAnonymous) {
if (loginInfo && loginInfo.isAutoLogin) {
PostLogin({
@ -172,6 +173,7 @@ const App: React.FC = () => {
event.preventDefault();
}
});
document.getElementsByTagName('title')[0].innerText = getTitle(import.meta.env.VITE_ENV)
}, [])
const handleResize = (): void => {
setWindowSize({

BIN
src/assets/icon53.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

BIN
src/assets/icon54.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

View File

@ -1,5 +1,6 @@
import styles from '@/components/UpdateModal/index.module.scss'
import ImageUrl from '@/utils/package/imageUrl';
import { getUpdateUrl } from '@/utils/package/public';
import { Button, Flex, Modal, Progress } from 'antd';
import { forwardRef, useImperativeHandle, useState } from "react";
@ -22,7 +23,7 @@ const UpdateModal = forwardRef((props: any, ref: any) => {
const [updateContent, setUpdateContent] = useState('') // 版本更新内容
function getContent() {
fetch(`https://meeting-api.23544.com/meeting/update/update.txt?t=${+new Date()}`) // 配置服务器地址
fetch(`${getUpdateUrl(import.meta.env.VITE_ENV)}/update.txt?t=${+new Date()}`) // 配置服务器地址
.then(async response => {
if (response.status === 200) {
return setUpdateContent(await response.text())

View File

@ -173,7 +173,7 @@ const Login: React.FC = () => {
<>
<div className={styles.login}>
<div className={styles.loginBg}>
<img src={ImageUrl.icon1} alt="" />
<img src={import.meta.env.VITE_ENV === 'xy' ? ImageUrl.icon53 : ImageUrl.icon1} alt="" />
</div>
<div className={styles.loginContent}>
<div>

1
src/render.d.ts vendored
View File

@ -24,6 +24,7 @@ export interface IElectronAPI {
downFile: (callBack: Function) => void;
quitAndInstall: (callBack: Function) => void;
isOpenWindows: (callBack: Function) => void;
setEnv: (str: string) => any;
getVersion: () => Promise<string>;
isVisible: () => Promise<string>;
setRegistry: (uuid: string) => any;

View File

@ -81,6 +81,7 @@ import virtualBackground5 from '@/assets/virtualBackground/5.png'
import virtualBackground6 from '@/assets/virtualBackground/6.png'
import icon52 from '@/assets/icon52.png'
import icon52Select from '@/assets/icon52-select.png'
import icon53 from '@/assets/icon53.png'
export default {
loading,
icon,
@ -164,5 +165,6 @@ export default {
virtualBackground5,
virtualBackground6,
icon52,
icon52Select
icon52Select,
icon53
}

View File

@ -53,4 +53,21 @@ export const storageSeeting: any = {
color: '0xFFFFFF', // 纯色
sourceIndex: '', // 背景图下标
},
}
export const getUpdateUrl = (env: string) => {
switch (env) {
case 'xy':
return 'https://meeting-api.23544.com/meeting/xysz'
default:
return 'https://meeting-api.23544.com/meeting/update'
}
}
export const getTitle = (env: string) => {
switch (env) {
case 'xy':
return '湖北襄阳四中教研平台'
default:
return '智汇享'
}
}

View File

@ -0,0 +1,26 @@
module.exports = {
getUpdateUrl(env) {
switch (env) {
case 'xy':
return 'https://meeting-api.23544.com/meeting/xysz'
default:
return 'https://meeting-api.23544.com/meeting/update'
}
},
getTitle(env) {
switch (env) {
case 'xy':
return '湖北襄阳四中教研平台'
default:
return '智汇享'
}
},
getIcon(env) {
switch (env) {
case 'xy':
return 'icon54'
default:
return 'icon'
}
}
}