Skip to content

Commit

Permalink
Merge pull request #1482 from RoboSats/disable-android-notifications
Browse files Browse the repository at this point in the history
Manually disable android notifications
  • Loading branch information
KoalaSat authored Sep 18, 2024
2 parents 88c53d5 + 670bb1f commit 16eeb32
Show file tree
Hide file tree
Showing 28 changed files with 1,364 additions and 1,374 deletions.
12 changes: 10 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { StrictMode, Suspense } from 'react';
import ReactDOM from 'react-dom/client';
import Main from './basic/Main';
import { CssBaseline } from '@mui/material';
import { CssBaseline, Grid } from '@mui/material';
import HostAlert from './components/HostAlert';
import TorConnectionBadge from './components/TorConnection';

Expand All @@ -13,6 +13,7 @@ import ErrorBoundary from './components/ErrorBoundary';
import { AppContextProvider } from './contexts/AppContext';
import { GarageContextProvider } from './contexts/GarageContext';
import { FederationContextProvider } from './contexts/FederationContext';
import NotificationSwitchBadge from './components/NotificationSwitch';

const App = (): JSX.Element => {
const [client, _view] = window.RobosatsSettings.split('-');
Expand All @@ -25,7 +26,14 @@ const App = (): JSX.Element => {
<FederationContextProvider>
<GarageContextProvider>
<CssBaseline />
{client !== 'mobile' ? <HostAlert /> : <TorConnectionBadge />}
{client === 'mobile' ? (
<>
<TorConnectionBadge />
<NotificationSwitchBadge />
</>
) : (
<HostAlert />
)}
<Main />
</GarageContextProvider>
</FederationContextProvider>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Dialogs/Coordinator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ const CoordinatorDialog = ({ open = false, onClose, shortAlias }: Props): JSX.El
const { t } = useTranslation();
const { clientVersion, page, settings, origin } = useContext(AppContext);
const { federation } = useContext<UseFederationStoreType>(FederationContext);
const coordinator = federation.getCoordinator(shortAlias);
const coordinator = federation.getCoordinator(shortAlias ?? '');

const [expanded, setExpanded] = useState<'summary' | 'stats' | 'policies' | undefined>(undefined);

Expand Down
49 changes: 49 additions & 0 deletions frontend/src/components/NotificationSwitch/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React, { useContext, useEffect, useState } from 'react';
import { Box, CircularProgress, useTheme } from '@mui/material';
import { NotificationsActive, NotificationsOff } from '@mui/icons-material';
import { AppContext, UseAppStoreType } from '../../contexts/AppContext';
import { systemClient } from '../../services/System';

const NotificationSwitchBadge = (): JSX.Element => {
const { setSettings, settings, torStatus } = useContext<UseAppStoreType>(AppContext);
const theme = useTheme();

const [stopNotifications, setStopNotifications] = useState<boolean>(settings.stopNotifications);

useEffect(() => {
setStopNotifications(settings.stopNotifications);
}, [settings.stopNotifications]);

const onClick = () => {
if (torStatus === 'ON' || !settings.useProxy) {
setSettings({ ...settings, stopNotifications: !settings.stopNotifications });
systemClient.setItem('settings_stop_notifications', String(!settings.stopNotifications));
}
};

const style = {
width: 20,
height: 20,
color: stopNotifications ? theme.palette.secondary.main : theme.palette.primary.main,
};

return (
<Box sx={{ display: 'inline-flex', position: 'fixed', right: '0.5em', top: '0.5em' }}>
<Box>
{torStatus === 'ON' || !settings.useProxy ? (
<>
{stopNotifications ? (
<NotificationsOff sx={style} onClick={onClick} />
) : (
<NotificationsActive sx={style} onClick={onClick} />
)}
</>
) : (
<CircularProgress thickness={6} size={22} />
)}
</Box>
</Box>
);
};

export default NotificationSwitchBadge;
97 changes: 0 additions & 97 deletions frontend/src/components/TorConnection.tsx

This file was deleted.

10 changes: 3 additions & 7 deletions frontend/src/components/TorConnection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useContext } from 'react';
import { Box, CircularProgress, Tooltip } from '@mui/material';
import { TorIcon } from '../Icons';
import { useTranslation } from 'react-i18next';
import { AppContext, type AppContextProps } from '../contexts/AppContext';
import { AppContext, UseAppStoreType } from '../../contexts/AppContext';

interface TorIndicatorProps {
color: 'inherit' | 'error' | 'warning' | 'success' | 'primary' | 'secondary' | 'info' | undefined;
Expand Down Expand Up @@ -55,14 +55,10 @@ const TorIndicator = ({
};

const TorConnectionBadge = (): JSX.Element => {
const { torStatus } = useContext<AppContextProps>(AppContext);
const { torStatus } = useContext<UseAppStoreType>(AppContext);
const { t } = useTranslation();

if (window?.NativeRobosats == null) {
return <></>;
}

if (torStatus === 'OFF' || torStatus === 'STOPING') {
if (torStatus === 'OFF' || torStatus === 'STOPPING') {
return (
<TorIndicator
color='primary'
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/models/Settings.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ class BaseSettings {
this.network = networkCookie && networkCookie !== '' ? networkCookie : 'mainnet';
this.host = getHost();

const useProxy = systemClient.getItem('settings_use_proxy');

const [client, _view] = window.RobosatsSettings.split('-');
this.useProxy = client === 'mobile' && useProxy !== 'false';

const stopNotifications = systemClient.getItem('settings_stop_notifications');
this.stopNotifications = client === 'mobile' && stopNotifications === 'true';

const useProxy = systemClient.getItem('settings_use_proxy');
this.useProxy = client === 'mobile' && useProxy !== 'false';
apiClient.useProxy = this.useProxy;
}

Expand All @@ -65,6 +67,7 @@ class BaseSettings {
public unsafeClient: boolean = false;
public selfhostedClient: boolean = false;
public useProxy: boolean;
public stopNotifications: boolean;
}

export default BaseSettings;
Loading

0 comments on commit 16eeb32

Please sign in to comment.