mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +03:00
Adapt the web version to Electron
This commit is contained in:
Vendored
+12
@@ -0,0 +1,12 @@
|
|||||||
|
export type Platform = "win32" | "darwin" | "linux"
|
||||||
|
|
||||||
|
export interface ElectronInterface {
|
||||||
|
desktop: true,
|
||||||
|
platform: Platform
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
electronInterface: ElectronInterface
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,21 @@
|
|||||||
import { app, BrowserWindow } from 'electron';
|
import { app, BrowserWindow } from 'electron';
|
||||||
|
import path from "node:path";
|
||||||
|
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
const win = new BrowserWindow({
|
const win = new BrowserWindow({
|
||||||
title: 'Main window',
|
title: 'Main window',
|
||||||
minWidth: 650,
|
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`
|
// You can use `process.env.VITE_DEV_SERVER_URL` when the vite command is called `serve`
|
||||||
|
|||||||
@@ -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);
|
||||||
@@ -7,6 +7,17 @@
|
|||||||
<link rel="icon" href="./src/images/logo.png" />
|
<link rel="icon" href="./src/images/logo.png" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<div id="electron-title-bar">
|
||||||
|
<div class="macos-padding"></div>
|
||||||
|
<div id="window-title"></div>
|
||||||
|
<!-- <div class="window-controls">
|
||||||
|
<mdui-button-icon icon="remove" id="window-minimize"></mdui-button-icon>
|
||||||
|
<mdui-button-icon icon="stack--outlined" id="window-restore" class="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>
|
||||||
|
<div id="main-wrapper">
|
||||||
<!-- Login Form -->
|
<!-- Login Form -->
|
||||||
<div id="login-form" class="auth-container">
|
<div id="login-form" class="auth-container">
|
||||||
<div class="auth-card fade-in">
|
<div class="auth-card fade-in">
|
||||||
@@ -192,6 +203,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<mdui-dialog id="profile-dialog" close-on-overlay-click close-on-esc>
|
<mdui-dialog id="profile-dialog" close-on-overlay-click close-on-esc>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ export function showLogin(): void {
|
|||||||
document.getElementById('register-form')!.style.display = 'none';
|
document.getElementById('register-form')!.style.display = 'none';
|
||||||
document.getElementById('chat-interface')!.style.display = 'none';
|
document.getElementById('chat-interface')!.style.display = 'none';
|
||||||
clearAlerts();
|
clearAlerts();
|
||||||
|
document.getElementById("electron-title-bar")!.classList.add("color-surface");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,6 +69,7 @@ export function showRegister(): void {
|
|||||||
document.getElementById('register-form')!.style.display = 'flex';
|
document.getElementById('register-form')!.style.display = 'flex';
|
||||||
document.getElementById('chat-interface')!.style.display = 'none';
|
document.getElementById('chat-interface')!.style.display = 'none';
|
||||||
clearAlerts();
|
clearAlerts();
|
||||||
|
document.getElementById("electron-title-bar")!.classList.add("color-surface");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,6 +83,7 @@ export function showChat(): void {
|
|||||||
document.getElementById('register-form')!.style.display = 'none';
|
document.getElementById('register-form')!.style.display = 'none';
|
||||||
document.getElementById('chat-interface')!.style.display = 'block';
|
document.getElementById('chat-interface')!.style.display = 'block';
|
||||||
loadMessages();
|
loadMessages();
|
||||||
|
document.getElementById("electron-title-bar")!.classList.remove("color-surface");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
min-height: 100vh;
|
height: 100%;
|
||||||
padding: 2rem;
|
padding: 2rem;
|
||||||
background-color: $color-dark-surface;
|
background-color: $color-dark-surface;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
@use "common/material" as *;
|
@use "common/material" as *;
|
||||||
|
|
||||||
#chat-interface {
|
#chat-interface {
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
display: flex;
|
display: flex;
|
||||||
background-color: $color-dark-surface-container;
|
background-color: $color-dark-surface-container;
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
@use "common/material" as *;
|
||||||
|
|
||||||
|
#electron-title-bar {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
html.electron {
|
||||||
|
#electron-title-bar {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
gap: 8px;
|
||||||
|
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;
|
||||||
|
|
||||||
|
&.color-surface {
|
||||||
|
background-color: $color-dark-surface;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#window-title {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.platform-darwin .macos-padding {
|
||||||
|
width: 70px;
|
||||||
|
}
|
||||||
|
|
||||||
|
// .window-controls {
|
||||||
|
// -webkit-app-region: no-drag;
|
||||||
|
|
||||||
|
// .hidden {
|
||||||
|
// display: none;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100vh;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#profile {
|
#profile {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
@use "common/components";
|
@use "common/components";
|
||||||
@use "common/colors" as *;
|
@use "common/colors" as *;
|
||||||
@use "common/material" as *;
|
@use "common/material" as *;
|
||||||
|
@use "electron";
|
||||||
|
|
||||||
@use "lib/fonts/montserrat";
|
@use "lib/fonts/montserrat";
|
||||||
@use "lib/fonts/material-symbols";
|
@use "lib/fonts/material-symbols";
|
||||||
@@ -24,6 +25,13 @@ body {
|
|||||||
height: 100vh;
|
height: 100vh;
|
||||||
position: relative;
|
position: relative;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
#main-wrapper {
|
||||||
|
flex: 1;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mdui-dialog {
|
mdui-dialog {
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import "../electron.d.ts";
|
||||||
|
import { PRODUCT_NAME } from "./config";
|
||||||
|
|
||||||
|
if (window.electronInterface !== undefined) {
|
||||||
|
console.log("Running in Electron");
|
||||||
|
document.documentElement.classList.add("electron", `platform-${window.electronInterface.platform}`);
|
||||||
|
document.getElementById("window-title")!.textContent = PRODUCT_NAME;
|
||||||
|
} else {
|
||||||
|
console.log("Running in normal browser");
|
||||||
|
}
|
||||||
@@ -16,3 +16,4 @@ import "./init";
|
|||||||
import "./profile";
|
import "./profile";
|
||||||
import "./message-context-menu";
|
import "./message-context-menu";
|
||||||
import "./user-profile-dialog";
|
import "./user-profile-dialog";
|
||||||
|
import "./electron";
|
||||||
Reference in New Issue
Block a user