Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/origine2/src/components/Assets/Assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import Upload from './Upload';
import naturalCompare from 'natural-compare-lite';
import useEditorStore from '@/store/useEditorStore';
import useTrashFailedToast from '@/hooks/useTrashFailedToast';
import { isLocalBrowserHost } from '@/utils/isLocalBrowserHost';

export interface IFile {
extName: string;
Expand Down Expand Up @@ -136,6 +137,7 @@ export default function Assets({
const updateSortOrder = useEditorStore.use.updateSortOrder();
const isTrash = useEditorStore.use.isTrash();
const toastTrashFailed = useTrashFailedToast();
const canOpenLocalFolder = isLocalBrowserHost();

const currentPath = useValue([...basePath, ...selectedFilePath.slice(0, -1)]);
const currentFullPath = useMemo(() => [...rootPath, ...currentPath.value], [currentPath.value]);
Expand Down Expand Up @@ -589,7 +591,9 @@ export default function Assets({
<MenuPopover>
<MenuList>
<MenuItem icon={<ArrowSyncIcon />} onClick={handleRefresh}>{t`刷新`}</MenuItem>
<MenuItem icon={<FolderOpenIcon />} onClick={handleOpenFolder}>{t`在文件管理器中打开`}</MenuItem>
{canOpenLocalFolder && (
<MenuItem icon={<FolderOpenIcon />} onClick={handleOpenFolder}>{t`在文件管理器中打开`}</MenuItem>
)}
<Menu>
<MenuTrigger>
<MenuItem icon={<ArrowSortIcon />}>{t`排序方式`}</MenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import useSWR, { mutate } from 'swr';
import { t } from '@lingui/macro';
import useEditorStore from '@/store/useEditorStore';
import { getMigrationGuideUrl } from '@/utils/language';
import { isLocalBrowserHost } from '@/utils/isLocalBrowserHost';
import styles from './UserDataSettingsDialog.module.scss';

declare global {
Expand Down Expand Up @@ -72,6 +73,7 @@ export function UserDataSettingsPanel() {
const [busy, setBusy] = useState(false);
const language = useEditorStore.use.language();
const migrationGuideUrl = getMigrationGuideUrl(language);
const canOpenLocalFolder = isLocalBrowserHost();

useEffect(() => {
if (status) setTargetPath(status.configuredUserDataRoot);
Expand Down Expand Up @@ -207,17 +209,19 @@ export function UserDataSettingsPanel() {
{status.configRoot}
</div>
</div>
<div className={styles.actions}>
<Button icon={<FolderOpen20Regular />} onClick={() => openPath('active')}>
{t`打开用户数据目录`}
</Button>
<Button icon={<FolderOpen20Regular />} onClick={() => openPath('config')}>
{t`打开配置目录`}
</Button>
<Button icon={<FolderOpen20Regular />} onClick={() => openPath('app')}>
{t`打开安装目录`}
</Button>
</div>
{canOpenLocalFolder && (
<div className={styles.actions}>
<Button icon={<FolderOpen20Regular />} onClick={() => openPath('active')}>
{t`打开用户数据目录`}
</Button>
<Button icon={<FolderOpen20Regular />} onClick={() => openPath('config')}>
{t`打开配置目录`}
</Button>
<Button icon={<FolderOpen20Regular />} onClick={() => openPath('app')}>
{t`打开安装目录`}
</Button>
</div>
)}
</div>

<div className={styles.section}>
Expand Down
12 changes: 8 additions & 4 deletions packages/origine2/src/pages/dashboard/GameElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { t } from '@lingui/macro';
import { GameInfoDto } from '@/api/Api';
import useEditorStore from '@/store/useEditorStore';
import useTrashFailedToast from '@/hooks/useTrashFailedToast';
import { isLocalBrowserHost } from '@/utils/isLocalBrowserHost';

interface IGameElementProps {
gameInfo: GameInfoDto;
Expand Down Expand Up @@ -74,6 +75,7 @@ export default function GameElement(props: IGameElementProps) {
const deleteChecked = useValue(false);
const isTrash = useEditorStore.use.isTrash();
const toastTrashFailed = useTrashFailedToast();
const canOpenLocalFolder = isLocalBrowserHost();

const openInFileExplorer = () => {
api.manageGameControllerOpenGameDict(props.gameInfo.dir);
Expand Down Expand Up @@ -130,10 +132,12 @@ export default function GameElement(props: IGameElementProps) {
</MenuTrigger>
<MenuPopover>
<MenuList>
<MenuItem
icon={<FolderOpenIcon />}
onClick={() => openInFileExplorer()}
>{t`在文件管理器中打开`}</MenuItem>
{canOpenLocalFolder && (
<MenuItem
icon={<FolderOpenIcon />}
onClick={() => openInFileExplorer()}
>{t`在文件管理器中打开`}</MenuItem>
)}
<MenuItem icon={<OpenIcon />} onClick={() => previewInNewTab()}>{t`在新标签页中预览`}</MenuItem>
<MenuItem
icon={<RenameIcon />}
Expand Down
12 changes: 8 additions & 4 deletions packages/origine2/src/pages/dashboard/TemplateElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { localStorageRename } from '@/utils/localStorageRename';
import { TemplateInfoDto } from '@/api/Api';
import useEditorStore from '@/store/useEditorStore';
import useTrashFailedToast from '@/hooks/useTrashFailedToast';
import { isLocalBrowserHost } from '@/utils/isLocalBrowserHost';

interface ITemplateElementProps {
templateInfo: TemplateInfoDto;
Expand Down Expand Up @@ -75,6 +76,7 @@ export default function TemplateElement(props: ITemplateElementProps) {
const newTemplateName = useValue(props.templateInfo.dir);
const isTrash = useEditorStore.use.isTrash();
const toastTrashFailed = useTrashFailedToast();
const canOpenLocalFolder = isLocalBrowserHost();

const openInFileExplorer = () => {
api.assetsControllerOpenDict(`templates/${props.templateInfo.dir}`);
Expand Down Expand Up @@ -146,10 +148,12 @@ export default function TemplateElement(props: ITemplateElementProps) {
</MenuTrigger>
<MenuPopover>
<MenuList>
<MenuItem
icon={<FolderOpenIcon />}
onClick={() => openInFileExplorer()}
>{t`在文件管理器中打开`}</MenuItem>
{canOpenLocalFolder && (
<MenuItem
icon={<FolderOpenIcon />}
onClick={() => openInFileExplorer()}
>{t`在文件管理器中打开`}</MenuItem>
)}
<MenuItem icon={<OpenIcon />} onClick={() => previewInNewTab()}>{t`在新标签页中预览`}</MenuItem>
<MenuItem
disabled={isBuiltIn}
Expand Down
4 changes: 4 additions & 0 deletions packages/origine2/src/utils/isLocalBrowserHost.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function isLocalBrowserHost(hostname = window.location.hostname): boolean {
const normalizedHostname = hostname.replace(/^\[|\]$/g, '').toLowerCase();
return normalizedHostname === 'localhost' || normalizedHostname === '::1' || /^127(?:\.\d{1,3}){3}$/.test(normalizedHostname);
}