Skip to content

Commit

Permalink
Fix release issues
Browse files Browse the repository at this point in the history
  • Loading branch information
undyingwraith committed Jan 20, 2025
1 parent eca9148 commit 621b6c5
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 110 deletions.
21 changes: 9 additions & 12 deletions packages/desktop/electron-builder.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
appId: com.electron.app
productName: desktop
appId: com.electron.ipmc
productName: IPMC
asar: true
artifactName: ${productName}-${version}.${ext}
directories:
buildResources: build
files:
- '!**/.vscode/*'
- '!src/*'
- '!electron.vite.config.{js,ts,mjs,cjs}'
- '!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}'
- '!{.env,.env.*,.npmrc,pnpm-lock.yaml}'
- '!{tsconfig.json,tsconfig.node.json,tsconfig.web.json}'
- 'out/**/*'
asarUnpack:
- resources/**
win:
executableName: desktop
executableName: IPMC
nsis:
artifactName: ${name}-${version}-setup.${ext}
artifactName: ${productName}-${version}-setup.${ext}
shortcutName: ${productName}
uninstallDisplayName: ${productName}
createDesktopShortcut: always
Expand All @@ -27,7 +24,7 @@ mac:
- NSDownloadsFolderUsageDescription: Application requests access to the user's Downloads folder.
notarize: false
dmg:
artifactName: ${name}-${version}.${ext}
artifactName: ${productName}-${version}.${ext}
linux:
target:
- AppImage
Expand All @@ -36,7 +33,7 @@ linux:
maintainer: electronjs.org
category: Utility
appImage:
artifactName: ${name}-${version}.${ext}
artifactName: ${productName}-${version}.${ext}
npmRebuild: false
publish:
provider: generic
Expand Down
5 changes: 0 additions & 5 deletions packages/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
"build:mac": "electron-vite build && electron-builder --mac --config",
"build:linux": "electron-vite build && electron-builder --linux --config"
},
"build": {
"files": [
"out/**/*"
]
},
"dependencies": {
"@chainsafe/libp2p-gossipsub": "^13.0.0",
"@chainsafe/libp2p-noise": "^15.0.0",
Expand Down
8 changes: 7 additions & 1 deletion packages/desktop/src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app, shell, BrowserWindow } from 'electron';
import { app, shell, BrowserWindow, ipcMain } from 'electron';
import { join } from 'path';
import { electronApp, optimizer, is } from '@electron-toolkit/utils';
import icon from '../../resources/icon.png?asset';
Expand All @@ -8,6 +8,10 @@ process.on('uncaughtException', function (error) {
process.stdout.write(error.name + ': ' + error.message + '\n' + (error.stack != undefined ? error.stack + '\n' : ''));
});

function getAppPath(): string {
return app.getPath('appData');
}

function createWindow(): void {
// Create the browser window.
const mainWindow = new BrowserWindow({
Expand Down Expand Up @@ -52,6 +56,8 @@ function createWindow(): void {
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
ipcMain.handle('getAppPath', getAppPath);

// Set app user model id for windows
electronApp.setAppUserModelId('com.electron');

Expand Down
37 changes: 22 additions & 15 deletions packages/desktop/src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ import { uPnPNAT } from '@libp2p/upnp-nat';
import { webSockets } from '@libp2p/websockets';
import { FsBlockstore } from 'blockstore-fs';
import { LevelDatastore } from 'datastore-level';
import { contextBridge } from 'electron';
import { contextBridge, ipcRenderer } from 'electron';
import fs from 'fs';
import { createHelia } from 'helia';
import { IConfigurationService, IFileInfo, IInternalProfile, IIpfsService, INodeService, IProfile } from 'ipmc-interfaces';
import { ipnsSelector } from 'ipns/selector';
import { ipnsValidator } from 'ipns/validator';
import * as libp2pInfo from 'libp2p/version';
import { CID } from 'multiformats';
import path from 'path';
import { concat } from 'uint8arrays';

function getProfileFolder(name: string): string {
return `./profiles/${name}`;
async function getProfileFolder(id?: string): Promise<string> {
const appPath = path.join(await ipcRenderer.invoke('getAppPath'), 'profiles');
return id ? path.join(appPath, id) : appPath;
}

const nodes = new Map<string, IIpfsService>();
Expand All @@ -44,10 +46,12 @@ const nodeService: INodeService = {
return nodes.get(profile.id)!;
}

const folder = await getProfileFolder(profile.id);

const agentVersion = `helia/2.0.0 ${libp2pInfo.name}/${libp2pInfo.version} UserAgent=${process.version}`;
const datastore = new LevelDatastore(`${getProfileFolder(profile.id)}/data`);
const datastore = new LevelDatastore(path.join(folder, 'data'));
await datastore.open();
const blockstore = new FsBlockstore(`${getProfileFolder(profile.id)}/blocks`);
const blockstore = new FsBlockstore(path.join(folder, 'blocks'));
await blockstore.open();

const helia = await createHelia({
Expand Down Expand Up @@ -196,25 +200,28 @@ const nodeService: INodeService = {
};

const configService: IConfigurationService = {
getProfiles(): string[] {
async getProfiles(): Promise<string[]> {
try {
const profiles = fs.readdirSync('./profiles');
const profiles = fs.readdirSync(await getProfileFolder());
return profiles;
} catch (_) {
return [];
}
},
getProfile(id: string): IProfile {
return JSON.parse(fs.readFileSync(getProfileFolder(id) + '/profile.json', 'utf-8'));
async getProfile(id: string): Promise<IProfile> {
return JSON.parse(fs.readFileSync(path.join(await getProfileFolder(id), '/profile.json'), 'utf-8'));
},
setProfile(id: string, profile: IProfile) {
if (!fs.existsSync(getProfileFolder(id))) {
fs.mkdirSync(getProfileFolder(id));
async setProfile(id: string, profile: IProfile) {
const folder = await getProfileFolder(id);
if (!fs.existsSync(folder)) {
fs.mkdirSync(folder, {
recursive: true
});
}
fs.writeFileSync(getProfileFolder(id) + '/profile.json', JSON.stringify(profile));
fs.writeFileSync(path.join(folder, '/profile.json'), JSON.stringify(profile));
},
removeProfile(id) {
fs.rmSync(getProfileFolder(id), { recursive: true });
async removeProfile(id) {
fs.rmSync(await getProfileFolder(id), { recursive: true });
},
};

Expand Down
22 changes: 12 additions & 10 deletions packages/desktop/src/renderer/index.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>Electron</title>
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<!-- <meta

<head>
<meta charset="UTF-8" />
<title>IPMC</title>
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<!-- <meta
http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; connect-src '*'"
/> -->
</head>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
8 changes: 4 additions & 4 deletions packages/interfaces/src/Services/IConfigurationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ export interface IConfigurationService {
/**
* Gets a list of all {@link IProfile} names.
*/
getProfiles(): string[];
getProfiles(): Promise<string[]>;

/**
* Returns the specified {@link IProfile}.
* @param id id of the {@link IProfile}.
*/
getProfile(id: string): IProfile;
getProfile(id: string): Promise<IProfile>;

/**
* Updates the specified {@link IProfile}.
* @param id id of the {@link IProfile}.
* @param profile updated {@link IProfile}.
*/
setProfile(id: string, profile: IProfile): void;
setProfile(id: string, profile: IProfile): Promise<void>;

/**
* Deletes the specified {@link IProfile}.
* @param id id of the {@link IProfile}.
*/
removeProfile(id: string): void;
removeProfile(id: string): Promise<void>;
}
49 changes: 26 additions & 23 deletions packages/ui/src/IpmcApp.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Box, CssBaseline } from '@mui/material';
import { BrowserModule, CoreModule, FileExportService, IModule } from 'ipmc-core';
import { IConfigurationService, IConfigurationServiceSymbol, IFileExportServiceSymbol, INodeService, ITranslation, ITranslationsSymbol } from 'ipmc-interfaces';
import React from 'react';
import { Switch } from 'wouter';
import { Router, Switch } from 'wouter';
import { useHashLocation } from 'wouter/use-hash-location';
import { AppBar } from './components/organisms/AppBar';
import { AppContextProvider, ThemeProvider } from './context';
import { IpmcLauncher } from './IpmcLauncher';
import { UiModule } from './services/UiModule';
import translations from './translations';
import { IpmcLauncher } from './IpmcLauncher';
import { Box, CssBaseline } from '@mui/material';

export interface IIpmcAppProps {
setup?: IModule;
Expand All @@ -19,26 +20,28 @@ export function IpmcApp(props: IIpmcAppProps) {
const { setup } = props;

return (
<AppContextProvider setup={(app) => {
app.use(CoreModule);
app.use(BrowserModule);
app.use(UiModule);
app.registerConstant(props.configService, IConfigurationServiceSymbol);
app.register(FileExportService, IFileExportServiceSymbol);
app.registerConstantMultiple<ITranslation>(translations, ITranslationsSymbol);
setup && app.use(setup);
}}>
<ThemeProvider>
<CssBaseline />
<Box sx={{ height: '100vh', width: '100vw', display: 'flex', flexDirection: 'column' }}>
<AppBar />
<Box sx={{ overflow: 'auto', flexGrow: 1 }}>
<Switch>
<IpmcLauncher configService={props.configService} nodeService={props.nodeService} />
</Switch>
<Router hook={useHashLocation}>
<AppContextProvider setup={(app) => {
app.use(CoreModule);
app.use(BrowserModule);
app.use(UiModule);
app.registerConstant(props.configService, IConfigurationServiceSymbol);
app.register(FileExportService, IFileExportServiceSymbol);
app.registerConstantMultiple<ITranslation>(translations, ITranslationsSymbol);
setup && app.use(setup);
}}>
<ThemeProvider>
<CssBaseline />
<Box sx={{ height: '100vh', width: '100vw', display: 'flex', flexDirection: 'column' }}>
<AppBar />
<Box sx={{ overflow: 'auto', flexGrow: 1 }}>
<Switch>
<IpmcLauncher configService={props.configService} nodeService={props.nodeService} />
</Switch>
</Box>
</Box>
</Box>
</ThemeProvider>
</AppContextProvider>
</ThemeProvider>
</AppContextProvider>
</Router>
);
}
2 changes: 1 addition & 1 deletion packages/ui/src/IpmcLauncher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function IpmcLauncher(props: PropsWithChildren<IIpmcLauncherProps>) {
async function start(name: string) {
if (name == undefined) return;

const currentProfile = props.configService.getProfile(name);
const currentProfile = await props.configService.getProfile(name);
if (currentProfile != undefined) {
profile.value = currentProfile;
try {
Expand Down
37 changes: 11 additions & 26 deletions packages/ui/src/components/molecules/ProfileEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,22 @@ import { LibraryEditor } from './LibraryEditor';
import { uuid } from 'ipmc-core';
import { useService } from '@src/context';

export function ProfileEditor(props: { id: string, onCancel: () => void, onSave: () => void; }) {
const { id, onCancel, onSave } = props;
export function ProfileEditor(props: { profile: IProfile, onCancel: () => void, onSave: () => void; }) {
const { profile, onCancel, onSave } = props;
const configService = useService<IConfigurationService>(IConfigurationServiceSymbol);
const _t = useTranslation();

const profile = useComputed<IProfile>(() => {
const defaultProfile = {
id: props.id,
libraries: [],
name: '',
type: 'internal',
} as IProfile;
try {
const profile = configService.getProfile(id);
return profile ?? defaultProfile;
} catch (ex) {
return defaultProfile;
}
});

const name = useSignal<string>(profile.value?.name ?? id);
const type = useSignal<'internal' | 'remote'>(profile.value?.type ?? 'internal');
const apiUrl = useSignal<string>(isRemoteProfile(profile.value) ? profile.value.url ?? '' : '');
const swarmKey = useSignal<string>(isInternalProfile(profile.value) ? profile.value.swarmKey ?? '' : '');
const port = useSignal<string>(isInternalProfile(profile.value) ? profile.value.port?.toString() ?? '' : '');
const bootstrap = useSignal<Signal<string>[]>(isInternalProfile(profile.value) ? profile.value.bootstrap?.map(i => new Signal(i)) ?? [] : []);
const libraries = useSignal<Signal<ILibrary>[]>(profile.value.libraries.map(i => new Signal(i)));
const name = useSignal<string>(profile.name);
const type = useSignal<'internal' | 'remote'>(profile.type ?? 'internal');
const apiUrl = useSignal<string>(isRemoteProfile(profile) ? profile.url ?? '' : '');
const swarmKey = useSignal<string>(isInternalProfile(profile) ? profile.swarmKey ?? '' : '');
const port = useSignal<string>(isInternalProfile(profile) ? profile.port?.toString() ?? '' : '');
const bootstrap = useSignal<Signal<string>[]>(isInternalProfile(profile) ? profile.bootstrap?.map(i => new Signal(i)) ?? [] : []);
const libraries = useSignal<Signal<ILibrary>[]>(profile.libraries.map(i => new Signal(i)));

function save() {
configService.setProfile(id, {
...(profile.value ?? {}),
configService.setProfile(profile.id, {
...(profile ?? {}),
name: name.value,
type: type.value,
...(type.value === 'internal' ? {
Expand Down
Loading

0 comments on commit 621b6c5

Please sign in to comment.