Migrate all isElectron to use main-axios.
This commit is contained in:
@@ -5,6 +5,7 @@ import DesktopApp from './ui/Desktop/DesktopApp.tsx'
|
|||||||
import { MobileApp } from './ui/Mobile/MobileApp.tsx'
|
import { MobileApp } from './ui/Mobile/MobileApp.tsx'
|
||||||
import {ThemeProvider} from "@/components/theme-provider"
|
import {ThemeProvider} from "@/components/theme-provider"
|
||||||
import './i18n/i18n'
|
import './i18n/i18n'
|
||||||
|
import {isElectron} from './ui/main-axios.ts'
|
||||||
|
|
||||||
function useWindowWidth() {
|
function useWindowWidth() {
|
||||||
const [width, setWidth] = useState(window.innerWidth);
|
const [width, setWidth] = useState(window.innerWidth);
|
||||||
@@ -52,9 +53,7 @@ function useWindowWidth() {
|
|||||||
function RootApp() {
|
function RootApp() {
|
||||||
const width = useWindowWidth();
|
const width = useWindowWidth();
|
||||||
const isMobile = width < 768;
|
const isMobile = width < 768;
|
||||||
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
if (isElectron()) {
|
||||||
|
|
||||||
if (isElectron) {
|
|
||||||
return <DesktopApp />;
|
return <DesktopApp />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ import {
|
|||||||
makeUserAdmin,
|
makeUserAdmin,
|
||||||
removeAdminStatus,
|
removeAdminStatus,
|
||||||
deleteUser,
|
deleteUser,
|
||||||
getCookie
|
getCookie,
|
||||||
|
isElectron
|
||||||
} from "@/ui/main-axios.ts";
|
} from "@/ui/main-axios.ts";
|
||||||
|
|
||||||
interface AdminSettingsProps {
|
interface AdminSettingsProps {
|
||||||
@@ -75,8 +76,7 @@ export function AdminSettings({isTopbarOpen = true}: AdminSettingsProps): React.
|
|||||||
if (!jwt) return;
|
if (!jwt) return;
|
||||||
|
|
||||||
// Check if we're in Electron and have a server configured
|
// Check if we're in Electron and have a server configured
|
||||||
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
if (isElectron()) {
|
||||||
if (isElectron) {
|
|
||||||
// In Electron, check if we have a configured server
|
// In Electron, check if we have a configured server
|
||||||
const serverUrl = (window as any).configuredServerUrl;
|
const serverUrl = (window as any).configuredServerUrl;
|
||||||
if (!serverUrl) {
|
if (!serverUrl) {
|
||||||
@@ -101,8 +101,7 @@ export function AdminSettings({isTopbarOpen = true}: AdminSettingsProps): React.
|
|||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
// Check if we're in Electron and have a server configured
|
// Check if we're in Electron and have a server configured
|
||||||
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
if (isElectron()) {
|
||||||
if (isElectron) {
|
|
||||||
const serverUrl = (window as any).configuredServerUrl;
|
const serverUrl = (window as any).configuredServerUrl;
|
||||||
if (!serverUrl) {
|
if (!serverUrl) {
|
||||||
console.log('No server configured in Electron, skipping registration status check');
|
console.log('No server configured in Electron, skipping registration status check');
|
||||||
@@ -130,8 +129,7 @@ export function AdminSettings({isTopbarOpen = true}: AdminSettingsProps): React.
|
|||||||
if (!jwt) return;
|
if (!jwt) return;
|
||||||
|
|
||||||
// Check if we're in Electron and have a server configured
|
// Check if we're in Electron and have a server configured
|
||||||
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
if (isElectron()) {
|
||||||
if (isElectron) {
|
|
||||||
const serverUrl = (window as any).configuredServerUrl;
|
const serverUrl = (window as any).configuredServerUrl;
|
||||||
if (!serverUrl) {
|
if (!serverUrl) {
|
||||||
console.log('No server configured in Electron, skipping user fetch');
|
console.log('No server configured in Electron, skipping user fetch');
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {Unicode11Addon} from '@xterm/addon-unicode11';
|
|||||||
import {WebLinksAddon} from '@xterm/addon-web-links';
|
import {WebLinksAddon} from '@xterm/addon-web-links';
|
||||||
import {useTranslation} from 'react-i18next';
|
import {useTranslation} from 'react-i18next';
|
||||||
import {toast} from 'sonner';
|
import {toast} from 'sonner';
|
||||||
import {getCookie} from '@/ui/main-axios.ts';
|
import {getCookie, isElectron} from '@/ui/main-axios.ts';
|
||||||
|
|
||||||
interface SSHTerminalProps {
|
interface SSHTerminalProps {
|
||||||
hostConfig: any;
|
hostConfig: any;
|
||||||
@@ -197,7 +197,6 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
|
|||||||
const isDev = process.env.NODE_ENV === 'development' &&
|
const isDev = process.env.NODE_ENV === 'development' &&
|
||||||
(window.location.port === '3000' || window.location.port === '5173' || window.location.port === '');
|
(window.location.port === '3000' || window.location.port === '5173' || window.location.port === '');
|
||||||
|
|
||||||
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
|
||||||
|
|
||||||
const wsUrl = isDev
|
const wsUrl = isDev
|
||||||
? 'ws://localhost:8082'
|
? 'ws://localhost:8082'
|
||||||
@@ -491,7 +490,6 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
|
|||||||
const isDev = process.env.NODE_ENV === 'development' &&
|
const isDev = process.env.NODE_ENV === 'development' &&
|
||||||
(window.location.port === '3000' || window.location.port === '5173' || window.location.port === '');
|
(window.location.port === '3000' || window.location.port === '5173' || window.location.port === '');
|
||||||
|
|
||||||
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
|
||||||
|
|
||||||
const wsUrl = isDev
|
const wsUrl = isDev
|
||||||
? 'ws://localhost:8082'
|
? 'ws://localhost:8082'
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
setCookie,
|
setCookie,
|
||||||
getCookie,
|
getCookie,
|
||||||
getServerConfig,
|
getServerConfig,
|
||||||
|
isElectron,
|
||||||
type ServerConfig
|
type ServerConfig
|
||||||
} from "../../main-axios.ts";
|
} from "../../main-axios.ts";
|
||||||
import {ServerConfig as ServerConfigComponent} from "@/ui/Desktop/ElectronOnly/ServerConfig.tsx";
|
import {ServerConfig as ServerConfigComponent} from "@/ui/Desktop/ElectronOnly/ServerConfig.tsx";
|
||||||
@@ -413,7 +414,7 @@ export function HomepageAuth({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const checkServerConfig = async () => {
|
const checkServerConfig = async () => {
|
||||||
if ((window as any).electronAPI) {
|
if (isElectron()) {
|
||||||
try {
|
try {
|
||||||
const config = await getServerConfig();
|
const config = await getServerConfig();
|
||||||
console.log('Desktop HomepageAuth - Server config check:', config);
|
console.log('Desktop HomepageAuth - Server config check:', config);
|
||||||
@@ -630,8 +631,7 @@ export function HomepageAuth({
|
|||||||
<p>{t('auth.loginWithExternalDesc')}</p>
|
<p>{t('auth.loginWithExternalDesc')}</p>
|
||||||
</div>
|
</div>
|
||||||
{(() => {
|
{(() => {
|
||||||
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
if (isElectron()) {
|
||||||
if (isElectron) {
|
|
||||||
return (
|
return (
|
||||||
<div className="text-center p-4 bg-muted/50 rounded-lg border">
|
<div className="text-center p-4 bg-muted/50 rounded-lg border">
|
||||||
<p className="text-muted-foreground text-sm">
|
<p className="text-muted-foreground text-sm">
|
||||||
@@ -871,7 +871,7 @@ export function HomepageAuth({
|
|||||||
</div>
|
</div>
|
||||||
<LanguageSwitcher />
|
<LanguageSwitcher />
|
||||||
</div>
|
</div>
|
||||||
{(window as any).electronAPI && currentServerUrl && (
|
{isElectron() && currentServerUrl && (
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<div>
|
<div>
|
||||||
<Label className="text-sm text-muted-foreground">Server</Label>
|
<Label className="text-sm text-muted-foreground">Server</Label>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
ChevronUp, User2, HardDrive, Menu, ChevronRight
|
ChevronUp, User2, HardDrive, Menu, ChevronRight
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import {getCookie, setCookie} from "@/ui/main-axios.ts";
|
import {getCookie, setCookie, isElectron} from "@/ui/main-axios.ts";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Sidebar,
|
Sidebar,
|
||||||
@@ -61,10 +61,6 @@ interface SidebarProps {
|
|||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isElectron() {
|
|
||||||
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
|
||||||
return isElectron;
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleLogout() {
|
function handleLogout() {
|
||||||
if (isElectron()) {
|
if (isElectron()) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {ClipboardAddon} from '@xterm/addon-clipboard';
|
|||||||
import {Unicode11Addon} from '@xterm/addon-unicode11';
|
import {Unicode11Addon} from '@xterm/addon-unicode11';
|
||||||
import {WebLinksAddon} from '@xterm/addon-web-links';
|
import {WebLinksAddon} from '@xterm/addon-web-links';
|
||||||
import {useTranslation} from 'react-i18next';
|
import {useTranslation} from 'react-i18next';
|
||||||
|
import {isElectron} from '@/ui/main-axios.ts';
|
||||||
|
|
||||||
interface SSHTerminalProps {
|
interface SSHTerminalProps {
|
||||||
hostConfig: any;
|
hostConfig: any;
|
||||||
@@ -215,11 +216,10 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
|
|||||||
const isDev = process.env.NODE_ENV === 'development' &&
|
const isDev = process.env.NODE_ENV === 'development' &&
|
||||||
(window.location.port === '3000' || window.location.port === '5173' || window.location.port === '');
|
(window.location.port === '3000' || window.location.port === '5173' || window.location.port === '');
|
||||||
|
|
||||||
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
|
||||||
|
|
||||||
const wsUrl = isDev
|
const wsUrl = isDev
|
||||||
? 'ws://localhost:8082'
|
? 'ws://localhost:8082'
|
||||||
: isElectron
|
: isElectron()
|
||||||
? (() => {
|
? (() => {
|
||||||
// Get configured server URL from window object (set by main-axios)
|
// Get configured server URL from window object (set by main-axios)
|
||||||
const baseUrl = (window as any).configuredServerUrl || 'http://127.0.0.1:8081';
|
const baseUrl = (window as any).configuredServerUrl || 'http://127.0.0.1:8081';
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ interface OIDCAuthorize {
|
|||||||
// UTILITY FUNCTIONS
|
// UTILITY FUNCTIONS
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
|
export function isElectron(): boolean {
|
||||||
|
return (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
||||||
|
}
|
||||||
|
|
||||||
function getLoggerForService(serviceName: string) {
|
function getLoggerForService(serviceName: string) {
|
||||||
if (serviceName.includes('SSH') || serviceName.includes('ssh')) {
|
if (serviceName.includes('SSH') || serviceName.includes('ssh')) {
|
||||||
return sshLogger;
|
return sshLogger;
|
||||||
@@ -92,9 +96,7 @@ function getLoggerForService(serviceName: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function setCookie(name: string, value: string, days = 7): void {
|
export function setCookie(name: string, value: string, days = 7): void {
|
||||||
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
if (isElectron()) {
|
||||||
|
|
||||||
if (isElectron) {
|
|
||||||
localStorage.setItem(name, value);
|
localStorage.setItem(name, value);
|
||||||
} else {
|
} else {
|
||||||
const expires = new Date(Date.now() + days * 864e5).toUTCString();
|
const expires = new Date(Date.now() + days * 864e5).toUTCString();
|
||||||
@@ -103,8 +105,7 @@ export function setCookie(name: string, value: string, days = 7): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getCookie(name: string): string | undefined {
|
export function getCookie(name: string): string | undefined {
|
||||||
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
if (isElectron()) {
|
||||||
if (isElectron) {
|
|
||||||
const token = localStorage.getItem(name) || undefined;
|
const token = localStorage.getItem(name) || undefined;
|
||||||
return token;
|
return token;
|
||||||
} else {
|
} else {
|
||||||
@@ -243,8 +244,7 @@ function createApiInstance(baseURL: string, serviceName: string = 'API'): AxiosI
|
|||||||
|
|
||||||
// Handle auth token clearing
|
// Handle auth token clearing
|
||||||
if (status === 401) {
|
if (status === 401) {
|
||||||
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
if (isElectron()) {
|
||||||
if (isElectron) {
|
|
||||||
localStorage.removeItem('jwt');
|
localStorage.removeItem('jwt');
|
||||||
} else {
|
} else {
|
||||||
document.cookie = 'jwt=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
|
document.cookie = 'jwt=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
|
||||||
@@ -263,7 +263,6 @@ function createApiInstance(baseURL: string, serviceName: string = 'API'): AxiosI
|
|||||||
// API INSTANCES
|
// API INSTANCES
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
const isElectron = (window as any).IS_ELECTRON === true || (window as any).electronAPI?.isElectron === true;
|
|
||||||
|
|
||||||
const isDev = process.env.NODE_ENV === 'development' &&
|
const isDev = process.env.NODE_ENV === 'development' &&
|
||||||
(window.location.port === '3000' || window.location.port === '5173' || window.location.port === '');
|
(window.location.port === '3000' || window.location.port === '5173' || window.location.port === '');
|
||||||
@@ -334,7 +333,7 @@ if (isElectron) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getApiUrl(path: string, defaultPort: number): string {
|
function getApiUrl(path: string, defaultPort: number): string {
|
||||||
if (isElectron) {
|
if (isElectron()) {
|
||||||
if (configuredServerUrl) {
|
if (configuredServerUrl) {
|
||||||
// In Electron with configured server, all requests go through nginx reverse proxy
|
// In Electron with configured server, all requests go through nginx reverse proxy
|
||||||
// Use the same base URL for all services (nginx routes to correct backend port)
|
// Use the same base URL for all services (nginx routes to correct backend port)
|
||||||
|
|||||||
Reference in New Issue
Block a user