refactor: remove electron lib

This commit is contained in:
Tristan Yang
2023-08-31 14:19:15 +08:00
parent 07105dc9f2
commit 48ff349e66
6 changed files with 23 additions and 42 deletions
+1 -2
View File
@@ -1,9 +1,8 @@
{ {
"name": "vocechat-web", "name": "vocechat-web",
"version": "0.5.2", "version": "0.5.4",
"homepage": "https://voce.chat", "homepage": "https://voce.chat",
"dependencies": { "dependencies": {
"@electron-toolkit/preload": "^2.0.0",
"@emoji-mart/react": "^1.1.1", "@emoji-mart/react": "^1.1.1",
"@metamask/onboarding": "^1.0.1", "@metamask/onboarding": "^1.0.1",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
-18
View File
@@ -1,18 +0,0 @@
import { useEffect } from "react";
// type Props = {};
const Electron = () => {
useEffect(() => {
if (window.electron === undefined) return;
const handleData = (_: any, arg: any) => {
console.log("electron msg", arg);
};
console.log("ttttt", window.electron.process.platform);
window.electron.ipcRenderer.on("server-name-popover", handleData);
}, []);
return null;
};
export default Electron;
+4 -3
View File
@@ -5,25 +5,26 @@ import { GuestRoutes, KEY_LOCAL_TRY_PATH } from "@/app/config";
import { useAppSelector } from "@/app/store"; import { useAppSelector } from "@/app/store";
import Loading from "./Loading"; import Loading from "./Loading";
import { shallowEqual } from "react-redux"; import { shallowEqual } from "react-redux";
import { LoginConfig } from "@/types/server";
interface Props { interface Props {
loginConfig: LoginConfig | null;
children: ReactElement; children: ReactElement;
redirectTo?: string; redirectTo?: string;
} }
const GuestAllows = GuestRoutes.map((path) => { const GuestAllows = GuestRoutes.map((path) => {
return { path }; return { path };
}); });
const RequireAuth: FC<Props> = ({ children, redirectTo = "/login" }) => { const RequireAuth: FC<Props> = ({ children, redirectTo = "/login", loginConfig }) => {
const location = useLocation(); const location = useLocation();
const matches = matchRoutes(GuestAllows, location); const matches = matchRoutes(GuestAllows, location);
const allowGuest = matches ? !!matches[0].pathname : false; const allowGuest = matches ? !!matches[0].pathname : false;
const token = useAppSelector((store) => store.authData.token, shallowEqual); const token = useAppSelector((store) => store.authData.token, shallowEqual);
const guest = useAppSelector((store) => store.authData.guest, shallowEqual); const guest = useAppSelector((store) => store.authData.guest, shallowEqual);
const initialized = useAppSelector((store) => store.authData.initialized, shallowEqual); const initialized = useAppSelector((store) => store.authData.initialized, shallowEqual);
const loginConfig = useAppSelector((store) => store.server.loginConfig, shallowEqual);
console.info("check basic info", loginConfig); console.info("check basic info", loginConfig);
// 初始化login配置检查 // 初始化login配置检查
if (!loginConfig) return <Loading fullscreen={true} context="auth-route" />; if (!loginConfig) return <Loading fullscreen={true} reload context="auth-route" />;
// 未初始化 则先走setup 流程 // 未初始化 则先走setup 流程
if (!initialized) return <Navigate to={`/onboarding`} replace />; if (!initialized) return <Navigate to={`/onboarding`} replace />;
// 开启guest 并且没token 而且是允许guest访问的路由 则先去过渡页登录 // 开启guest 并且没token 而且是允许guest访问的路由 则先去过渡页登录
+5 -7
View File
@@ -1,16 +1,14 @@
import { lazy, memo, useEffect } from "react"; import { lazy, useEffect, memo } from "react";
import toast from "react-hot-toast"; import toast from "react-hot-toast";
import { Provider, shallowEqual } from "react-redux"; import { Provider, shallowEqual } from "react-redux";
import { HashRouter, Route, Routes } from "react-router-dom"; import { HashRouter, Route, Routes } from "react-router-dom";
import { isEqual } from "lodash";
import Electron from "@/components/Electron";
import Meta from "@/components/Meta"; import Meta from "@/components/Meta";
import useDeviceToken from "@/components/Notification/useDeviceToken"; import useDeviceToken from "@/components/Notification/useDeviceToken";
import RequireAuth from "@/components/RequireAuth"; import RequireAuth from "@/components/RequireAuth";
import RequireNoAuth from "@/components/RequireNoAuth"; import RequireNoAuth from "@/components/RequireNoAuth";
import RequireSingleTab from "@/components/RequireSingleTab"; import RequireSingleTab from "@/components/RequireSingleTab";
import { compareVersion, isElectronContext } from "@/utils"; import { compareVersion } from "@/utils";
import { vapidKey } from "../app/config"; import { vapidKey } from "../app/config";
import store, { useAppSelector } from "../app/store"; import store, { useAppSelector } from "../app/store";
import NotFoundPage from "./404"; import NotFoundPage from "./404";
@@ -40,6 +38,7 @@ const HomePage = lazy(() => import("./home"));
let toastId: string; let toastId: string;
const PageRoutes = () => { const PageRoutes = () => {
const loginConfig = useAppSelector((store) => store.server.loginConfig, shallowEqual);
const version = useAppSelector((store) => store.server.version, shallowEqual); const version = useAppSelector((store) => store.server.version, shallowEqual);
const online = useAppSelector((store) => store.ui.online, shallowEqual); const online = useAppSelector((store) => store.ui.online, shallowEqual);
// 提前获取device token // 提前获取device token
@@ -70,7 +69,7 @@ const PageRoutes = () => {
path="/invite_private/:channel_id" path="/invite_private/:channel_id"
element={ element={
<LazyIt> <LazyIt>
<RequireAuth> <RequireAuth loginConfig={loginConfig}>
<InvitePrivate /> <InvitePrivate />
</RequireAuth> </RequireAuth>
</LazyIt> </LazyIt>
@@ -174,7 +173,7 @@ const PageRoutes = () => {
path="/" path="/"
element={ element={
<LazyIt> <LazyIt>
<RequireAuth> <RequireAuth loginConfig={loginConfig}>
{/* 只允许活跃一个tab标签 */} {/* 只允许活跃一个tab标签 */}
<RequireSingleTab> <RequireSingleTab>
<HomePage /> <HomePage />
@@ -295,7 +294,6 @@ const PageRoutes = () => {
function ReduxRoutes() { function ReduxRoutes() {
return ( return (
<Provider store={store}> <Provider store={store}>
{isElectronContext() && <Electron />}
<Meta /> <Meta />
<PageRoutes /> <PageRoutes />
</Provider> </Provider>
+13 -7
View File
@@ -1,5 +1,12 @@
import { IAgoraRTCClient, ICameraVideoTrack, ILocalAudioTrack, ILocalVideoTrack, IMicrophoneAudioTrack, IRemoteAudioTrack, IRemoteVideoTrack } from "agora-rtc-sdk-ng"; import {
import {ElectronAPI} from '@electron-toolkit/preload'; IAgoraRTCClient,
ICameraVideoTrack,
ILocalAudioTrack,
ILocalVideoTrack,
IMicrophoneAudioTrack,
IRemoteAudioTrack,
IRemoteVideoTrack
} from "agora-rtc-sdk-ng";
interface BeforeInstallPromptEvent extends Event { interface BeforeInstallPromptEvent extends Event {
/** /**
* Returns an array of DOMString items containing the platforms on which the event was dispatched. * Returns an array of DOMString items containing the platforms on which the event was dispatched.
@@ -28,17 +35,16 @@ export declare global {
import localforage from "localforage"; import localforage from "localforage";
interface Window { interface Window {
electron: ElectronAPI;
__WB_MANIFEST: Array<PrecacheEntry | string>; __WB_MANIFEST: Array<PrecacheEntry | string>;
skipWaiting: () => void; skipWaiting: () => void;
CACHE: { [key: string]: typeof localforage | undefined }; CACHE: { [key: string]: typeof localforage | undefined };
VOICE_CLIENT?: IAgoraRTCClient; VOICE_CLIENT?: IAgoraRTCClient;
VOICE_TRACK_MAP: { VOICE_TRACK_MAP: {
[key: number]: IRemoteAudioTrack | IMicrophoneAudioTrack | undefined | null [key: number]: IRemoteAudioTrack | IMicrophoneAudioTrack | undefined | null;
}, };
VIDEO_TRACK_MAP: { VIDEO_TRACK_MAP: {
[key: number]: IRemoteVideoTrack | ICameraVideoTrack | ShareScreenTrack | undefined | null [key: number]: IRemoteVideoTrack | ICameraVideoTrack | ShareScreenTrack | undefined | null;
}, };
} }
interface WindowEventMap { interface WindowEventMap {
beforeinstallprompt: BeforeInstallPromptEvent; beforeinstallprompt: BeforeInstallPromptEvent;
-5
View File
@@ -1259,11 +1259,6 @@
"@babel/helper-validator-identifier" "^7.22.5" "@babel/helper-validator-identifier" "^7.22.5"
to-fast-properties "^2.0.0" to-fast-properties "^2.0.0"
"@electron-toolkit/preload@^2.0.0":
version "2.0.0"
resolved "https://mirrors.cloud.tencent.com/npm/@electron-toolkit/preload/-/preload-2.0.0.tgz#1b704c4c4643ae1d960835db196625e17c9dcf4e"
integrity sha512-zpZDzbqJTZQC5d4LRs2EKruKWnqah+T75s+niBYFemYLtiW5TTZcWi3Q8UxHqnwTudDMuWJb233aaS2yjx3Xiw==
"@emoji-mart/react@^1.1.1": "@emoji-mart/react@^1.1.1":
version "1.1.1" version "1.1.1"
resolved "https://mirrors.cloud.tencent.com/npm/@emoji-mart/react/-/react-1.1.1.tgz#ddad52f93a25baf31c5383c3e7e4c6e05554312a" resolved "https://mirrors.cloud.tencent.com/npm/@emoji-mart/react/-/react-1.1.1.tgz#ddad52f93a25baf31c5383c3e7e4c6e05554312a"