diff --git a/.github/workflows/desktop-server-api.apps.yml b/.github/workflows/desktop-server-api.apps.yml index ed9d259eb..abfe2b389 100644 --- a/.github/workflows/desktop-server-api.apps.yml +++ b/.github/workflows/desktop-server-api.apps.yml @@ -222,6 +222,11 @@ jobs: DESKTOP_API_SERVER_APP_DESCRIPTION: 'Ever Teams API Server' DESKTOP_API_SERVER_APP_ID: 'com.ever.everteamsapiserver' + - name: Print environment variable names + run: | + echo "Environment Variable Names:" + printenv | cut -d= -f1 + - name: Build API Server App run: 'yarn build:gauzy-api-server:windows:release:gh' env: diff --git a/.github/workflows/desktop.apps.yml b/.github/workflows/desktop.apps.yml index 35f2c029d..feb3b29db 100644 --- a/.github/workflows/desktop.apps.yml +++ b/.github/workflows/desktop.apps.yml @@ -222,6 +222,11 @@ jobs: DESKTOP_TIMER_APP_DESCRIPTION: 'Ever Teams Desktop' DESKTOP_TIMER_APP_ID: 'com.ever.everteamsdesktop' + - name: Print environment variable names + run: | + echo "Environment Variable Names:" + printenv | cut -d= -f1 + - name: Build Desktop Timer App run: 'yarn build:desktop-timer:windows:release:gh' env: diff --git a/apps/server-web/.erb/configs/webpack.config.renderer.dev.ts b/apps/server-web/.erb/configs/webpack.config.renderer.dev.ts index a6ca87e90..b78d23ac3 100644 --- a/apps/server-web/.erb/configs/webpack.config.renderer.dev.ts +++ b/apps/server-web/.erb/configs/webpack.config.renderer.dev.ts @@ -80,8 +80,9 @@ const configuration: webpack.Configuration = { }, { test: /\.s?css$/, - use: ['style-loader', 'css-loader', 'sass-loader'], + use: ['style-loader', 'css-loader', 'sass-loader', 'postcss-loader'], exclude: /\.module\.s?(c|a)ss$/, + include: [webpackPaths.srcRendererPath], }, // Fonts { diff --git a/apps/server-web/.erb/configs/webpack.config.renderer.prod.ts b/apps/server-web/.erb/configs/webpack.config.renderer.prod.ts index 3cebf30d4..2425f6b16 100644 --- a/apps/server-web/.erb/configs/webpack.config.renderer.prod.ts +++ b/apps/server-web/.erb/configs/webpack.config.renderer.prod.ts @@ -56,7 +56,7 @@ const configuration: webpack.Configuration = { }, { test: /\.s?(a|c)ss$/, - use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'], + use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader', 'postcss-loader'], exclude: /\.module\.s?(c|a)ss$/, }, // Fonts diff --git a/apps/server-web/assets/icon.icns b/apps/server-web/assets/icon.icns index c2213ce89..d7bd9522e 100644 Binary files a/apps/server-web/assets/icon.icns and b/apps/server-web/assets/icon.icns differ diff --git a/apps/server-web/assets/icon.ico b/apps/server-web/assets/icon.ico index 98948ea68..346ae4440 100644 Binary files a/apps/server-web/assets/icon.ico and b/apps/server-web/assets/icon.ico differ diff --git a/apps/server-web/assets/icon.png b/apps/server-web/assets/icon.png old mode 100755 new mode 100644 index 755a6e51d..d7bd9522e Binary files a/apps/server-web/assets/icon.png and b/apps/server-web/assets/icon.png differ diff --git a/apps/server-web/assets/icons/gauzy/icon.png b/apps/server-web/assets/icons/gauzy/icon.png new file mode 100644 index 000000000..faa960171 Binary files /dev/null and b/apps/server-web/assets/icons/gauzy/icon.png differ diff --git a/apps/server-web/assets/icons/gauzy/icon@1.25x.png b/apps/server-web/assets/icons/gauzy/icon@1.25x.png new file mode 100644 index 000000000..46ea6d876 Binary files /dev/null and b/apps/server-web/assets/icons/gauzy/icon@1.25x.png differ diff --git a/apps/server-web/assets/icons/gauzy/icon@1.33x.png b/apps/server-web/assets/icons/gauzy/icon@1.33x.png new file mode 100644 index 000000000..bc73df996 Binary files /dev/null and b/apps/server-web/assets/icons/gauzy/icon@1.33x.png differ diff --git a/apps/server-web/assets/icons/gauzy/icon@1.4x.png b/apps/server-web/assets/icons/gauzy/icon@1.4x.png new file mode 100644 index 000000000..19ee320f0 Binary files /dev/null and b/apps/server-web/assets/icons/gauzy/icon@1.4x.png differ diff --git a/apps/server-web/assets/icons/gauzy/icon@1.5x.png b/apps/server-web/assets/icons/gauzy/icon@1.5x.png new file mode 100644 index 000000000..5faa32626 Binary files /dev/null and b/apps/server-web/assets/icons/gauzy/icon@1.5x.png differ diff --git a/apps/server-web/assets/icons/gauzy/icon@1.8x.png b/apps/server-web/assets/icons/gauzy/icon@1.8x.png new file mode 100644 index 000000000..0f97c50d5 Binary files /dev/null and b/apps/server-web/assets/icons/gauzy/icon@1.8x.png differ diff --git a/apps/server-web/assets/icons/gauzy/icon@2.5x.png b/apps/server-web/assets/icons/gauzy/icon@2.5x.png new file mode 100644 index 000000000..aeb2dadc3 Binary files /dev/null and b/apps/server-web/assets/icons/gauzy/icon@2.5x.png differ diff --git a/apps/server-web/assets/icons/gauzy/icon@2x.png b/apps/server-web/assets/icons/gauzy/icon@2x.png new file mode 100644 index 000000000..9d27eebae Binary files /dev/null and b/apps/server-web/assets/icons/gauzy/icon@2x.png differ diff --git a/apps/server-web/assets/icons/gauzy/icon@3x.png b/apps/server-web/assets/icons/gauzy/icon@3x.png new file mode 100644 index 000000000..999c00be1 Binary files /dev/null and b/apps/server-web/assets/icons/gauzy/icon@3x.png differ diff --git a/apps/server-web/assets/icons/gauzy/icon@4x.png b/apps/server-web/assets/icons/gauzy/icon@4x.png new file mode 100644 index 000000000..ff6c4fdec Binary files /dev/null and b/apps/server-web/assets/icons/gauzy/icon@4x.png differ diff --git a/apps/server-web/assets/icons/gauzy/icon@5x.png b/apps/server-web/assets/icons/gauzy/icon@5x.png new file mode 100644 index 000000000..da278ab3f Binary files /dev/null and b/apps/server-web/assets/icons/gauzy/icon@5x.png differ diff --git a/apps/server-web/assets/linux/128x128.png b/apps/server-web/assets/linux/128x128.png new file mode 100644 index 000000000..55a3fc4da Binary files /dev/null and b/apps/server-web/assets/linux/128x128.png differ diff --git a/apps/server-web/assets/linux/16x16.png b/apps/server-web/assets/linux/16x16.png new file mode 100644 index 000000000..faa960171 Binary files /dev/null and b/apps/server-web/assets/linux/16x16.png differ diff --git a/apps/server-web/assets/linux/256x256.png b/apps/server-web/assets/linux/256x256.png new file mode 100644 index 000000000..d449f44a8 Binary files /dev/null and b/apps/server-web/assets/linux/256x256.png differ diff --git a/apps/server-web/assets/linux/32x32.png b/apps/server-web/assets/linux/32x32.png new file mode 100644 index 000000000..9d27eebae Binary files /dev/null and b/apps/server-web/assets/linux/32x32.png differ diff --git a/apps/server-web/assets/linux/512x512.png b/apps/server-web/assets/linux/512x512.png new file mode 100644 index 000000000..d7bd9522e Binary files /dev/null and b/apps/server-web/assets/linux/512x512.png differ diff --git a/apps/server-web/assets/linux/64x64.png b/apps/server-web/assets/linux/64x64.png new file mode 100644 index 000000000..ff6c4fdec Binary files /dev/null and b/apps/server-web/assets/linux/64x64.png differ diff --git a/apps/server-web/package.json b/apps/server-web/package.json index fa95261b3..20cce9612 100644 --- a/apps/server-web/package.json +++ b/apps/server-web/package.json @@ -1,36 +1,40 @@ { "name": "@ever-teams/server-web", - "version": "0.1.0", + "version": "0.1.0", "description": "Ever Teams Web Server", - "license": "AGPL-3.0", + "license": "AGPL-3.0", "homepage": "https://ever.team", "repository": { - "type": "git", - "url": "https://github.com/ever-co/ever-teams.git" - }, - "bugs": { - "url": "https://github.com/ever-co/ever-teams/issues" - }, + "type": "git", + "url": "https://github.com/ever-co/ever-teams.git" + }, + "bugs": { + "url": "https://github.com/ever-co/ever-teams/issues" + }, "private": true, "author": { - "name": "Ever Co. LTD", - "email": "ever@ever.co", - "url": "https://ever.co" - }, + "name": "Ever Co. LTD", + "email": "ever@ever.co", + "url": "https://ever.co" + }, "main": "./src/main/main.ts", "scripts": { - "build": "concurrently \"npm run build:main\" \"npm run build:renderer\"", + "build": "concurrently \"npm run build:main\" \"npm run build:renderer\"", "build:dll": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.renderer.dev.dll.ts", "build:main": "cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.main.prod.ts", "build:renderer": "cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.renderer.prod.ts", "postinstall": "ts-node .erb/scripts/check-native-dep.js && electron-builder install-app-deps && npm run build:dll", "lint": "cross-env NODE_ENV=development eslint . --ext .js,.jsx,.ts,.tsx", - "package": "ts-node ./.erb/scripts/clean.js dist && npm run build && electron-builder build --publish never && npm run build:dll", + "pack:mac": "electron-builder build --mac --publish never && npm run build:dll", + "pack:win": "electron-builder build --win --publish never && npm run build:dll", + "pack:linux": "electron-builder build --linux --publish never && npm run build:dll", + "package": "electron-builder build --publish never && npm run build:dll", "rebuild": "electron-rebuild --parallel --types prod,dev,optional --module-dir release/app", "start": "ts-node ./.erb/scripts/check-port-in-use.js && npm run start:renderer", "start:main": "cross-env NODE_ENV=development electronmon electronmon.js", "start:preload": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.preload.dev.ts", "start:renderer": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack serve --config ./.erb/configs/webpack.config.renderer.dev.ts", + "prepare:electron": "ts-node ./.erb/scripts/clean.js dist", "test": "jest" }, "dependencies": { @@ -40,12 +44,12 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-router-dom": "^6.16.0", - "electron-store": "^8.1.0" + "electron-store": "^8.1.0" }, "devDependencies": { "electron": "28.1.0", - "electron-builder": "^24.6.4", - "@electron/notarize": "^2.1.0", + "electron-builder": "^24.6.4", + "@electron/notarize": "^2.1.0", "@electron/rebuild": "^3.3.0", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.11", "@teamsupercell/typings-for-css-modules-loader": "^2.5.2", @@ -101,7 +105,8 @@ "webpack-bundle-analyzer": "^4.9.1", "webpack-cli": "^5.1.4", "webpack-dev-server": "^4.15.1", - "webpack-merge": "^5.9.0" + "webpack-merge": "^5.9.0", + "postcss-loader": "^8.1.1" }, "prettier": { "singleQuote": true, @@ -150,104 +155,107 @@ } }, "engines": { - "node": ">=16.0.0", - "yarn": ">=1.13.0" - }, - "build": { + "node": ">=16.0.0", + "yarn": ">=1.13.0" + }, + "build": { "appId": "co.ever.teamswebserver", "artifactName": "${name}-${version}.${ext}", - "productName": "Ever Teams Web Server", + "productName": "Ever Teams Web Server", "copyright": "Copyright © 2024-Present. Ever Co. LTD", + "asar": true, + "asarUnpack": "**\\*.{node,dll}", + "files": [ + "dist", + "node_modules", + "package.json" + ], + "afterSign": ".erb/scripts/notarize.js", + "mac": { + "category": "public.app-category.developer-tools", + "target": [ + "zip", + "dmg" + ], + "asarUnpack": "**/*.node", + "artifactName": "${name}-${version}.${ext}", + "type": "distribution", + "hardenedRuntime": true, + "gatekeeperAssess": false, + "entitlements": "assets/entitlements.mac.plist", + "entitlementsInherit": "assets/entitlements.mac.plist" + }, "dmg": { - "sign": false - }, - "asar": true, - "asarUnpack": "**\\*.{node,dll}", - "files": [ - "dist", - "node_modules", - "package.json" - ], - "afterSign": ".erb/scripts/notarize.js", - "mac": { - "category": "public.app-category.developer-tools", - "target": [ - "zip", - "dmg" - ], - "asarUnpack": "**/*.node", - "artifactName": "${name}-${version}.${ext}", - "type": "distribution", - "hardenedRuntime": true, - "gatekeeperAssess": false, - "entitlements": "assets/entitlements.mac.plist", - "entitlementsInherit": "assets/entitlements.mac.plist" - }, - "dmg": { - "contents": [ - { - "x": 130, - "y": 220 - }, - { - "x": 410, - "y": 220, - "type": "link", - "path": "/Applications" - } - ] - }, - "win": { - "publisherName": "Ever", - "target": [ - { - "target": "nsis", - "arch": [ - "x64" - ] - } - ], - "verifyUpdateCodeSignature": false, - "requestedExecutionLevel": "requireAdministrator" - }, - "linux": { - "target": [ - "AppImage", - "deb", - "tar.gz" - ], - "executableName": "ever-teams-web-server", - "artifactName": "${name}-${version}.${ext}", - "synopsis": "Server", - "category": "Development" - }, - "directories": { - "app": "release/app", - "buildResources": "assets", - "output": "release/build" - }, - "extraResources": [ - "./assets/**" - ], - "publish": [{ - "provider": "github", - "repo": "ever-teams-web-server", - "releaseType": "release" - }, - { - "provider": "spaces", - "name": "ever", - "region": "sfo3", - "path": "/ever-teams-web-server", - "acl": "public-read" - } - ] - }, - "electronmon": { - "patterns": [ - "!**/**", - "src/main/**" - ], - "logLevel": "quiet" - } + "icon": "icon.icns", + "sign": false, + "contents": [ + { + "x": 130, + "y": 220 + }, + { + "x": 410, + "y": 220, + "type": "link", + "path": "/Applications" + } + ] + }, + "win": { + "icon": "icon.ico", + "publisherName": "Ever", + "target": [ + { + "target": "nsis", + "arch": [ + "x64" + ] + } + ], + "verifyUpdateCodeSignature": false, + "requestedExecutionLevel": "requireAdministrator" + }, + "linux": { + "icon": "linux", + "target": [ + "AppImage", + "deb", + "tar.gz" + ], + "executableName": "ever-teams-web-server", + "artifactName": "${name}-${version}.${ext}", + "synopsis": "Server", + "category": "Development" + }, + "directories": { + "app": "release/app", + "buildResources": "assets", + "output": "release/build" + }, + "extraResources": [ + "./assets/**", + "./release/app/dist/standalone/**" + ], + "publish": [ + { + "provider": "github", + "repo": "ever-teams-web-server", + "releaseType": "release" + }, + { + "provider": "spaces", + "name": "ever", + "region": "sfo3", + "path": "/ever-teams-web-server", + "acl": "public-read" + } + ] + }, + "electronmon": { + "patterns": [ + "!**/**", + "src/main/**" + ], + "logLevel": "quiet" + } } diff --git a/apps/server-web/postcss.config.js b/apps/server-web/postcss.config.js new file mode 100644 index 000000000..3ea9307f4 --- /dev/null +++ b/apps/server-web/postcss.config.js @@ -0,0 +1,3 @@ +module.exports = { + plugins: [require('tailwindcss'), require('autoprefixer')], +}; diff --git a/apps/server-web/release/app/package-lock.json b/apps/server-web/release/app/package-lock.json index 351a9dab9..07dfc2c51 100644 --- a/apps/server-web/release/app/package-lock.json +++ b/apps/server-web/release/app/package-lock.json @@ -1,14 +1,14 @@ { - "name": "electron-react-boilerplate", - "version": "4.6.0", + "name": "ever-teams-server-web", + "version": "0.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "electron-react-boilerplate", - "version": "4.6.0", + "name": "ever-teams-server-web", + "version": "0.1.0", "hasInstallScript": true, - "license": "MIT" + "license": "AGPL-3.0" } } } diff --git a/apps/server-web/release/app/package.json b/apps/server-web/release/app/package.json index de2f9ac9c..2d7d161d7 100644 --- a/apps/server-web/release/app/package.json +++ b/apps/server-web/release/app/package.json @@ -1,12 +1,12 @@ { - "name": "electron-react-boilerplate", - "version": "4.6.0", - "description": "A foundation for scalable desktop apps", - "license": "MIT", + "name": "ever-teams-server-web", + "version": "0.1.0", + "description": "Ever Teams Web Server", + "license": "AGPL-3.0", "author": { - "name": "Electron React Boilerplate Maintainers", - "email": "electronreactboilerplate@gmail.com", - "url": "https://github.com/electron-react-boilerplate" + "name": "Ever Co. LTD", + "email": "ever@ever.co", + "url": "https://ever.co" }, "main": "./dist/main/main.js", "scripts": { diff --git a/apps/server-web/src/main/helpers/constant.ts b/apps/server-web/src/main/helpers/constant.ts index 3090c1df5..2bae02a0d 100644 --- a/apps/server-web/src/main/helpers/constant.ts +++ b/apps/server-web/src/main/helpers/constant.ts @@ -2,5 +2,6 @@ export const EventLists = { webServerStarted: 'WEB_SERVER_STARTED', webServerStopped: 'WEB_SERVER_STOPPED', webServerStart: 'WEB_SERVER_START', - webServerStop: 'WEB_SERVER_STOP' + webServerStop: 'WEB_SERVER_STOP', + gotoSetting: 'GO_TO_SETTING' } diff --git a/apps/server-web/src/main/main.ts b/apps/server-web/src/main/main.ts index e73ceb147..cc7bedaac 100644 --- a/apps/server-web/src/main/main.ts +++ b/apps/server-web/src/main/main.ts @@ -1,10 +1,11 @@ import path from 'path' -import { app, ipcMain, Tray, dialog } from 'electron'; +import { app, ipcMain, Tray, dialog, BrowserWindow, shell } from 'electron'; import { DesktopServer } from './helpers/desktop-server'; import { LocalStore } from './helpers/services/libs/desktop-store'; import { EventEmitter } from 'events'; import { defaultTrayMenuItem, _initTray, updateTrayMenu } from './tray'; import { EventLists } from './helpers/constant'; +import { resolveHtmlPath } from './util'; const eventEmiter = new EventEmitter(); @@ -19,10 +20,17 @@ const isProd = process.env.NODE_ENV === 'production'; let isServerRun: boolean; let tray:Tray; +let settingWindow: BrowserWindow | null = null; const trayMenuItems = defaultTrayMenuItem(eventEmiter); +const RESOURCES_PATH = app.isPackaged + ? path.join(process.resourcesPath, 'assets/icons/gauzy') + : path.join(__dirname, '../../assets/icons/gauzy'); +const getAssetPath = (...paths: string[]): string => { + return path.join(RESOURCES_PATH, ...paths); +}; console.log(__dirname); @@ -33,7 +41,7 @@ if (isProd) { } const resourceDir = { - webServer: !isPack ? '../../release/app/dist' : '..', + webServer: !isPack ? '../../release/app/dist' : '.', resources: '../resources' }; const resourcesFiles = { @@ -41,6 +49,65 @@ const resourcesFiles = { iconTray: 'icons/tray/icon.png' } +const devServerPath = path.join(__dirname, resourceDir.webServer, resourcesFiles.webServer); +const serverPath = isPack ? path.join(process.resourcesPath, 'release', 'app', 'dist', resourcesFiles.webServer) : devServerPath; + + + +if (process.env.NODE_ENV === 'production') { + const sourceMapSupport = require('source-map-support'); + sourceMapSupport.install(); +} + +const isDebug = + process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true'; + +if (isDebug) { + require('electron-debug')(); +} + +const installExtensions = async () => { + const installer = require('electron-devtools-installer'); + const forceDownload = !!process.env.UPGRADE_EXTENSIONS; + const extensions = ['REACT_DEVELOPER_TOOLS']; + + return installer + .default( + extensions.map((name) => installer[name]), + forceDownload, + ) + .catch(console.log); +}; + + +const createWindow = async () => { + if (isDebug) { + await installExtensions(); + } + + settingWindow = new BrowserWindow({ + show: false, + width: 1024, + height: 728, + icon: getAssetPath('icon.png'), + maximizable: false, + resizable: false, + webPreferences: { + preload: app.isPackaged + ? path.join(__dirname, 'preload.js') + : path.join(__dirname, '../../.erb/dll/preload.js'), + }, + }); + const url = resolveHtmlPath('index.html', 'setting'); + settingWindow.loadURL(url); + + + settingWindow.on('closed', () => { + settingWindow = null; + }); + +}; + const runServer = async () => { console.log('Run the Server...'); try { @@ -48,7 +115,7 @@ const runServer = async () => { // Instantiate API and UI servers await desktopServer.start( - { api: path.join(__dirname, resourceDir.webServer, resourcesFiles.webServer) }, + { api: serverPath }, envVal, undefined, signal @@ -73,7 +140,7 @@ const getEnvApi = () => { const onInitApplication = () => { LocalStore.setDefaultServerConfig(); // check and set default config - tray = _initTray(resourceDir, resourcesFiles, trayMenuItems); + tray = _initTray(trayMenuItems, getAssetPath('icon.png')); eventEmiter.on(EventLists.webServerStart, async () => { updateTrayMenu('SERVER_START', { enabled: false }, eventEmiter, tray, trayMenuItems); isServerRun = true; @@ -100,36 +167,38 @@ const onInitApplication = () => { updateTrayMenu('SERVER_STATUS', { label: 'Status: Stopped' }, eventEmiter, tray, trayMenuItems); isServerRun = false; }) + + eventEmiter.on(EventLists.gotoSetting, async () => { + if (!settingWindow) { + await createWindow() + } + const serverSetting = LocalStore.getStore('config'); + console.log('setting data', serverSetting); + settingWindow?.show(); + settingWindow?.webContents.once('did-finish-load', () => { + settingWindow?.webContents.send('load_setting', serverSetting); + }) + }) } (async () => { await app.whenReady() onInitApplication(); - // const mainWindow = createWindow('main', { - // width: 1000, - // height: 600, - // webPreferences: { - // preload: path.join(__dirname, 'preload.js'), - // }, - // }) - - // if (isProd) { - // await mainWindow.loadURL('app://./home') - // } else { - // const port = process.argv[2] - // await mainWindow.loadURL(`http://localhost:${port}/home`) - // mainWindow.webContents.openDevTools() - // } })() app.on('window-all-closed', () => { - app.quit() + // e.preventDefault() + // app.quit() }) ipcMain.on('message', async (event, arg) => { event.reply('message', `${arg} World!`) }) +ipcMain.on('save_setting', (event, arg) => { + LocalStore.updateConfigSetting(arg); +}) + app.on('before-quit', async (e) => { console.log('Before Quit'); @@ -154,3 +223,9 @@ app.on('before-quit', async (e) => { app.exit(0); } }); + +app.on('activate', () => { + // On macOS it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + // if (mainWindow === null) createWindow(); +}); diff --git a/apps/server-web/src/main/preload.ts b/apps/server-web/src/main/preload.ts index 7f8f10ca0..9133a7922 100644 --- a/apps/server-web/src/main/preload.ts +++ b/apps/server-web/src/main/preload.ts @@ -1,20 +1,29 @@ -import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron' +// Disable no-unused-vars, broken for spread args +/* eslint no-unused-vars: off */ +import { contextBridge, ipcRenderer, IpcRendererEvent } from 'electron'; -const handler = { - send(channel: string, value: unknown) { - ipcRenderer.send(channel, value) - }, - on(channel: string, callback: (...args: unknown[]) => void) { - const subscription = (_event: IpcRendererEvent, ...args: unknown[]) => - callback(...args) - ipcRenderer.on(channel, subscription) +export type Channels = 'ipc-example'; + +const electronHandler = { + ipcRenderer: { + sendMessage(channel: Channels, ...args: unknown[]) { + ipcRenderer.send(channel, ...args); + }, + on(channel: Channels, func: (...args: unknown[]) => void) { + const subscription = (_event: IpcRendererEvent, ...args: unknown[]) => + func(...args); + ipcRenderer.on(channel, subscription); - return () => { - ipcRenderer.removeListener(channel, subscription) - } + return () => { + ipcRenderer.removeListener(channel, subscription); + }; + }, + once(channel: Channels, func: (...args: unknown[]) => void) { + ipcRenderer.once(channel, (_event, ...args) => func(...args)); + }, }, -} +}; -contextBridge.exposeInMainWorld('ipc', handler) +contextBridge.exposeInMainWorld('electron', electronHandler); -export type IpcHandler = typeof handler +export type ElectronHandler = typeof electronHandler; diff --git a/apps/server-web/src/main/tray.ts b/apps/server-web/src/main/tray.ts index 861a65154..b5d0d54c3 100644 --- a/apps/server-web/src/main/tray.ts +++ b/apps/server-web/src/main/tray.ts @@ -3,10 +3,9 @@ import path from 'path'; import { EventEmitter } from 'events'; import { EventLists } from './helpers/constant'; -export const _initTray = (resourceDir: any, resourcesFiles: any, contextMenu:any): Tray => { - const iconPath = path.join(__dirname, resourceDir.resources, resourcesFiles.iconTray); - console.log(iconPath) - const iconNativePath: NativeImage = nativeImage.createFromPath(iconPath); +export const _initTray = (contextMenu:any, icon:string): Tray => { + + const iconNativePath: NativeImage = nativeImage.createFromPath(icon); iconNativePath.resize({ width: 16, height: 16 }) const tray = new Tray(iconNativePath); tray.setContextMenu(Menu.buildFromTemplate(contextMenu)); @@ -29,6 +28,7 @@ export const defaultTrayMenuItem = (eventEmitter: EventEmitter) => { { id: 'SERVER_STOP', label: 'Stop', + enabled: false, async click() { eventEmitter.emit(EventLists.webServerStop); } @@ -37,7 +37,7 @@ export const defaultTrayMenuItem = (eventEmitter: EventEmitter) => { id: 'APP_SETTING', label: 'Settings', async click() { - console.log('settings') + eventEmitter.emit(EventLists.gotoSetting); } }, { diff --git a/apps/server-web/src/main/util.ts b/apps/server-web/src/main/util.ts index 7775eda37..512e67035 100644 --- a/apps/server-web/src/main/util.ts +++ b/apps/server-web/src/main/util.ts @@ -1,13 +1,10 @@ /* eslint import/prefer-default-export: off */ -import { URL } from 'url'; import path from 'path'; -export function resolveHtmlPath(htmlFileName: string) { +export function resolveHtmlPath(htmlFileName: string, hash: string) { if (process.env.NODE_ENV === 'development') { const port = process.env.PORT || 1212; - const url = new URL(`http://localhost:${port}`); - url.pathname = htmlFileName; - return url.href; + return `http://localhost:${port}#/${hash}`; } - return `file://${path.resolve(__dirname, '../renderer/', htmlFileName)}`; + return `file://${path.resolve(__dirname, '../renderer/', `${htmlFileName}#/${hash}`)}`; } diff --git a/apps/server-web/src/renderer/App.css b/apps/server-web/src/renderer/App.css index 616d9a48a..9bb37ee65 100644 --- a/apps/server-web/src/renderer/App.css +++ b/apps/server-web/src/renderer/App.css @@ -1,62 +1,4 @@ -/* - * @NOTE: Prepend a `~` to css file paths that are in your node_modules - * See https://github.com/webpack-contrib/sass-loader#imports - */ -body { - position: relative; - color: white; - height: 100vh; - background: linear-gradient( - 200.96deg, - #fedc2a -29.09%, - #dd5789 51.77%, - #7a2c9e 129.35% - ); - font-family: sans-serif; - overflow-y: hidden; - display: flex; - justify-content: center; - align-items: center; -} -button { - background-color: white; - padding: 10px 20px; - border-radius: 10px; - border: none; - appearance: none; - font-size: 1.3rem; - box-shadow: 0px 8px 28px -6px rgba(24, 39, 75, 0.12), - 0px 18px 88px -4px rgba(24, 39, 75, 0.14); - transition: all ease-in 0.1s; - cursor: pointer; - opacity: 0.9; -} - -button:hover { - transform: scale(1.05); - opacity: 1; -} - -li { - list-style: none; -} - -a { - text-decoration: none; - height: fit-content; - width: fit-content; - margin: 10px; -} - -a:hover { - opacity: 1; - text-decoration: none; -} - -.Hello { - display: flex; - justify-content: center; - align-items: center; - margin: 20px 0; -} +@tailwind base; +@tailwind components; +@tailwind utilities; diff --git a/apps/server-web/src/renderer/App.tsx b/apps/server-web/src/renderer/App.tsx index 43a4a7e07..77931220c 100644 --- a/apps/server-web/src/renderer/App.tsx +++ b/apps/server-web/src/renderer/App.tsx @@ -1,49 +1,13 @@ -import { MemoryRouter as Router, Routes, Route } from 'react-router-dom'; +import { HashRouter as Router, Routes, Route } from 'react-router-dom'; import icon from '../../assets/icon.svg'; import './App.css'; - -function Hello() { - return ( -
- ); -} +import { Setting } from './pages/Setting'; export default function App() { return (