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

feat: use favicons instead of icons #1734

Merged
merged 1 commit into from
May 3, 2024
Merged
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
1 change: 1 addition & 0 deletions src/components/settings/services/EditServiceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ class EditServiceForm extends Component<IProps, IState> {

<div className="settings__settings-group">
<H3>{intl.formatMessage(messages.headlineAppearance)}</H3>
<Toggle {...form.$('useFavicon').bind()} />
<Toggle {...form.$('isDarkModeEnabled').bind()} />
{form.$('isDarkModeEnabled').value && (
<>
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ export const DEFAULT_SERVICE_SETTINGS = {
isBadgeEnabled: true,
isMediaBadgeEnabled: false,
trapLinkClicks: false,
useFavicon: false,
isMuted: false,
customIcon: false,
isDarkModeEnabled: false,
Expand Down
13 changes: 13 additions & 0 deletions src/containers/settings/EditServiceScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ const messages = defineMessages({
id: 'settings.service.form.trapLinkClicks',
defaultMessage: 'Open URLs within Ferdium',
},
useFavicon: {
id: 'settings.service.form.useFavicon',
defaultMessage: 'Use service favicon instead of default or custom icon',
},
onlyShowFavoritesInUnreadCount: {
id: 'settings.service.form.onlyShowFavoritesInUnreadCount',
defaultMessage: 'Only show Favorites in unread count',
Expand Down Expand Up @@ -258,6 +262,15 @@ class EditServiceScreen extends Component<IProps> {
default: DEFAULT_SERVICE_SETTINGS.trapLinkClicks,
type: 'checkbox',
},
useFavicon: {
label: intl.formatMessage(messages.useFavicon),
value: ifUndefined<boolean>(
service?.useFavicon,
DEFAULT_SERVICE_SETTINGS.useFavicon,
),
default: DEFAULT_SERVICE_SETTINGS.useFavicon,
type: 'checkbox',
},
isMuted: {
label: intl.formatMessage(messages.enableAudio),
value: !ifUndefined<boolean>(
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/favicon-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function getFaviconUrl(url: string, size: number = 128): string {
return `https://www.google.com/s2/favicons?sz=${size}&domain_url=${url}`;
}
1 change: 1 addition & 0 deletions src/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@
"settings.service.form.tabOnPremise": "Self hosted ⭐️",
"settings.service.form.team": "Team",
"settings.service.form.trapLinkClicks": "Open URLs within Ferdium",
"settings.service.form.useFavicon": "Use service favicon instead of default or custom icon",
"settings.service.form.useHostedService": "Use the hosted {name} service.",
"settings.service.form.yourServices": "Your services",
"settings.service.reloadRequired": "Changes require reload of the service",
Expand Down
3 changes: 3 additions & 0 deletions src/internal-server/app/Controllers/Http/ServiceController.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class ServiceController {
isNotificationEnabled: DEFAULT_SERVICE_SETTINGS.isNotificationEnabled,
isBadgeEnabled: DEFAULT_SERVICE_SETTINGS.isBadgeEnabled,
trapLinkClicks: DEFAULT_SERVICE_SETTINGS.trapLinkClicks,
useFavicon: DEFAULT_SERVICE_SETTINGS.useFavicon,
isMuted: DEFAULT_SERVICE_SETTINGS.isMuted,
isDarkModeEnabled: '', // TODO: This should ideally be a boolean (false). But, changing it caused the sidebar toggle to not work.
isProgressbarEnabled: DEFAULT_SERVICE_SETTINGS.isProgressbarEnabled,
Expand Down Expand Up @@ -83,6 +84,7 @@ class ServiceController {
hasCustomIcon: DEFAULT_SERVICE_SETTINGS.hasCustomIcon,
isBadgeEnabled: DEFAULT_SERVICE_SETTINGS.isBadgeEnabled,
trapLinkClicks: DEFAULT_SERVICE_SETTINGS.trapLinkClicks,
useFavicon: DEFAULT_SERVICE_SETTINGS.useFavicon,
isDarkModeEnabled: '', // TODO: This should ideally be a boolean (false). But, changing it caused the sidebar toggle to not work.
isProgressbarEnabled: DEFAULT_SERVICE_SETTINGS.isProgressbarEnabled,
isEnabled: DEFAULT_SERVICE_SETTINGS.isEnabled,
Expand Down Expand Up @@ -232,6 +234,7 @@ class ServiceController {
hasCustomIcon: DEFAULT_SERVICE_SETTINGS.customIcon,
isBadgeEnabled: DEFAULT_SERVICE_SETTINGS.isBadgeEnabled,
trapLinkClicks: DEFAULT_SERVICE_SETTINGS.trapLinkClicks,
useFavicon: DEFAULT_SERVICE_SETTINGS.useFavicon,
isDarkModeEnabled: '', // TODO: This should ideally be a boolean (false). But, changing it caused the sidebar toggle to not work.
isProgressbarEnabled: DEFAULT_SERVICE_SETTINGS.isProgressbarEnabled,
isEnabled: DEFAULT_SERVICE_SETTINGS.isEnabled,
Expand Down
8 changes: 8 additions & 0 deletions src/models/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { v4 as uuidV4 } from 'uuid';
import { needsToken } from '../api/apiBase';
import { DEFAULT_SERVICE_ORDER, DEFAULT_SERVICE_SETTINGS } from '../config';
import { todosStore } from '../features/todos';
import { getFaviconUrl } from '../helpers/favicon-helpers';
import { isValidExternalURL, normalizedUrl } from '../helpers/url-helpers';
import { ifUndefined } from '../jsUtils';
import type { IRecipe } from './Recipe';
Expand Down Expand Up @@ -134,6 +135,8 @@ export default class Service {

@observable isMediaPlaying: boolean = false;

@observable useFavicon: boolean = DEFAULT_SERVICE_SETTINGS.useFavicon;

@action _setAutoRun() {
if (!this.isEnabled) {
this.webview = null;
Expand Down Expand Up @@ -167,6 +170,7 @@ export default class Service {
this.team = ifUndefined<string>(data.team, this.team);
this.customUrl = ifUndefined<string>(data.customUrl, this.customUrl);
this.iconUrl = ifUndefined<string>(data.iconUrl, this.iconUrl);
this.useFavicon = ifUndefined<boolean>(data.useFavicon, this.useFavicon);
this.order = ifUndefined<number>(data.order, this.order);
this.isEnabled = ifUndefined<boolean>(data.isEnabled, this.isEnabled);
this.isNotificationEnabled = ifUndefined<boolean>(
Expand Down Expand Up @@ -350,6 +354,10 @@ export default class Service {
}

@computed get icon(): string {
if (this.useFavicon) {
return getFaviconUrl(this.url);
}

if (this.iconUrl) {
if (needsToken()) {
let url: URL;
Expand Down
1 change: 1 addition & 0 deletions src/stores/ServicesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ export default class ServicesStore extends TypedStore {
isBadgeEnabled: DEFAULT_SERVICE_SETTINGS.isBadgeEnabled,
isMediaBadgeEnabled: DEFAULT_SERVICE_SETTINGS.isMediaBadgeEnabled,
trapLinkClicks: DEFAULT_SERVICE_SETTINGS.trapLinkClicks,
useFavicon: DEFAULT_SERVICE_SETTINGS.useFavicon,
isMuted: DEFAULT_SERVICE_SETTINGS.isMuted,
customIcon: DEFAULT_SERVICE_SETTINGS.customIcon,
isDarkModeEnabled: DEFAULT_SERVICE_SETTINGS.isDarkModeEnabled,
Expand Down