Skip to content

Commit

Permalink
fix: 7z window
Browse files Browse the repository at this point in the history
  • Loading branch information
aqaurius6666 committed May 21, 2023
1 parent aebfb55 commit d4197da
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 41 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "MpbootGUI",
"description": "GUI Desktop Application for Mpboot",
"version": "2.3.0",
"version": "2.3.1",
"private": true,
"author": {
"name": "Vu Nguyen <aqaurius6666@gmail.com>"
Expand Down Expand Up @@ -62,6 +62,7 @@
"vitest": "0.25.1"
},
"dependencies": {
"7zip-bin": "^5.2.0",
"@aqaurius6666/react-folder-tree": "5.2.8",
"@fortawesome/fontawesome-svg-core": "^6.3.0",
"@parcel/watcher": "^2.1.0",
Expand Down
1 change: 0 additions & 1 deletion packages/main/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const is = {

export const githubToken = env.PUBLIC_GITHUB_TOKEN;


export const mpbootSource: MPBootSource = {
gitProvider: 'github',
gitOwner: 'aqaurius6666',
Expand Down
16 changes: 12 additions & 4 deletions packages/main/src/entity/installation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { githubFetch } from '../services/github';
import { mkdirp } from '../common/fs';
import { globAsync } from '../common/glob';
import { join } from 'path';
import { is } from '../const';

export class Installation {
static async listVersions(
Expand All @@ -31,7 +32,8 @@ export class Installation {
} else {
throw new Error(`git provider ${source.gitProvider} not supported`);
}
const inAppInstalled = await globAsync(join(binaryDirectory, '**', 'mpboot*'));
const inAppInstalled = await globAsync(join('**', 'mpboot*'), { cwd: binaryDirectory });
console.log(inAppInstalled);
versions = versions.map((e: MPBootVersion) => {
const installed = inAppInstalled.find(i => {
return i.includes(e.versionName);
Expand Down Expand Up @@ -133,11 +135,17 @@ export class Installation {

static async extractAsset(assetPath: string, dest: string): Promise<string> {
await mkdirp(dest);
const extractCommand = new Commander('unzip', [assetPath, '-d', dest]);
await extractCommand.executeInline();
if (is.win) {
const { path7za } = await import('7zip-bin');
const extractCommand = new Commander(path7za, ['x', assetPath, `-o${dest}`]);
await extractCommand.executeInline();
} else {
const extractCommand = new Commander('unzip', [assetPath, '-d', dest]);
await extractCommand.executeInline();
}
const files = await readdir(dest);
if (files.length >= 0) {
return `${dest}/${files[0]}`;
return join(dest, files[files.length - 1]); // in Windows, it return mpboot-click.exe and mpboot.exe, mpboot-click.exe is always the first one.
}
throw new Error(`extract asset ${assetPath} failed`);
}
Expand Down
7 changes: 5 additions & 2 deletions packages/main/src/ipc/command.ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ wrapperIpcMainHandle(
async (_event, request: SaveExecutionHistoryRequest) => {
const { seed, fullCommand, workspaceId, sequenceNumber } = request;
const parameter = convertCommandToParameter(fullCommand);

if (!parameter.source) {
logger.error('Source file not found when saving command execution');
return false;
}
try {
const sourceHash = await hashFile(parameter.source!);
const sourceHash = await hashFile(parameter.source);
await repository.updateExecutionHistory(
workspaceId,
sequenceNumber,
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/services/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const githubFetch = async (url: string, init?: RequestInit) => {
...init,
headers: {
...init?.headers,
...(githubToken && {Authorization: 'Bearer ' + githubToken}),
...(githubToken && { Authorization: 'Bearer ' + githubToken }),
},
});
if (!res.ok) {
Expand Down
16 changes: 11 additions & 5 deletions packages/main/tests/installation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { Installation } from '../src/entity/installation';
import type { OSType } from '../../common/stuff';
import { stat } from 'fs/promises';
import { logger } from '../../common/logger';
import { is } from '../src/const';
import { tmpdir } from 'os';
import { join } from 'path';

const testSource = {
gitProvider: 'github',
Expand Down Expand Up @@ -38,19 +41,22 @@ describe('installation', () => {
});

it('download asset', async () => {
const url = await Installation.getAssetUrl(testSource, testVersion, 'ubuntu');
const zipDestPath = `/tmp/test-mpboot-${new Date().getTime()}`;
const url = await Installation.getAssetUrl(
testSource,
testVersion,
is.win ? 'windows' : is.mac ? 'macos' : 'ubuntu',
);
const zipDestPath = join(tmpdir(), `test-mpboot-${new Date().getTime()}`);
await Installation.downloadAsset(url, zipDestPath, event => {
expect(event.progress).toBeGreaterThanOrEqual(0);
expect(event.progress).toBeLessThanOrEqual(1);
});
let statInfo = await stat(zipDestPath);
expect(statInfo.size).toBeGreaterThan(0);

const dest2 = `/tmp/test-mpboot-${new Date().getTime()}-extracted`;
const dest2 = join(tmpdir(), `test-mpboot-${new Date().getTime()}-extracted`);
const binaryPath = await Installation.extractAsset(zipDestPath, dest2);
statInfo = await stat(dest2);
statInfo = await stat(binaryPath);
expect(statInfo.size).toBeGreaterThan(0);
expect(binaryPath).toBeDefined();
});
});
26 changes: 1 addition & 25 deletions packages/renderer/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { lazy, Suspense, useEffect } from 'react';
import { lazy, Suspense } from 'react';
import { HashRouter, Route, Routes } from 'react-router-dom';

// import { MainPage } from './pages/main';
Expand Down Expand Up @@ -31,19 +31,6 @@ const InstallationPage = lazy(() =>
function App() {
const size = useWindowSize();
const electron = useElectron();
const [errMsg, setErrMsg] = React.useState<string>('');

useEffect(() => {
if (!electron || typeof electron.testAvailable !== 'function') return;

electron.testAvailable().then(res => {
if (!res) {
setErrMsg('mpboot executable is not available');
} else {
setErrMsg('');
}
});
}, [electron]);

if (!electron || typeof electron.testAvailable !== 'function') {
return (
Expand All @@ -57,17 +44,6 @@ function App() {
);
}

if (errMsg) {
return (
<div>
<div>
We are really sorry that MpbootGUI is not currently working as expected. Please contact us
for more support.
</div>
<h1>{errMsg}</h1>
</div>
);
}
return (
<div style={{ width: size.width, height: size.height }}>
<Suspense fallback={<div>Loading...</div>}>
Expand Down
7 changes: 5 additions & 2 deletions scripts/inject-env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { writeFile } from 'fs/promises';

dotenv.config();

await writeFile('packages/main/src/inject-env.ts', `export default ${JSON.stringify({
await writeFile(
'packages/main/src/inject-env.ts',
`export default ${JSON.stringify({
PUBLIC_GITHUB_TOKEN: process.env.PUBLIC_GITHUB_TOKEN,
})}`);
})}`,
);
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# yarn lockfile v1


"7zip-bin@^5.2.0":
version "5.2.0"
resolved "https://registry.yarnpkg.com/7zip-bin/-/7zip-bin-5.2.0.tgz#7a03314684dd6572b7dfa89e68ce31d60286854d"
integrity sha512-ukTPVhqG4jNzMro2qA9HSCSSVJN3aN7tlb+hfqYCt3ER0yWroeA2VR38MNrOHLQ/cVj+DaIMad0kFCtWWowh/A==

"7zip-bin@~5.1.1":
version "5.1.1"
resolved "https://registry.yarnpkg.com/7zip-bin/-/7zip-bin-5.1.1.tgz#9274ec7460652f9c632c59addf24efb1684ef876"
Expand Down

0 comments on commit d4197da

Please sign in to comment.