diff --git a/.env.development b/.env.development index 825915f..db62f58 100644 --- a/.env.development +++ b/.env.development @@ -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 = '.' #开发环境 diff --git a/.env.production b/.env.production index 61787de..9f463c7 100644 --- a/.env.production +++ b/.env.production @@ -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 = '.' #生产环境 diff --git a/.env.test b/.env.test deleted file mode 100644 index 4c8b009..0000000 --- a/.env.test +++ /dev/null @@ -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' diff --git a/.env.xy b/.env.xy new file mode 100644 index 0000000..45335d0 --- /dev/null +++ b/.env.xy @@ -0,0 +1,6 @@ +#基础API 绝对的 +VITE_BASE_URL_API = 'https://meeting-api.23544.com/pc' +#当前IP 相对的 +VITE_BASE_CURRENT_API = '.' +#测试环境 +VITE_ENV = 'xy' diff --git a/build/start-xy.ico b/build/start-xy.ico new file mode 100644 index 0000000..d9a0f80 Binary files /dev/null and b/build/start-xy.ico differ diff --git a/config/build.json b/config/build.json new file mode 100644 index 0000000..df6adec --- /dev/null +++ b/config/build.json @@ -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 + } +} \ No newline at end of file diff --git a/config/xy.json b/config/xy.json new file mode 100644 index 0000000..643c891 --- /dev/null +++ b/config/xy.json @@ -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 + } +} \ No newline at end of file diff --git a/forge.config.js b/forge.config.js deleted file mode 100644 index a47c38b..0000000 --- a/forge.config.js +++ /dev/null @@ -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, - }), - ], -}; diff --git a/index.html b/index.html index e3ab5f4..1061ae2 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ - 智汇享 + diff --git a/main.js b/main.js index f6b030b..8ff0046 100644 --- a/main.js +++ b/main.js @@ -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 diff --git a/package.json b/package.json index 52a3a82..4b1f24b 100644 --- a/package.json +++ b/package.json @@ -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 - } } -} +} \ No newline at end of file diff --git a/preload.js b/preload.js index 2435a1d..55a0c47 100644 --- a/preload.js +++ b/preload.js @@ -87,6 +87,10 @@ window.electron = { isOpenWindows: (callback) => { ipcRenderer.on('isOpenWindows', callback) }, + // 设置环境变量 + setEnv: (str) => { + ipcRenderer.invoke('setEnv', str) + }, // 通知下载最新的包 onDownload: (type) => { ipcRenderer.invoke('updateDownload', type) diff --git a/src/App.tsx b/src/App.tsx index ada9605..7e28ca6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -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({ diff --git a/src/assets/icon53.png b/src/assets/icon53.png new file mode 100644 index 0000000..ff50e9e Binary files /dev/null and b/src/assets/icon53.png differ diff --git a/src/assets/icon54.png b/src/assets/icon54.png new file mode 100644 index 0000000..d9a0f80 Binary files /dev/null and b/src/assets/icon54.png differ diff --git a/src/components/UpdateModal/index.tsx b/src/components/UpdateModal/index.tsx index e97819b..261327d 100644 --- a/src/components/UpdateModal/index.tsx +++ b/src/components/UpdateModal/index.tsx @@ -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()) diff --git a/src/page/Login/index.tsx b/src/page/Login/index.tsx index 6ac5ca2..e722f49 100644 --- a/src/page/Login/index.tsx +++ b/src/page/Login/index.tsx @@ -173,7 +173,7 @@ const Login: React.FC = () => { <>
- +
diff --git a/src/render.d.ts b/src/render.d.ts index bc2be79..95e2967 100644 --- a/src/render.d.ts +++ b/src/render.d.ts @@ -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; isVisible: () => Promise; setRegistry: (uuid: string) => any; diff --git a/src/utils/package/imageUrl.ts b/src/utils/package/imageUrl.ts index 3b8e6dc..79651f7 100644 --- a/src/utils/package/imageUrl.ts +++ b/src/utils/package/imageUrl.ts @@ -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 } \ No newline at end of file diff --git a/src/utils/package/public.ts b/src/utils/package/public.ts index 82f5aba..2e49f9d 100644 --- a/src/utils/package/public.ts +++ b/src/utils/package/public.ts @@ -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 '智汇享' + } } \ No newline at end of file diff --git a/src/utils/package/update.js b/src/utils/package/update.js new file mode 100644 index 0000000..c03486b --- /dev/null +++ b/src/utils/package/update.js @@ -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' + } + } +} \ No newline at end of file