mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +03:00
Improve Electron experience and build system
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
{
|
||||
"name": "FromChat",
|
||||
"productName": "FromChat",
|
||||
"version": "1.0.0",
|
||||
"description": "A 100% Open Source Messenger",
|
||||
"main": "dist-electron/main.js",
|
||||
"scripts": {
|
||||
"package": "electron-forge package",
|
||||
"make": "electron-forge make",
|
||||
"publish": "electron-forge publish"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": {
|
||||
"name": "denis0001-dev",
|
||||
"email": "denis0001.dev@ya.ru"
|
||||
},
|
||||
"license": "GPL-2.0",
|
||||
"devDependencies": {
|
||||
"@electron-forge/cli": "^7.8.3",
|
||||
"@electron-forge/maker-deb": "^7.8.3",
|
||||
"@electron-forge/maker-rpm": "^7.8.3",
|
||||
"@electron-forge/maker-squirrel": "^7.8.3",
|
||||
"@electron-forge/maker-zip": "^7.8.3",
|
||||
"@electron-forge/plugin-auto-unpack-natives": "^7.8.3",
|
||||
"@electron-forge/plugin-fuses": "^7.8.3",
|
||||
"@electron/fuses": "^1.8.0",
|
||||
"electron": "37.3.1",
|
||||
"vite": "^5.4.19"
|
||||
},
|
||||
"dependencies": {
|
||||
"electron-squirrel-startup": "^1.0.1"
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import path from "node:path";
|
||||
app.whenReady().then(() => {
|
||||
const win = new BrowserWindow({
|
||||
title: 'Main window',
|
||||
minWidth: 650,
|
||||
minWidth: 800,
|
||||
minHeight: 420,
|
||||
webPreferences: {
|
||||
preload: path.join(import.meta.dirname, "preload.mjs")
|
||||
@@ -16,11 +16,11 @@ app.whenReady().then(() => {
|
||||
y: 16 - 4
|
||||
},
|
||||
titleBarOverlay: process.platform !== "darwin"
|
||||
})
|
||||
});
|
||||
|
||||
if (process.env.VITE_DEV_SERVER_URL) {
|
||||
win.loadURL(process.env.VITE_DEV_SERVER_URL)
|
||||
win.loadURL(process.env.VITE_DEV_SERVER_URL);
|
||||
} else {
|
||||
win.loadFile('dist/index.html');
|
||||
win.loadFile('frontend/build/electron/dist/index.html');
|
||||
}
|
||||
});
|
||||
@@ -1,29 +1,28 @@
|
||||
import { FusesPlugin } from '@electron-forge/plugin-fuses';
|
||||
import { FuseV1Options, FuseVersion } from '@electron/fuses';
|
||||
import type { ForgeConfig } from "@electron-forge/shared-types";
|
||||
import type { ForgeConfig } from '@electron-forge/shared-types';
|
||||
|
||||
const config: ForgeConfig = {
|
||||
export default {
|
||||
packagerConfig: {
|
||||
asar: true
|
||||
asar: true,
|
||||
},
|
||||
outDir: "frontend/build/electron/forge",
|
||||
rebuildConfig: {},
|
||||
makers: [
|
||||
{
|
||||
name: '@electron-forge/maker-squirrel',
|
||||
config: {},
|
||||
},
|
||||
{
|
||||
name: '@electron-forge/maker-zip',
|
||||
config: {},
|
||||
platforms: ['darwin'],
|
||||
platforms: ['win32', 'darwin'],
|
||||
},
|
||||
{
|
||||
name: '@electron-forge/maker-deb',
|
||||
config: {},
|
||||
platforms: ['linux'],
|
||||
},
|
||||
{
|
||||
name: '@electron-forge/maker-rpm',
|
||||
config: {},
|
||||
platforms: ['linux'],
|
||||
},
|
||||
],
|
||||
plugins: [
|
||||
@@ -43,6 +42,4 @@ const config: ForgeConfig = {
|
||||
[FuseV1Options.OnlyLoadAppFromAsar]: true,
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
||||
export default config;
|
||||
} satisfies ForgeConfig;
|
||||
@@ -5,13 +5,11 @@
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
import { PRODUCT_NAME } from "../core/config.ts";
|
||||
import { id } from "../utils/utils.ts";
|
||||
export const isElectron = import.meta.env.VITE_ELECTRON && window.electronInterface != undefined;
|
||||
|
||||
if (window.electronInterface !== undefined) {
|
||||
if (isElectron) {
|
||||
console.log("Running in Electron");
|
||||
document.documentElement.classList.add("electron", `platform-${window.electronInterface.platform}`);
|
||||
id("window-title").textContent = PRODUCT_NAME;
|
||||
} else {
|
||||
console.log("Running in normal browser");
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import "mdui/mdui.css";
|
||||
|
||||
import "./utils/material";
|
||||
import "./core/init";
|
||||
import "./electron/electron";
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import App from './ui/App';
|
||||
import { StrictMode } from 'react';
|
||||
|
||||
@@ -9,13 +9,14 @@ html.electron {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 8px;
|
||||
height: 40px;
|
||||
min-height: 40px;
|
||||
background-color: $color-dark-surface-container;
|
||||
width: 100%;
|
||||
-webkit-app-region: drag;
|
||||
user-select: none;
|
||||
z-index: 10;
|
||||
transition: background-color 0.5s ease;
|
||||
flex-shrink: 0;
|
||||
|
||||
&.color-surface {
|
||||
background-color: $color-dark-surface;
|
||||
@@ -29,15 +30,12 @@ html.electron {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
&.platform-darwin .macos-padding {
|
||||
width: 70px;
|
||||
#main-wrapper {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
// .window-controls {
|
||||
// -webkit-app-region: no-drag;
|
||||
|
||||
// .hidden {
|
||||
// display: none;
|
||||
// }
|
||||
// }
|
||||
&.platform-darwin .macos-padding {
|
||||
width: 80px;
|
||||
}
|
||||
}
|
||||
@@ -24,17 +24,20 @@ body {
|
||||
background-color: $color-dark-surface;
|
||||
color: $color-dark-on-surface;
|
||||
line-height: 1.6;
|
||||
|
||||
#main-wrapper {
|
||||
flex: 1;
|
||||
position: relative;
|
||||
min-height: 0;
|
||||
}
|
||||
}
|
||||
|
||||
body, #root {
|
||||
height: 100vh;
|
||||
position: relative;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
#main-wrapper {
|
||||
flex: 1;
|
||||
position: relative;
|
||||
height: 100vh;
|
||||
}
|
||||
}
|
||||
|
||||
mdui-dialog {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { MINIMUM_WIDTH } from "../core/config";
|
||||
import { isElectron } from "../electron/electron";
|
||||
import { ElectronTitleBar } from "./components/Electron";
|
||||
import useWindowSize from "./hooks/useWindowSize";
|
||||
import ChatScreen from "./screen/ChatScreen";
|
||||
@@ -17,7 +18,7 @@ export default function App() {
|
||||
restoreUserFromStorage();
|
||||
}, [restoreUserFromStorage]);
|
||||
|
||||
if (width < MINIMUM_WIDTH) {
|
||||
if (!isElectron && width < MINIMUM_WIDTH) {
|
||||
return <DownloadAppScreen />
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,11 @@
|
||||
import { PRODUCT_NAME } from "../../core/config";
|
||||
import { isElectron } from "../../electron/electron";
|
||||
|
||||
export function ElectronTitleBar() {
|
||||
if (window.electronInterface !== undefined) {
|
||||
return (
|
||||
<div id="electron-title-bar">
|
||||
{window.electronInterface.platform == "darwin" ? <div className="macos-padding"></div> : undefined}
|
||||
<div id="window-title">{PRODUCT_NAME}</div>
|
||||
{/* <div className="window-controls">
|
||||
<mdui-button-icon icon="remove" id="window-minimize"></mdui-button-icon>
|
||||
<mdui-button-icon icon="stack--outlined" id="window-restore" className="hidden"></mdui-button-icon>
|
||||
<mdui-button-icon icon="ad--outlined" id="window-maximize"></mdui-button-icon>
|
||||
<mdui-button-icon icon="close" id="window-close"></mdui-button-icon>
|
||||
</div> */}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return isElectron && (
|
||||
<div id="electron-title-bar">
|
||||
{window.electronInterface.platform == "darwin" && <div className="macos-padding"></div>}
|
||||
<div id="window-title">{PRODUCT_NAME}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -153,20 +153,20 @@ export function MessagePanelRenderer({ panel, isChatSwitching }: MessagePanelRen
|
||||
<ChatMessages
|
||||
messages={panelState.messages}
|
||||
isDm={panel.isDm()}
|
||||
onReplySelect={(m) => {
|
||||
onReplySelect={(message) => {
|
||||
if (editMessage || editVisible) {
|
||||
setPendingAction({ type: "reply", message: m });
|
||||
setPendingAction({ type: "reply", message: message });
|
||||
setEditVisible(false); // onCloseEdit will apply pending
|
||||
} else {
|
||||
setReplyTo(m);
|
||||
setReplyTo(message);
|
||||
}
|
||||
}}
|
||||
onEditSelect={(m) => {
|
||||
onEditSelect={(message) => {
|
||||
if (replyTo || replyToVisible) {
|
||||
setPendingAction({ type: "edit", message: m });
|
||||
setPendingAction({ type: "edit", message: message });
|
||||
setReplyToVisible(false); // onCloseReply will apply pending
|
||||
} else {
|
||||
setEditMessage(m);
|
||||
setEditMessage(message);
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { PublicChatPanel } from "./panels/PublicChatPanel";
|
||||
import { DMPanel, type DMPanelData } from "./panels/DMPanel";
|
||||
import { getAuthHeaders } from "../auth/api";
|
||||
import { restoreKeys } from "../auth/crypto";
|
||||
import { API_BASE_URL } from "../core/config";
|
||||
|
||||
type Page = "login" | "register" | "chat"
|
||||
export type ChatTabs = "chats" | "channels" | "contacts" | "dms"
|
||||
@@ -199,7 +200,7 @@ export const useAppState = create<AppState>((set, get) => ({
|
||||
const token = localStorage.getItem('authToken');
|
||||
|
||||
if (token) {
|
||||
const response = await fetch("/api/user/profile", {
|
||||
const response = await fetch(`${API_BASE_URL}/user/profile`, {
|
||||
headers: getAuthHeaders(token)
|
||||
});
|
||||
|
||||
|
||||
+13
-2
@@ -25,9 +25,19 @@ if (process.env.VITE_ELECTRON) {
|
||||
electron({
|
||||
main: {
|
||||
entry: "electron/main.ts",
|
||||
vite: {
|
||||
build: {
|
||||
outDir: "build/electron/core"
|
||||
}
|
||||
}
|
||||
},
|
||||
preload: {
|
||||
input: "frontend/electron/preload.ts"
|
||||
input: "frontend/electron/preload.ts",
|
||||
vite: {
|
||||
build: {
|
||||
outDir: "build/electron/core"
|
||||
}
|
||||
}
|
||||
},
|
||||
renderer: {},
|
||||
})
|
||||
@@ -68,6 +78,7 @@ export default defineConfig({
|
||||
}
|
||||
},
|
||||
cssMinify: true,
|
||||
assetsInlineLimit: 0
|
||||
assetsInlineLimit: 0,
|
||||
outDir: process.env.VITE_ELECTRON ? "build/electron/dist" : "build/normal/dist"
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user