Skip to content

Commit

Permalink
✨ Option To Disable 3rd Party
Browse files Browse the repository at this point in the history
  • Loading branch information
snaildos committed Aug 7, 2022
1 parent 78036a5 commit 5511639
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"typescript-plugin-styled-components": "2.0.0",
"webpack": "5.68.0",
"webpack-bundle-analyzer": "4.5.0",
"webpack-cli": "4.9.2",
"webpack-cli": "4.10.0",
"webpack-dev-server": "4.9.3",
"webpack-merge": "5.8.0",
"x-default-browser": "0.4.0"
Expand Down
6 changes: 5 additions & 1 deletion src/constants/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const DEFAULT_SETTINGS: ISettings = {
type: 'empty',
},
warnOnQuit: false,
version: 3,
version: 4,
downloadsDialog: false,
downloadsPath: app
? app.getPath('downloads')
Expand All @@ -59,6 +59,10 @@ export const DEFAULT_SETTINGS: ISettings = {
: app
? app.getPath('downloads')
: '',
newtab: {
news: false,
weather: false,
},
doNotTrack: true,
globalPrivacyControl: true,
topBarVariant: 'default',
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export interface ISettings {
topSites: boolean;
pinned: boolean;
};
newtab: {
news: boolean;
weather: boolean
};
searchEngines: ISearchEngine[];
startupBehavior: IStartupBehavior;
warnOnQuit: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/views/menu/components/QuickMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export const QuickMenu = observer(() => {
<Line />
<MenuItem onClick={onCloseClick}>
<Icon icon={ICON_CLOSE} />
<MenuItemTitle>Close</MenuItemTitle>
<MenuItemTitle>Quit</MenuItemTitle>
<Shortcut>Ctrl+W</Shortcut>
</MenuItem>
</MenuItems>
Expand Down
11 changes: 8 additions & 3 deletions src/renderer/views/newtab/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,26 @@ const onRefreshClick = () => {
};

const Time = () => {
// const getDate = () => { setInterval(() => { return new Date().toLocaleTimeString([], { timeStyle: 'long' }) }, 100); }
return (
<StyledTime>
<h1>{new Date().toLocaleTimeString([], { timeStyle: 'short' })}</h1>
<h1>{ new Date().toLocaleTimeString([], { timeStyle: 'short' }) }</h1>
</StyledTime>
);
};

const Forecast = () => {
const { data: forecast } = useQuery(['weather'], async () => {
if (store.isweather == true) {
try {
const res = await (await fetch(`https://wttr.in/?format=%c%20%C`)).text();
return res;
} catch {
return 'Failed to load weather :(';
}
} else {
return 'Weather disabled';
}
});

return (
Expand Down Expand Up @@ -100,14 +105,14 @@ export default observer(() => {
<Image src={store.imageVisible ? store.image : ''}></Image>
<Content>
<Time />
<Forecast />
{store.isweather && <Forecast />}
{store.topSitesVisible && <TopSites></TopSites>}
</Content>

<RightBar>
<IconItem
imageSet={store.imageVisible}
title="Configure landing page"
title="Configure newtab page"
icon={ICON_TUNE}
onMouseDown={(e) => e.stopPropagation()}
onClick={onTuneClick}
Expand Down
24 changes: 18 additions & 6 deletions src/renderer/views/newtab/components/Preferences/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
} from '~/renderer/components/ContextMenu';
import { Switch } from '~/renderer/components/Switch';
import { Dropdown } from '~/renderer/components/Dropdown';

import { newTabSwitchChange } from '../../../settings/utils/settings';
import settingstore from '../../../settings/store/index';
import store, { Preset } from '../../store';
import { ICON_WINDOW, ICON_BACK, ICON_REFRESH } from '~/renderer/constants';

Expand All @@ -39,9 +40,6 @@ const onPresetClick = (name: Preset) => () => {
store.preset = name;
};

const getWebUIURL = (hostname: string) =>
`${WEBUI_BASE_URL}${hostname}${WEBUI_URL_SUFFIX}`;

const onRefreshImageClick = () => {
store.image = '';
setTimeout(() => {
Expand All @@ -51,6 +49,18 @@ const onRefreshImageClick = () => {
}, 50);
};


const NewsToggle = observer(() => {
const { news } = settingstore.settings.newtab;

return (
<ContextMenuItem bigger onClick={newTabSwitchChange('news')}>
<div style={{ flex: 1 }}>Disable News</div>
<Switch value={news}></Switch>
</ContextMenuItem>
);
});

export const SwitchItem = observer(
({
children,
Expand Down Expand Up @@ -161,7 +171,7 @@ export const Preferences = observer(() => {
pointerEvents:
store.preferencesContent === 'custom' ? 'inherit' : 'none',
transition: '0.3s max-height, 0.3s transform, 0.3s opacity',
maxHeight: store.preferencesContent === 'custom' ? 390 : 200,
maxHeight: store.preferencesContent === 'custom' ? 420 : 200,
transform:
store.preferencesContent === 'custom'
? 'translateX(-100%)'
Expand Down Expand Up @@ -198,8 +208,10 @@ export const Preferences = observer(() => {
<Dropdown.Item value="hidden">Hidden</Dropdown.Item>
<Dropdown.Item value="on-scroll">Visible on scroll</Dropdown.Item>
</Dropdown>
<ContextMenuSeparator bigger></ContextMenuSeparator>
<NewsToggle />
</div>
</div>
</ContextMenu>
);
});
});
14 changes: 14 additions & 0 deletions src/renderer/views/newtab/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ export class Store {
return getTheme(this.settings.theme);
}

@computed
public get isnews() {
return this.settings.newtab.news;
}

@computed
public get isweather() {
return this.settings.newtab.weather;
}


@observable
public news: INewsItem[] = [];

Expand Down Expand Up @@ -250,6 +261,7 @@ export class Store {

public async loadNews() {
// const randompage = Math.floor(Math.random() * 10) + 1;
if (this.isnews) {
const { data } = await networkMainChannel.getInvoker().request(`
https://github.win11react.com/NewsAPI/data.json
`); // ?lang=
Expand All @@ -260,6 +272,8 @@ export class Store {
} else {
throw new Error('Error fetching news');
}
}
throw new Error('News is disabled in settings.');
}

public async loadTopSites() {
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/views/settings/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Appearance } from '../Appearance';
import { AddressBar, ManageSearchEngines } from '../AddressBar';
import { Privacy } from '../Privacy';
import { About } from '../About';
import { Party } from '../Party';
import { Other } from '../Other';
import store from '../../store';
import { NavigationDrawer } from '~/renderer/components/NavigationDrawer';
Expand All @@ -29,6 +30,7 @@ import {
ICON_TRASH,
ICON_EDIT,
ICON_ADD,
ICON_DASHBOARD
} from '~/renderer/constants';
import {
ContextMenuItem,
Expand Down Expand Up @@ -262,6 +264,9 @@ export default observer(() => {
<MenuItem icon={ICON_SHIELD} section="privacy">
Privacy
</MenuItem>
<MenuItem icon={ICON_DASHBOARD} section="party">
Third Party
</MenuItem>
<MenuItem icon={ICON_FIRE} section="about">
About
</MenuItem>
Expand All @@ -287,6 +292,7 @@ export default observer(() => {
{selectedSection === 'about' && <About />}
{selectedSection === 'other' && <Other />}
{selectedSection === 'downloads' && <Downloads />}
{selectedSection === 'party' && <Party />}
</LeftContent>
</Content>
</Container>
Expand Down
55 changes: 55 additions & 0 deletions src/renderer/views/settings/components/Party/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* Copyright (c) 2021-2022 SnailDOS */

import * as React from 'react';

import { Header, Row, Title, Control } from '../App/style';
import store from '../../store';
import { BLUE_500, RED_500 } from '~/renderer/constants';
import { observer } from 'mobx-react-lite';
import { newTabSwitchChange } from '../../utils';
import { Switch } from '~/renderer/components/Switch';


const WeatherToggle = observer(() => {
const { weather } = store.settings.newtab;

return (
<Row onClick={newTabSwitchChange('weather')}>
<Title>
Allow the weather network request on the newtab screen (wttr.in)
</Title>
<Control>
<Switch value={weather} />
</Control>
</Row>
);
});

const NewsToggle = observer(() => {
const { news } = store.settings.newtab;

return (
<Row onClick={newTabSwitchChange('news')}>
<Title>
Allow the news network request on the newtab screen
</Title>
<Control>
<Switch value={news} />
</Control>
</Row>
);
});


export const Party = () => {
return (
<>
<Header>Third Party Services</Header>
<span>Fifo offers an easy way to block and allow third party services that are optional to the user that may use their private infomation for unique features.</span>
<Row>
</Row>
<NewsToggle />
<WeatherToggle />
</>
);
};
5 changes: 5 additions & 0 deletions src/renderer/views/settings/utils/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ export const onSwitchChange = (key: string) => () => {
(store.settings as any)[key] = !(store.settings as any)[key];
store.save();
};

export const newTabSwitchChange = (key: string) => () => {
(store.settings.newtab as any)[key] = !(store.settings.newtab as any)[key];
store.save();
};

0 comments on commit 5511639

Please sign in to comment.