Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: define extra globalThis properties #2902

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
4 changes: 0 additions & 4 deletions react/src/components/BAIErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ const BAIErrorBoundary: React.FC<BAIErrorBoundaryProps> = ({ ...props }) => {
type="primary"
key="console"
onClick={() => {
// @ts-ignore
if (globalThis.isElectron) {
// @ts-ignore
globalThis.location.href = globalThis.electronInitialHref;
} else {
globalThis.location.reload();
Expand Down Expand Up @@ -89,9 +87,7 @@ export const ErrorView = () => {
type="primary"
key="console"
onClick={() => {
// @ts-ignore
if (globalThis.isElectron) {
// @ts-ignore
globalThis.location.href = globalThis.electronInitialHref;
} else {
globalThis.location.reload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,10 @@ const getWSProxyVersion = async (
) => {
// TODO: remove globalThis.appLauncher(backend-ai-app-launcher) dependency after migration to React
if (baiClient.debug === true) {
// @ts-ignore
if (globalThis.appLauncher?.forceUseV1Proxy?.checked) return 'v1';
// @ts-ignore
else if (globalThis.appLauncher?.forceUseV2Proxy?.checked) return 'v2';
}

// @ts-ignore
if (globalThis.isElectron) {
return 'v1';
}
Expand Down
2 changes: 0 additions & 2 deletions react/src/components/LoginSessionExtendButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ const LoginSessionExtendButton: React.FC<
const duration = dayjs.duration(Math.max(0, diff), 'seconds');
const days = Math.floor(duration.asDays());
if (duration.asSeconds() <= 0) {
// @ts-ignore
if (globalThis.isElectron) {
// @ts-ignore
globalThis.location.href = globalThis.electronInitialHref;
} else {
globalThis.location.reload();
Expand Down
1 change: 0 additions & 1 deletion react/src/hooks/useThemeMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export const ThemeModeProvider: React.FC<PropsWithChildren> = ({
} else {
document.body.classList.remove('dark-theme');
}
// @ts-ignore
globalThis.isDarkMode = value;

document.dispatchEvent(
Expand Down
3 changes: 1 addition & 2 deletions react/src/pages/SessionLauncherPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,7 @@ const SessionLauncherPage = () => {

// only launch app when it has valid service ports
if (service_info.length > 0) {
// @ts-ignore
globalThis.appLauncher.showLauncher(appOptions);
globalThis.appLauncher.showLauncher?.(appOptions);
}
}
},
Expand Down
30 changes: 14 additions & 16 deletions react/src/pages/UserSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SSHKeypairManagementModal from '../components/SSHKeypairManagementModal';
import { SettingItemProps } from '../components/SettingItem';
import SettingList from '../components/SettingList';
import ShellScriptEditModal from '../components/ShellScriptEditModal';
import { filterEmptyItem } from '../helper';
import {
useBAISettingGeneralState,
useBAISettingUserState,
Expand Down Expand Up @@ -53,7 +54,7 @@ const UserPreferencesPage = () => {
const settingGroup: { title: string; settingItems: SettingItemProps[] }[] = [
{
title: t('usersettings.Preferences'),
settingItems: [
settingItems: filterEmptyItem([
{
type: 'checkbox',
title: t('usersettings.DesktopNotification'),
Expand Down Expand Up @@ -126,22 +127,19 @@ const UserPreferencesPage = () => {
console.log(globalThis.backendaioptions.get('selected_language'));
},
},
...[
globalThis.isElectron && {
type: 'checkbox',
title: t('usersettings.KeepLoginSessionInformation'),
description: (
<Trans i18nKey="usersettings.DescKeepLoginSessionInformation" />
),
defaultValue: false,
//@ts-ignore
globalThis.isElectron && {
type: 'checkbox',
title: t('usersettings.KeepLoginSessionInformation'),
description: (
<Trans i18nKey="usersettings.DescKeepLoginSessionInformation" />
),
defaultValue: false,
//@ts-ignore
value: preserveLogin,
onChange: (e: any) => {
setPreserveLogin(e.target.checked);
},
value: preserveLogin,
onChange: (e: any) => {
setPreserveLogin(e.target.checked);
},
].filter(Boolean),
},
{
type: 'checkbox',
title: t('usersettings.AutomaticUpdateCheck'),
Expand Down Expand Up @@ -202,7 +200,7 @@ const UserPreferencesPage = () => {
setIsClassicSessionLauncher(e.target.checked);
},
},
],
]),
},
{
title: t('usersettings.ShellEnvironments'),
Expand Down
22 changes: 20 additions & 2 deletions react/src/react-app-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,27 @@ type ArgumentTypes<F extends Function> = F extends (...args: infer A) => any
? A
: never;

//TODO: fix this declaration for globalThis. It's not working.
declare global {
declare module globalThis {
var isDarkMode: boolean;
var isElectron: boolean;
var electronInitialHref: string;
var appLauncher: {
showLauncher?: (sessionId: {
'session-name'?: string;
'session-uuid'?: string;
'access-key'?: string;
mode?: SessionMode;
'app-services'?: Array<string>;
runtime?: string;
filename?: string;
}) => void;
forceUseV1Proxy?: {
checked: boolean;
};
forceUseV2Proxy?: {
checked: boolean;
};
};
}

type DeepPartial<T> = {
Expand Down