Skip to content

Commit

Permalink
fix: Optimization for updater component.
Browse files Browse the repository at this point in the history
Signed-off-by: The1111mp <The1111mp@outlook.com>
  • Loading branch information
1111mp committed Oct 30, 2023
1 parent 31ac51c commit 4135c27
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 19 deletions.
66 changes: 64 additions & 2 deletions src/__tests__/specs/nvmd.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { platform } from 'node:process';
import { pathExists } from 'fs-extra';
import { browser, expect } from '@wdio/globals';

describe('nvmd', () => {
it('file should be existed', async () => {
describe('module nvmd', async () => {
it('nvmd file should be existed', async () => {
const HOMEDIR = (await browser.electron.app('getPath', 'home')) as string;
const nvmdPath = join(
HOMEDIR,
Expand All @@ -15,4 +15,66 @@ describe('nvmd', () => {

expect(await pathExists(nvmdPath)).toBeTruthy();
});

it('node file should be existed', async () => {
const HOMEDIR = (await browser.electron.app('getPath', 'home')) as string;
const nodePath = join(
HOMEDIR,
'.nvmd',
'bin',
platform === 'win32' ? 'node.exe' : 'node',
);

expect(await pathExists(nodePath)).toBeTruthy();
});

it('npm file should be existed', async () => {
const HOMEDIR = (await browser.electron.app('getPath', 'home')) as string;
const npmPath = join(
HOMEDIR,
'.nvmd',
'bin',
platform === 'win32' ? 'npm.exe' : 'npm',
);

expect(await pathExists(npmPath)).toBeTruthy();

if (platform === 'win32') {
const npmCmdPath = join(HOMEDIR, '.nvmd', 'bin', 'npm.cmd');
expect(await pathExists(npmCmdPath)).toBeTruthy();
}
});

it('npx file should be existed', async () => {
const HOMEDIR = (await browser.electron.app('getPath', 'home')) as string;
const npxPath = join(
HOMEDIR,
'.nvmd',
'bin',
platform === 'win32' ? 'npx.exe' : 'npx',
);

expect(await pathExists(npxPath)).toBeTruthy();

if (platform === 'win32') {
const npxCmdPath = join(HOMEDIR, '.nvmd', 'bin', 'npx.cmd');
expect(await pathExists(npxCmdPath)).toBeTruthy();
}
});

it('corepack file should be existed', async () => {
const HOMEDIR = (await browser.electron.app('getPath', 'home')) as string;
const corepackPath = join(
HOMEDIR,
'.nvmd',
'bin',
platform === 'win32' ? 'corepack.exe' : 'corepack',
);
expect(await pathExists(corepackPath)).toBeTruthy();

if (platform === 'win32') {
const corepackCmdPath = join(HOMEDIR, '.nvmd', 'bin', 'corepack.cmd');
expect(await pathExists(corepackCmdPath)).toBeTruthy();
}
});
});
12 changes: 2 additions & 10 deletions src/renderer/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@ import './styles.scss';

import { useState, useRef, lazy, Suspense, useEffect } from 'react';
import { Outlet, Link, useLocation } from 'react-router-dom';
import {
App,
Button,
Layout,
Menu,
Space,
Tour,
Typography,
message,
} from 'antd';
import { App, Button, Layout, Menu, Space, Tour, Typography } from 'antd';
import {
InfoCircleOutlined,
SettingOutlined,
Expand Down Expand Up @@ -383,6 +374,7 @@ const Home: React.FC = () => {
tipDrawer.current?.show();
}}
/>
<Updater />
{platform === 'win32' ? <Updater /> : null}
<Button
type="text"
Expand Down
21 changes: 14 additions & 7 deletions src/renderer/pages/home/updater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ export const Updater: React.FC = () => {
const { message } = App.useApp();
const updateInfo = useRef<UpdateInfo>();

const onCheckUpdate = useRef<
(info: UpdateInfo | 'update-not-available') => void
>((info) => {
if (info === 'update-not-available') {
return message.success(i18n('Up-to-date'));
}

updateInfo.current = info;
setOpen({ visible: true, type: ModalType.Check });
});

useEffect(() => {
window.Context.onCheckUpdateResultCallback((info) => {
if (info === 'update-not-available') {
return message.success(i18n('Up-to-date'));
}

updateInfo.current = info;
setOpen({ visible: true, type: ModalType.Check });
onCheckUpdate.current?.(info);
});

window.Context.onRegistUpdateProgress((progress) => {
Expand Down Expand Up @@ -120,7 +126,8 @@ export const Updater: React.FC = () => {
/>
}
onClick={() => {
setOpen({ visible: true, type: ModalType.Complete });
progress.percent >= 100 &&
setOpen({ visible: true, type: ModalType.Complete });
}}
/>
</Popover>
Expand Down

0 comments on commit 4135c27

Please sign in to comment.