From a1be1daa09a8abba3ec12116ad8aae3d42d37521 Mon Sep 17 00:00:00 2001 From: denis0001-dev Date: Sun, 24 Aug 2025 19:57:38 +0300 Subject: [PATCH 1/5] Start the Electron version --- .gitignore | 3 +- .vscode/tasks.json | 20 ++++++++++++-- frontend/electron/main.ts | 15 ++++++++++ frontend/electron/preload.ts | 0 frontend/vite.config.ts | 53 ++++++++++++++++++++++++------------ package.json | 6 ++++ 6 files changed, 76 insertions(+), 21 deletions(-) create mode 100644 frontend/electron/main.ts create mode 100644 frontend/electron/preload.ts diff --git a/.gitignore b/.gitignore index a7c6771..ea1679e 100644 --- a/.gitignore +++ b/.gitignore @@ -379,4 +379,5 @@ pyrightconfig.json data .vite *.db -package-lock.json \ No newline at end of file +package-lock.json +dist-electron \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index ad432ea..44ac70d 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -15,8 +15,24 @@ "panel": "shared" }, "group": { - "kind": "build", - "isDefault": true + "kind": "build" + } + }, + { + "label": "Run (Electron)", + "type": "shell", + "command": "npm run dev:electron", + "options": { + "cwd": "${workspaceFolder}" + }, + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared" + }, + "group": { + "kind": "build" } } ] diff --git a/frontend/electron/main.ts b/frontend/electron/main.ts new file mode 100644 index 0000000..379237f --- /dev/null +++ b/frontend/electron/main.ts @@ -0,0 +1,15 @@ +import { app, BrowserWindow } from 'electron'; + +app.whenReady().then(() => { + const win = new BrowserWindow({ + title: 'Main window', + }) + + // You can use `process.env.VITE_DEV_SERVER_URL` when the vite command is called `serve` + if (process.env.VITE_DEV_SERVER_URL) { + win.loadURL(process.env.VITE_DEV_SERVER_URL) + } else { + // Load your file + win.loadFile('dist/index.html'); + } +}); \ No newline at end of file diff --git a/frontend/electron/preload.ts b/frontend/electron/preload.ts new file mode 100644 index 0000000..e69de29 diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 7064e17..e9fcfc5 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -1,22 +1,39 @@ -import { defineConfig } from 'vite' -import { createHtmlPlugin } from 'vite-plugin-html' -import autoprefixer from 'autoprefixer' +import { defineConfig, PluginOption } from 'vite'; +import { createHtmlPlugin } from 'vite-plugin-html'; +import autoprefixer from 'autoprefixer'; +import electron from 'vite-plugin-electron/simple'; + +const plugins: PluginOption[] = [ + createHtmlPlugin({ + minify: { + collapseWhitespace: true, + removeComments: true, + removeRedundantAttributes: true, + removeScriptTypeAttributes: true, + removeStyleLinkTypeAttributes: true, + useShortDoctype: true, + minifyCSS: true, + minifyJS: true + } + }) +] + +if (process.env.VITE_ELECTRON) { + plugins.push( + electron({ + main: { + entry: "electron/main.ts", + }, + preload: { + input: "frontend/electron/preload.ts" + }, + renderer: {}, + }) + ); +} export default defineConfig({ - plugins: [ - createHtmlPlugin({ - minify: { - collapseWhitespace: true, - removeComments: true, - removeRedundantAttributes: true, - removeScriptTypeAttributes: true, - removeStyleLinkTypeAttributes: true, - useShortDoctype: true, - minifyCSS: true, - minifyJS: true - } - }) - ], + plugins: plugins, server: { host: '0.0.0.0', port: 8301, @@ -50,4 +67,4 @@ export default defineConfig({ cssMinify: true, assetsInlineLimit: 0 } -}) \ No newline at end of file +}); \ No newline at end of file diff --git a/package.json b/package.json index 68bf397..8b9f0b7 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "private": true, "version": "0.0.0", "type": "module", + "main": "frontend/dist-electron/main.js", "scripts": { "backend:run": "cd backend && dotenv -e ../deployment/.env -- ../.venv/bin/fastapi dev --port 8300 main.py", "backend:dependencies": "python3 -m venv .venv && ./.venv/bin/pip3 install -r backend/requirements.txt", @@ -10,10 +11,12 @@ "backend:clean": "rm -rf backend/data", "frontend:dev": "vite frontend", "frontend:build": "tsc --project frontend && vite build frontend", + "frontend:electron:dev": "VITE_ELECTRON=true npm run frontend:dev", "frontend:preview": "vite preview frontend", "frontend:dependencies": "npm install --ignore-scripts", "frontend:clean": "rm -rf frontend/dist", "dev": "concurrently 'npm run frontend:dev' 'npm run backend:run'", + "dev:electron": "concurrently 'npm run frontend:electron:dev' 'npm run backend:run'", "build": "npm run frontend:build", "preview": "cd deployment && docker compose up --build --watch", "preview:clean": "cd deployment && docker compose down -v", @@ -23,12 +26,15 @@ "devDependencies": { "autoprefixer": "^10.4.21", "concurrently": "^9.2.0", + "electron": "^37.3.1", "dotenv-cli": "^10.0.0", "postcss": "^8.5.6", "sass-embedded": "^1.90.0", "terser": "^5.43.1", "typescript": "~5.9.2", "vite": "^7.1.2", + "vite-plugin-electron": "^0.29.0", + "vite-plugin-electron-renderer": "^0.14.6", "vite-plugin-html": "^3.2.2" }, "dependencies": { From 3bbfafa9e58d8a9559a967f99898ec7e8f1692d6 Mon Sep 17 00:00:00 2001 From: denis0001-dev Date: Sun, 24 Aug 2025 21:01:25 +0300 Subject: [PATCH 2/5] Set minimum windows boundaries --- frontend/electron/main.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/frontend/electron/main.ts b/frontend/electron/main.ts index 379237f..4fab3df 100644 --- a/frontend/electron/main.ts +++ b/frontend/electron/main.ts @@ -1,15 +1,17 @@ import { app, BrowserWindow } from 'electron'; app.whenReady().then(() => { - const win = new BrowserWindow({ - title: 'Main window', - }) + const win = new BrowserWindow({ + title: 'Main window', + minWidth: 650, + minHeight: 420 + }) - // You can use `process.env.VITE_DEV_SERVER_URL` when the vite command is called `serve` - if (process.env.VITE_DEV_SERVER_URL) { - win.loadURL(process.env.VITE_DEV_SERVER_URL) - } else { - // Load your file - win.loadFile('dist/index.html'); - } + // You can use `process.env.VITE_DEV_SERVER_URL` when the vite command is called `serve` + if (process.env.VITE_DEV_SERVER_URL) { + win.loadURL(process.env.VITE_DEV_SERVER_URL) + } else { + // Load your file + win.loadFile('dist/index.html'); + } }); \ No newline at end of file From 8348547baa7164c871c15e96a8b08b90e7b9b5a6 Mon Sep 17 00:00:00 2001 From: denis0001-dev Date: Sun, 24 Aug 2025 23:15:20 +0300 Subject: [PATCH 3/5] Adapt the web version to Electron --- frontend/electron.d.ts | 12 ++ frontend/electron/main.ts | 13 +- frontend/electron/preload.ts | 9 + frontend/index.html | 354 ++++++++++++++++--------------- frontend/src/auth.ts | 3 + frontend/src/css/_auth.scss | 2 +- frontend/src/css/_chat.scss | 2 + frontend/src/css/_electron.scss | 43 ++++ frontend/src/css/_panelchat.scss | 2 +- frontend/src/css/style.scss | 8 + frontend/src/electron.ts | 10 + frontend/src/main.ts | 3 +- 12 files changed, 286 insertions(+), 175 deletions(-) create mode 100644 frontend/electron.d.ts create mode 100644 frontend/src/css/_electron.scss create mode 100644 frontend/src/electron.ts diff --git a/frontend/electron.d.ts b/frontend/electron.d.ts new file mode 100644 index 0000000..ae8b74e --- /dev/null +++ b/frontend/electron.d.ts @@ -0,0 +1,12 @@ +export type Platform = "win32" | "darwin" | "linux" + +export interface ElectronInterface { + desktop: true, + platform: Platform +} + +declare global { + interface Window { + electronInterface: ElectronInterface + } +} \ No newline at end of file diff --git a/frontend/electron/main.ts b/frontend/electron/main.ts index 4fab3df..55fbeb7 100644 --- a/frontend/electron/main.ts +++ b/frontend/electron/main.ts @@ -1,10 +1,21 @@ import { app, BrowserWindow } from 'electron'; +import path from "node:path"; app.whenReady().then(() => { const win = new BrowserWindow({ title: 'Main window', minWidth: 650, - minHeight: 420 + minHeight: 420, + webPreferences: { + preload: path.join(import.meta.dirname, "preload.mjs") + }, + titleBarStyle: "hidden", + ...(process.platform !== 'darwin' ? { titleBarOverlay: true } : {}), + trafficLightPosition: { + x: 16 - 4, + y: 16 - 4 + }, + titleBarOverlay: process.platform !== "darwin" }) // You can use `process.env.VITE_DEV_SERVER_URL` when the vite command is called `serve` diff --git a/frontend/electron/preload.ts b/frontend/electron/preload.ts index e69de29..4d99711 100644 --- a/frontend/electron/preload.ts +++ b/frontend/electron/preload.ts @@ -0,0 +1,9 @@ +import { contextBridge } from "electron"; +import type { ElectronInterface, Platform } from "../electron"; + +const electronInterface: ElectronInterface = { + desktop: true, + platform: process.platform as Platform +} + +contextBridge.exposeInMainWorld("electronInterface", electronInterface); \ No newline at end of file diff --git a/frontend/index.html b/frontend/index.html index 5a1549b..96eb4a7 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -7,185 +7,197 @@ - -
-
-
-

- login - Добро пожаловать! -

-

Войдите в свой аккаунт

-
-
-
- -
- - - - - - Войти -
- -
-

Ещё нет аккаунта? Зарегистрируйтесь

-
-
-
+
+
+
+
- - -