mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-10 04:30:25 +02:00
refactor feature hooks to be conditionally initialized
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { SetActivity, StatusDisplayType } from '@xhayper/discord-rpc';
|
||||
import isElectron from 'is-electron';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||
|
||||
import { api } from '/@/renderer/api';
|
||||
import { useItemImageUrl } from '/@/renderer/components/item-image/item-image';
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
useLastfmApiKey,
|
||||
usePlayerSong,
|
||||
usePlayerStore,
|
||||
useSettingsStore,
|
||||
useTimestampStoreBase,
|
||||
} from '/@/renderer/store';
|
||||
import { sentenceCase } from '/@/renderer/utils';
|
||||
@@ -410,3 +411,21 @@ export const useDiscordRpc = () => {
|
||||
setActivity,
|
||||
]);
|
||||
};
|
||||
|
||||
const DiscordRpcHookInner = () => {
|
||||
useDiscordRpc();
|
||||
return null;
|
||||
};
|
||||
|
||||
export const DiscordRpcHook = () => {
|
||||
const isElectronEnv = isElectron();
|
||||
const isDiscordRpcEnabled = useSettingsStore((state) => state.discord.enabled);
|
||||
const isPrivateMode = useAppStore((state) => state.privateMode);
|
||||
const discordRpc = isElectronEnv ? window.api.discordRpc : null;
|
||||
|
||||
if (!isElectronEnv || !discordRpc || !isDiscordRpcEnabled || isPrivateMode) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return React.createElement(DiscordRpcHookInner);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user