Skip to content

Commit

Permalink
Improve opening links in web browser
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-senechal committed Dec 21, 2023
1 parent 447d339 commit a1a3cf0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
7 changes: 2 additions & 5 deletions web/massastation/src/components/SidePanels/Upload/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { routeFor } from '../../../utils/utils';
import { parseForm } from '../../../utils/ParseForm';
import { useAccountStore } from '../../../store/store';
import { AccountObject } from '../../../models/AccountModel';
import { BrowserOpenURL } from '../../../../wailsjs/runtime';

import { URL } from '../../../const/url/url';

Expand All @@ -31,6 +30,7 @@ import {
} from '../../../validation/upload';
import { MASSA_WALLET } from '../../../const/const';
import { MassaPluginModel } from '@/models';
import { openInWebBrowser } from '@/custom/openInWebBrowser';

interface IFormError {
websiteName?: string;
Expand Down Expand Up @@ -244,10 +244,7 @@ export default function Upload() {
) : (
<Button
onClick={() =>
// eslint-disable-next-line new-cap
BrowserOpenURL(
'http://station.massa/plugin/massa-labs/massa-wallet/web-app/',
)
openInWebBrowser('/plugin/massa-labs/massa-wallet/web-app/')
}
>
{Intl.t('search.buttons.create-account')}
Expand Down
16 changes: 16 additions & 0 deletions web/massastation/src/custom/openInWebBrowser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { BrowserOpenURL } from '../../wailsjs/runtime';

// Opens the URL in the default web browser
// If the URL does not contain the protocol and host parts, we prepend VITE_BASE_API
export const openInWebBrowser = (url: string) => {
if (!url.includes('://')) {
if (url.startsWith('/')) {
url = `${import.meta.env.VITE_BASE_API}${url}`;
} else {
url = `${import.meta.env.VITE_BASE_API}/${url}`;
}
}

// eslint-disable-next-line new-cap
BrowserOpenURL(url);
};
7 changes: 3 additions & 4 deletions web/massastation/src/pages/Index/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { useConfigStore } from '@/store/store';
import { usePost, useResource } from '../../custom/api';
import { UseQueryResult } from '@tanstack/react-query';
import { MASSA_WALLET } from '@/const';
import { BrowserOpenURL } from '../../../wailsjs/runtime/runtime';
import { openInWebBrowser } from '@/custom/openInWebBrowser';

export function Index() {
const plugins = useResource<MassaPluginModel[]>('plugin-manager');
Expand Down Expand Up @@ -157,9 +157,8 @@ function NestedIndex({
iconActive={<WalletActive />}
iconInactive={<WalletInactive />}
onClickActive={() =>
// eslint-disable-next-line new-cap
BrowserOpenURL(
'http://station.massa/plugin/massa-labs/massa-wallet/web-app/index',
openInWebBrowser(
'/plugin/massa-labs/massa-wallet/web-app/index',
)
}
onClickInactive={() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Description } from '@massalabs/react-ui-kit';
import { HttpStatusCode } from 'axios';
import { useEffect, useState } from 'react';
import { FiGlobe } from 'react-icons/fi';
import { BrowserOpenURL } from '../../../../wailsjs/runtime/runtime';
import { openInWebBrowser } from '@/custom/openInWebBrowser';

interface DomainModelItemProps {
website: DomainModel;
Expand Down Expand Up @@ -52,8 +52,7 @@ export default function DomainModelItem(props: DomainModelItemProps) {
title={website.name}
website={website.name + '.massa'}
description={website.description}
// eslint-disable-next-line new-cap
onClick={() => BrowserOpenURL(url)}
onClick={() => openInWebBrowser(url)}
/>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { SyntheticEvent, useEffect } from 'react';
import { useDelete, usePost } from '@/custom/api';
import { BrowserOpenURL } from '../../../../wailsjs/runtime';

import {
Button,
Expand All @@ -27,6 +26,7 @@ import {
import Intl from '@/i18n/i18n';

import { MassaPluginModel, PluginStatus } from '@/models';
import { openInWebBrowser } from '@/custom/openInWebBrowser';

interface PluginExecuteRequest {
command: string;
Expand Down Expand Up @@ -167,8 +167,7 @@ export function StationPlugin({
<Button variant="icon">
<FiArrowUpRight
onClick={() => {
/* Using 'http://station.massa' probably isn't the cleanest thing to do */
BrowserOpenURL(`http://station.massa${home}`); // eslint-disable-line new-cap
openInWebBrowser(home);
}}
/>
</Button>,
Expand Down

0 comments on commit a1a3cf0

Please sign in to comment.