Skip to content

Commit

Permalink
fix: remove auto-install of udev-rules for Linux that requires runnin…
Browse files Browse the repository at this point in the history
…g SH scipt with sudo. Its spooky.
  • Loading branch information
peter-sanderson committed Jan 2, 2025
1 parent 870d399 commit 51f6874
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 200 deletions.
17 changes: 0 additions & 17 deletions packages/suite-desktop-api/src/__tests__/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,23 +268,6 @@ describe('DesktopApi', () => {
expect(spy).toHaveBeenCalledWith('user-data/open', existingDirectory);
});

it('DesktopApi.installUdevRules', async () => {
const spy = jest
.spyOn(ipcRenderer, 'invoke')
.mockImplementation(() => Promise.resolve({ success: true }));
const result = await api.installUdevRules();
expect(spy).toHaveBeenCalledWith('udev/install');
expect(result.success).toBe(true);
if (result.success) {
expect(result.payload).toBe(undefined);
} else {
expect(result.error).toBe('should not happen');
}

// @ts-expect-error no expected params
api.installUdevRules(true);
});

it('DesktopApi.handshake', async () => {
const spy = jest
.spyOn(ipcRenderer, 'invoke')
Expand Down
2 changes: 0 additions & 2 deletions packages/suite-desktop-api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ export interface DesktopApi {
clearStore: DesktopApiSend<'store/clear'>;
clearUserData: DesktopApiInvoke<'user-data/clear'>;
openUserDataDirectory: DesktopApiInvoke<'user-data/open'>;
// Udev rules
installUdevRules: DesktopApiInvoke<'udev/install'>;
// Logger
configLogger: DesktopApiSend<'logger/config'>;
// Bridge
Expand Down
3 changes: 0 additions & 3 deletions packages/suite-desktop-api/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ export const factory = <R extends StrictIpcRenderer<any, IpcRendererEvent>>(
return Promise.resolve({ success: false, error: 'invalid params' });
},

// Udev rules
installUdevRules: () => ipcRenderer.invoke('udev/install'),

// Logger
configLogger: config => {
ipcRenderer.send('logger/config', config);
Expand Down
3 changes: 1 addition & 2 deletions packages/suite-desktop-core/src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import * as metadata from './metadata';
import * as customProtocols from './custom-protocols';
import * as autoUpdater from './auto-updater';
import * as store from './store';
import * as udevInstall from './udev-install';
import * as userData from './user-data';
import * as trezorConnect from './trezor-connect';
import * as devTools from './dev-tools';
Expand Down Expand Up @@ -56,7 +55,6 @@ const MODULES: Module[] = [
customProtocols,
autoUpdater,
store,
udevInstall,
userData,
trezorConnect,
devTools,
Expand Down Expand Up @@ -85,6 +83,7 @@ interface MainThreadMessages {
'app/fully-quit': void;
'app/show': void;
}

export const mainThreadEmitter = new TypedEmitter<MainThreadMessages>();
export type MainThreadEmitter = typeof mainThreadEmitter;

Expand Down
73 changes: 0 additions & 73 deletions packages/suite-desktop-core/src/modules/udev-install.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,106 +1,19 @@
import { useState, MouseEvent } from 'react';

import { Button } from '@trezor/components';
import { desktopApi } from '@trezor/suite-desktop-api';
import { isDesktop, isLinux } from '@trezor/env-utils';
import { notificationsActions } from '@suite-common/toast-notifications';
import { selectSelectedDevice } from '@suite-common/wallet-core';
import { isLinux } from '@trezor/env-utils';

import { Translation, TroubleshootingTips, UdevDownload } from 'src/components/suite';
import { Translation, TroubleshootingTips } from 'src/components/suite';
import {
TROUBLESHOOTING_TIP_SUITE_DESKTOP,
TROUBLESHOOTING_TIP_DIFFERENT_COMPUTER,
TROUBLESHOOTING_TIP_UNREADABLE_HID,
TROUBLESHOOTING_TIP_SUITE_DESKTOP_TOGGLE_BRIDGE,
TROUBLESHOOTING_TIP_RECONNECT,
TROUBLESHOOTING_TIP_CLOSE_ALL_TABS,
TROUBLESHOOTING_TIP_UDEV,
} from 'src/components/suite/troubleshooting/tips';
import { useSelector, useDispatch } from 'src/hooks/suite';
import { useSelector } from 'src/hooks/suite';
import type { TrezorDevice } from 'src/types/suite';

// linux web
const UdevWeb = () => (
<TroubleshootingTips
label={<Translation id="TR_TROUBLESHOOTING_UNREADABLE_UDEV" />}
items={[
{
key: 'udev-about',
noBullet: true,
description: <Translation id="TR_UDEV_DOWNLOAD_DESC" />,
},
{
key: 'udev-download',
noBullet: true,
description: <UdevDownload />,
},
]}
data-testid="@connect-device-prompt/unreadable-udev"
/>
);

// linux desktop
const UdevDesktop = () => {
const [response, setResponse] = useState(-1);

const dispatch = useDispatch();

const handleCtaClick = async (event: MouseEvent) => {
event.preventDefault();
event.stopPropagation();

const resp = await desktopApi.installUdevRules();

if (resp?.success) {
setResponse(1);
} else {
dispatch(
notificationsActions.addToast({
type: 'error',
error: resp?.error || 'desktopApi not available',
}),
);

setResponse(0);
}
};

if (response === 1) {
return (
<TroubleshootingTips
opened={false}
label={<Translation id="TR_RECONNECT_IN_NORMAL" />}
items={[]}
data-testid="@connect-device-prompt/unreadable-udev"
/>
);
}

return (
<TroubleshootingTips
opened={response === 0}
label={<Translation id="TR_TROUBLESHOOTING_UNREADABLE_UDEV" />}
cta={
<Button onClick={handleCtaClick}>
<Translation id="TR_TROUBLESHOOTING_UDEV_INSTALL_TITLE" />
</Button>
}
items={[
{
key: 'udev-about',
description: <Translation id="TR_UDEV_DOWNLOAD_DESC" />,
noBullet: true,
},
{
key: 'udev-download',
description: <UdevDownload />,
noBullet: true,
},
]}
data-testid="@connect-device-prompt/unreadable-udev"
/>
);
};

interface DeviceUnreadableProps {
device?: TrezorDevice; // this should be actually UnreadableDevice, but it is not worth type casting
}
Expand All @@ -114,14 +27,14 @@ interface DeviceUnreadableProps {
export const DeviceUnreadable = ({ device }: DeviceUnreadableProps) => {
const selectedDevice = useSelector(selectSelectedDevice);

// generic troubleshooting tips
const items = [];

// this error is dispatched by trezord when udev rules are missing
if (isLinux() && device?.error === 'LIBUSB_ERROR_ACCESS') {
return <> {isDesktop() ? <UdevDesktop /> : <UdevWeb />}</>;
items.push(TROUBLESHOOTING_TIP_UDEV);
}

// generic troubleshooting tips
const items = [];

// only for unreadable HID devices
if (
// model 1 hid normal mode
Expand Down
8 changes: 0 additions & 8 deletions packages/suite/src/support/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7305,18 +7305,10 @@ export default defineMessages({
defaultMessage:
'Restarting your computer may fix the communication issue between your browser and device.',
},
TR_TROUBLESHOOTING_UNREADABLE_UDEV: {
id: 'TR_TROUBLESHOOTING_UNREADABLE_UDEV',
defaultMessage: 'Missing udev rules',
},
TR_TROUBLESHOOTING_UNREADABLE_UNKNOWN: {
id: 'TR_TROUBLESHOOTING_UNREADABLE_UNKNOWN',
defaultMessage: 'Unexpected state: {error}',
},
TR_TROUBLESHOOTING_UDEV_INSTALL_TITLE: {
id: 'TR_TROUBLESHOOTING_UDEV_INSTALL_TITLE',
defaultMessage: 'Install rules automatically',
},
TR_SEEDLESS_SETUP_IS_NOT_SUPPORTED_TITLE: {
id: 'TR_SEEDLESS_SETUP_IS_NOT_SUPPORTED_TITLE',
defaultMessage: "Seedless setup isn't supported in Trezor Suite",
Expand Down

0 comments on commit 51f6874

Please sign in to comment.