Skip to content

Commit

Permalink
Merge branch 'main' into chore/electron-31
Browse files Browse the repository at this point in the history
  • Loading branch information
jgresham authored Jul 10, 2024
2 parents 2ca048f + 59b7b20 commit 74a7e42
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import {
setNativeThemeSetting,
setThemeSetting,
} from './state/settings';
import { getSetIsDeveloperModeEnabled } from './state/settings.js';
import store from './state/store';
import { getSystemInfo } from './systemInfo';

Expand Down Expand Up @@ -256,6 +257,12 @@ export const initialize = () => {
return getSetIsPreReleaseUpdatesEnabled(isPreReleaseUpdatesEnabled);
},
);
ipcMain.handle(
'getSetIsDeveloperModeEnabled',
(_event, isDeveloperModeEnabled?: boolean) => {
return getSetIsDeveloperModeEnabled(isDeveloperModeEnabled);
},
);

// Notifications
ipcMain.handle('getNotifications', getNotifications);
Expand Down
3 changes: 3 additions & 0 deletions src/main/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ contextBridge.exposeInMainWorld('electron', {
isPreReleaseUpdatesEnabled,
);
},
getSetIsDeveloperModeEnabled: (isDeveloperModeEnabled?: boolean) => {
ipcRenderer.invoke('getSetIsDeveloperModeEnabled', isDeveloperModeEnabled);
},

// Notifications
getNotifications: () => ipcRenderer.invoke('getNotifications'),
Expand Down
18 changes: 18 additions & 0 deletions src/main/state/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const APP_IS_OPEN_ON_STARTUP = 'appIsOpenOnStartup';
const APP_IS_NOTIFICATIONS_ENABLED = 'appIsNotificationsEnabled';
export const APP_IS_EVENT_REPORTING_ENABLED = 'appIsEventReportingEnabled';
const APP_IS_PRE_RELEASE_UPDATES_ENABLED = 'appIsPreReleaseUpdatesEnabled';
export const APP_IS_DEVELOPER_MODE_ENABLED = 'appIsDeveloperModeEnabled';

export type ThemeSetting = 'light' | 'dark' | 'auto';
export type Settings = {
Expand All @@ -37,6 +38,7 @@ export type Settings = {
[APP_IS_NOTIFICATIONS_ENABLED]?: boolean;
[APP_IS_EVENT_REPORTING_ENABLED]?: boolean;
[APP_IS_PRE_RELEASE_UPDATES_ENABLED]?: boolean;
[APP_IS_DEVELOPER_MODE_ENABLED]?: boolean;
};

/**
Expand Down Expand Up @@ -191,6 +193,22 @@ export const getSetIsPreReleaseUpdatesEnabled = (
return savedIsPreReleaseUpdatesEnabled;
};

export const getSetIsDeveloperModeEnabled = (
isDeveloperModeEnabled?: boolean,
) => {
if (isDeveloperModeEnabled !== undefined) {
logger.info(`Setting isDeveloperModeEnabled to ${isDeveloperModeEnabled}`);
store.set(
`${SETTINGS_KEY}.${APP_IS_DEVELOPER_MODE_ENABLED}`,
isDeveloperModeEnabled,
);
}
const savedIsDeveloperModeEnabled: boolean = store.get(
`${SETTINGS_KEY}.${APP_IS_DEVELOPER_MODE_ENABLED}`,
);
return savedIsDeveloperModeEnabled;
};

// listen to OS theme updates
nativeTheme.on('updated', () => {
console.log("nativeTheme.on('updated')");
Expand Down
25 changes: 25 additions & 0 deletions src/renderer/Presentational/DevMode/DevMode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useEffect, useState } from 'react';
import type { Settings } from '../../../main/state/settings.js';
import { useGetSettingsQuery } from '../../state/settingsService.js';

export const DevMode = ({ children }) => {
const [sIsVisible, setIsVisible] = useState(false);
const qSettings = useGetSettingsQuery();

useEffect(() => {
qSettings.refetch();
const settingsData = qSettings?.data as Settings;
// console.log('DEV MODE: settingsData', settingsData);
setIsVisible(settingsData?.appIsDeveloperModeEnabled === true);
}, [qSettings.data]);

if (sIsVisible) {
return (
<div style={{ border: 1, borderStyle: 'dashed' }}>
<span>👷</span>
{children}
</div>
);
}
return null;
};
4 changes: 4 additions & 0 deletions src/renderer/Presentational/ModalManager/PreferencesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const PreferencesModal = ({ modalOnClose }: Props) => {
isNotificationsEnabled,
isEventReportingEnabled,
isPreReleaseUpdatesEnabled,
isDeveloperModeEnabled,
language,
} = updatedConfig || (modalConfig as ModalConfig);

Expand Down Expand Up @@ -68,6 +69,9 @@ export const PreferencesModal = ({ modalOnClose }: Props) => {
reportEvent('DisablePreReleaseUpdates');
}
}
if (isDeveloperModeEnabled !== undefined) {
await electron.getSetIsDeveloperModeEnabled(isDeveloperModeEnabled);
}
if (language) {
await electron.setLanguage(language);
qSettings.refetch();
Expand Down
17 changes: 17 additions & 0 deletions src/renderer/Presentational/NodeScreen/NodeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useNavigate } from 'react-router-dom';

import { NodeStatus } from '../../../common/node';
import Button from '../../Generics/redesign/Button/Button';
import CopyButton from '../../Generics/redesign/CopyButton/CopyButton.js';
import { HeaderButton } from '../../Generics/redesign/HeaderButton/HeaderButton';
import type { NodeAction } from '../../Generics/redesign/consts';
import type { NodeBackgroundId } from '../../assets/images/nodeBackgrounds';
Expand All @@ -27,6 +28,7 @@ import { hexToDecimal } from '../../utils';
import ContentSingleClient, {
type SingleNodeContent,
} from '../ContentSingleClient/ContentSingleClient';
import { DevMode } from '../DevMode/DevMode.js';
import {
backButtonContainer,
container,
Expand Down Expand Up @@ -384,6 +386,21 @@ const NodeScreen = () => {
nodeOverview={nodeContent}
isPodmanRunning={isPodmanRunning}
/>
<p>Controller version: {spec?.version}</p>
<DevMode>
<div style={{ display: 'flex', gap: '10px' }}>
<span>Active Controller Json</span>
<CopyButton data={JSON.stringify(selectedNode, null, 2)} />
</div>
<div style={{ display: 'flex', gap: '10px' }}>
<span>Controller Config Json</span>
<CopyButton data={JSON.stringify(selectedNode.config, null, 2)} />
</div>
<div style={{ display: 'flex', gap: '10px' }}>
<span>Controller Json</span>
<CopyButton data={JSON.stringify(selectedNode.spec, null, 2)} />
</div>
</DevMode>
</>
);
};
Expand Down
21 changes: 21 additions & 0 deletions src/renderer/Presentational/Preferences/Preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type Preference =
| 'isNotificationsEnabled'
| 'isEventReportingEnabled'
| 'isPreReleaseUpdatesEnabled'
| 'isDeveloperModeEnabled'
| 'language';
export interface PreferencesProps {
themeSetting?: ThemeSetting;
Expand All @@ -43,6 +44,7 @@ export interface PreferencesProps {
isNotificationsEnabled?: boolean;
isEventReportingEnabled?: boolean;
isPreReleaseUpdatesEnabled?: boolean;
isDeveloperModeEnabled?: boolean;
version?: string;
language?: string;
onChange?: (preference: Preference, value: unknown) => void;
Expand All @@ -55,6 +57,7 @@ const Preferences = ({
isNotificationsEnabled,
isEventReportingEnabled,
isPreReleaseUpdatesEnabled,
isDeveloperModeEnabled,
version,
language,
onChange,
Expand Down Expand Up @@ -270,6 +273,24 @@ const Preferences = ({
/>
),
},
{
label: `${t('Developer mode')}`,
description: t(
'Show developer information throuhout the app marked by 👷',
),
value: (
<Toggle
onText={t('Enabled')}
offText={t('Disabled')}
checked={isDeveloperModeEnabled}
onChange={(newValue) => {
if (onChange) {
onChange('isDeveloperModeEnabled', newValue);
}
}}
/>
),
},
],
},
]}
Expand Down
12 changes: 12 additions & 0 deletions src/renderer/Presentational/Preferences/PreferencesWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const PreferencesWrapper = ({
useState<boolean>();
const [sIsPreReleaseUpdatesEnabled, setIsPreReleaseUpdatesEnabled] =
useState<boolean>();
const [sIsDeveloperModeEnabled, setIsDeveloperModeEnabled] =
useState<boolean>();
const [sNiceNodeVersion, setNiceNodeVersion] = useState<string>();
const [sLanguageSetting, setLanguageSetting] = useState<string>();

Expand All @@ -49,12 +51,15 @@ const PreferencesWrapper = ({
userSettings.appIsEventReportingEnabled || false;
const isPreReleaseUpdatesEnabled =
userSettings.appIsPreReleaseUpdatesEnabled || false;
const isDeveloperModeEnabled =
userSettings.appIsDeveloperModeEnabled || false;
setThemeSetting(themeSetting);
setOsIsDarkMode(osIsDarkMode);
setIsNotificationsEnabled(notificationsSetting);
setIsOpenOnStartup(isOpenAtStartupSetting);
setIsEventReportingEnabled(isEventReportingEnabled);
setIsPreReleaseUpdatesEnabled(isPreReleaseUpdatesEnabled);
setIsDeveloperModeEnabled(isDeveloperModeEnabled);
};

const getNiceNodeVersion = async () => {
Expand Down Expand Up @@ -122,6 +127,12 @@ const PreferencesWrapper = ({
modalOnChangeConfig({
isPreReleaseUpdatesEnabled,
});
} else if (preference === 'isDeveloperModeEnabled') {
const isDeveloperModeEnabled = value as boolean;
setIsDeveloperModeEnabled(isDeveloperModeEnabled);
modalOnChangeConfig({
isDeveloperModeEnabled,
});
} else if (preference === 'language') {
const language = value as string;
setLanguageSetting(language);
Expand All @@ -143,6 +154,7 @@ const PreferencesWrapper = ({
isNotificationsEnabled={sIsNotificationsEnabled}
isEventReportingEnabled={sIsEventReportingEnabled}
isPreReleaseUpdatesEnabled={sIsPreReleaseUpdatesEnabled}
isDeveloperModeEnabled={sIsDeveloperModeEnabled}
language={sLanguageSetting}
onChange={onChangePreference}
/>
Expand Down
1 change: 1 addition & 0 deletions src/renderer/preload.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ declare global {
getSetIsPreReleaseUpdatesEnabled(
isPreReleaseUpdatesEnabled?: boolean,
): void;
getSetIsDeveloperModeEnabled(isDeveloperModeEnabled?: boolean): void;

// Notifications
getNotifications(): any;
Expand Down

0 comments on commit 74a7e42

Please sign in to comment.