Skip to content

Commit

Permalink
fix react-query bugs, add use-independence-process function
Browse files Browse the repository at this point in the history
  • Loading branch information
Dalufishe committed Jun 24, 2024
1 parent 192a49e commit cd4b4c7
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 30 deletions.
5 changes: 5 additions & 0 deletions locales/zh_tw/translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,5 +350,10 @@ const zh_tw = {
SpecialThanks: '特別感謝',
SpeicalThanksDesc: '感謝所有的開發人員、贊助者、小幫手及使用 GUI 的大家。',
BuyMeACoffee: '請我喝杯咖啡',
//
Process: '進程',
UseIndependentProcess: '使用獨立進程',
UseIndependentProcessDesc:
'預設情況下為關閉,伺服器為 GUI 的子進程。當您的伺服器經常發生非預期性的崩潰時,請嘗試開啟此選項。開啟後會顯示小黑窗,另外開啟後無法使用效能監測功能。',
};
export default zh_tw;
21 changes: 18 additions & 3 deletions src/main/ipcs/server/exec/execStartServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ ipcMain.on(

// start server

let processId = await startServer(event, serverId, queryport);
let processId = await startServer(
event,
serverId,
queryport,
serverInfo.UseIndependentProcess,
);

// #region auto restart

Expand All @@ -123,7 +128,12 @@ ipcMain.on(
}
// 伺服器重新啟動
await sleep(2000);
processId = await startServer(event, serverId, queryport);
processId = await startServer(
event,
serverId,
queryport,
serverInfo.UseIndependentProcess,
);
} catch (e) {
// 伺服器被提早關閉
// Error: kill ESRCH
Expand Down Expand Up @@ -174,6 +184,7 @@ const startServer = async (
event: IpcMainEvent,
serverId: string,
queryport: number,
useIndependentProcess: boolean,
) => {
const serverInfo = await getServerInfoByServerId(serverId);
const serverPath = path.join(USER_SERVER_INSTANCES_PATH, serverId, 'server');
Expand All @@ -187,7 +198,9 @@ const startServer = async (

const palserver = `${path.join(
serverPath,
'Pal/Binaries/Win64/PalServer-Win64-Shipping.exe',
useIndependentProcess
? 'PalServer.exe'
: 'Pal/Binaries/Win64/PalServer-Win64-Shipping.exe',
)}`;

const palserverStream = spawn(palserver, [
Expand All @@ -202,6 +215,8 @@ const startServer = async (
serverInfo.performanceOptimizationEnabled ? '-UseMultithreadForDS' : '',
]);



const processId = palserverStream.pid;

// ps_tree(processId, (err, children) => {
Expand Down
1 change: 1 addition & 0 deletions src/main/ipcs/server/instance/createServerInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ ipcMain.handle(
openToCommunity: false,
OnlineMapEnabled: false,
LogEnabled: true,
UseIndependentProcess: false,
};
fs.writeFile(
serverInstanceSettingPath,
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function Link(props: {
>
<RLink
onClick={() => {
window.electron.openLink(props.href);
window.electron.openLink(props.href || '');
}}
color="blue"
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import useIsRunningServers from '../../../redux/isRunningServers/useIsRunningSer
import CongratBootServerAlert from './CongratBootServerAlert/CongratBootServerAlert';
import { AlertDialog, ContextMenu } from '@radix-ui/themes';
import useLocalState from '../../../hooks/useLocalState';
import useServerInfo from '../../../hooks/server/info/useServerInfo';

export default function BootServerButton() {
const { t } = useTranslation();
Expand All @@ -18,6 +19,8 @@ export default function BootServerButton() {
isRunningServers,
} = useIsRunningServers();

const { serverInfo } = useServerInfo(selectedServerInstance);

const isServerRunning = includeRunningServers(selectedServerInstance);

const handleBootServer = () => {
Expand Down Expand Up @@ -72,10 +75,22 @@ export default function BootServerButton() {
return (
<div>
<AlertDialog.Trigger
onClick={isServerRunning ? handleShutDownServer : handleBootServer}
onClick={
isServerRunning
? serverInfo?.UseIndependentProcess
? () => {}
: handleShutDownServer
: handleBootServer
}
>
<div className="w-full h-10 bg-gray-200 hover:bg-slate-50 text-bg1 rounded-lg flex items-center justify-center select-none cursor-pointer">
{isServerRunning ? t('CloseServer') : t('BootServer')}
{serverInfo?.UseIndependentProcess
? isServerRunning
? t('ServerIsRunning')
: t('BootServer')
: isServerRunning
? t('CloseServer')
: t('BootServer')}
</div>
</AlertDialog.Trigger>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/* eslint-disable global-require */

import { Box, Button, IconButton, Text, Theme } from '@radix-ui/themes';
import React from 'react';
import React, { useState } from 'react';
import useServerOnlinePlayers from '../../../../hooks/server/players/useServerOnlinePlayers';
import useSelectedServerInstance from '../../../../redux/selectedServerInstance/useSelectedServerInstance';
import _ from 'lodash';
import useTranslation from '../../../../hooks/translation/useTranslation';
import { MdOutlineMoreVert } from 'react-icons/md';
import PlayerMoreAction from '../PlayerMoreAction/PlayerMoreAction';
import Channels from '../../../../../main/ipcs/channels';
import { PiEye, PiEyeClosed } from 'react-icons/pi';

export default function PlayerPreview({
playerIndex,
Expand All @@ -18,9 +19,15 @@ export default function PlayerPreview({
const { t } = useTranslation();

const { selectedServerInstance } = useSelectedServerInstance();

const players = useServerOnlinePlayers(selectedServerInstance);
const player = players[playerIndex] || {};

// eslint-disable-next-line no-use-before-define
const location = getInGameLocation(player.location_x, player.location_y);

const [showPlayerSteamId, setShowPlayerSteamId] = useState(false);

const handleKickPlayer = () => {
window.electron.ipcRenderer.invoke(
Channels.sendRCONCommand,
Expand All @@ -36,11 +43,9 @@ export default function PlayerPreview({
);
};

const location = getInGameLocation(player.location_x, player.location_y);

return (
_.isEmpty(player) || (
<div className="flex flex-col p-4">
<div className="flex flex-col p-3.5 h-fit">
<div className="flex items-center gap-4">
<img
className="w-12 h-12 rounded-full"
Expand All @@ -60,10 +65,19 @@ export default function PlayerPreview({
size="2"
color="gray"
>
{player.userId
?.replace(player.userId.substring(11, 18), '*******')
.slice(6)}
{showPlayerSteamId
? player.userId
?.replace(player.userId.substring(11, 18), '*******')
.slice(6)
: player.userId.slice(6)}
</Text>
<div
onClick={() => {
setShowPlayerSteamId(!showPlayerSteamId);
}}
>
{showPlayerSteamId ? <PiEye /> : <PiEyeClosed />}
</div>
</div>
<Text as="div" size="2" color="gray">
Lv {player.level} .{' '}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ export default function ServerPlayers() {
<div className="w-full h-full mt-4 flex">
{players.length ? (
<div className="w-full flex justify-between pr-4">
<div className="w-full h-[calc(100vh-180px)] overflow-y-scroll flex flex-wrap gap-4">
<div className="w-full h-[calc(100vh-180px)] overflow-y-scroll flex flex-col gap-4">
{players.map((player, i) => (
<PlayerPreview playerIndex={i} />
<>
<PlayerPreview playerIndex={i} />
</>
))}
{/* <div className="flex flex-col gap-1">
{players.map((player, i) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export default function ServerSettings() {
},
},
PerformanceMonitorEnabled: {
hidden: serverInfo?.UseIndependentProcess,
id: 'PerformanceMonitorEnabled',
title: t('PerformanceMonitorEnabled'),
desciption: t('PerformanceMonitorEnabledDesc'),
Expand Down Expand Up @@ -416,6 +417,20 @@ export default function ServerSettings() {
// },
// },
},
Process: {
UseIndependentProcess: {
id: 'UseIndependentProcess',
title: t('UseIndependentProcess'),
desciption: t('UseIndependentProcessDesc'),
value: serverInfo?.UseIndependentProcess,
onValueChange(v) {
setServerInfo({
...serverInfo!,
UseIndependentProcess: v,
});
},
},
},
OtherExtensions: {
LogEnabled: {
id: 'LogEnabled',
Expand Down
16 changes: 12 additions & 4 deletions src/renderer/components/Version.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ export default function Version() {
<span className="font-mono">
{ENV} - {VERSION} ({PLATFORM}){' '}
</span>
{/* {latestVersionValue > currentVersionValue ? (
<Link color="sky">
{latestVersionValue > currentVersionValue ? (
<Link
appearance="dark"
href={`https://github.com/Dalufishe/palserver-GUI/releases/tag/${latestVersion}`}
>
{formatLocale(t('NewUpdate'), [latestVersion])}
</Link>
) : (
<Link color="sky">{t('UpdateLog')}</Link>
)} */}
<Link
appearance="dark"
href={`https://github.com/Dalufishe/palserver-GUI/releases/tag/${VERSION}`}
>
{t('UpdateLog')}
</Link>
)}
</div>
<div>
Made by{' '}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/hooks/firebase/useOnlineLinksMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { doc, getDoc } from 'firebase/firestore';

const useOnlineLinksMap = (id: string) => {
const { data: link } = useQuery(
'online-links-map',
['online-links-map', id],
async () => {
const docRef = doc(db.Links, id);
const docSnap = await getDoc(docRef);
Expand All @@ -26,4 +26,4 @@ const useOnlineLinksMap = (id: string) => {
return link;
};

export default useOnlineLinksMap
export default useOnlineLinksMap;
17 changes: 9 additions & 8 deletions src/renderer/pages/ServerManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,15 @@ export default function ServerManagement() {
{t('OnlineMap')}
</Tabs.Trigger>
)}
{serverInfo?.performanceMonitorEnabled && (
<Tabs.Trigger
value="performance"
style={{ color: 'white', fontWeight: 500 }}
>
{t('PerformanceMonitor')}
</Tabs.Trigger>
)}
{!serverInfo?.UseIndependentProcess &&
serverInfo?.performanceMonitorEnabled && (
<Tabs.Trigger
value="performance"
style={{ color: 'white', fontWeight: 500 }}
>
{t('PerformanceMonitor')}
</Tabs.Trigger>
)}
<Tabs.Trigger
value="settings"
style={{ color: 'white', fontWeight: 500 }}
Expand Down
2 changes: 1 addition & 1 deletion src/types/ServerInstanceSetting.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export type ServerInstanceSetting = {
readonly openToCommunity: boolean;
readonly OnlineMapEnabled: boolean;
readonly LogEnabled: boolean;
readonly AutoBoardcast: number;
readonly UseIndependentProcess: boolean;
};

0 comments on commit cd4b4c7

Please sign in to comment.