Skip to content

Commit

Permalink
isolate client logic in a file
Browse files Browse the repository at this point in the history
  • Loading branch information
Soushi888 committed Feb 10, 2024
1 parent 3491ae4 commit 8de76e2
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 22 deletions.
39 changes: 39 additions & 0 deletions ui/src/lib/utils/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { CellType, type AppInfo, AdminWebsocket, AppAgentWebsocket } from '@holochain/client';

export const HOLOCHAIN_APP_ID = 'mewsfeed';
export const IS_LAUNCHER = import.meta.env.VITE_IS_LAUNCHER;
export const IS_HOLO_HOSTED = import.meta.env.VITE_IS_HOLO_HOSTED;

export const setupHolochain = async () => {
try {
// console.log(import.meta.env);
// const client = await AppAgentWebsocket.connect(
// IS_LAUNCHER ? `ws://UNUSED` : `ws://localhost:${import.meta.env.VITE_HC_PORT}`,
// HOLOCHAIN_APP_ID,
// 60000
// );
// if (typeof window === 'object' && !('__HC_LAUNCHER_ENV__' in window)) {
// const appInfo = await client.appInfo();
// await authorizeClient(appInfo);
// }
// return client;
} catch (e) {
console.log('Holochain client setup error', e);
throw e;
}
};

// set up zome call signing when run outside of launcher
export const authorizeClient = async (appInfo: AppInfo) => {
if (typeof window === 'object' && !('__HC_LAUNCHER_ENV__' in window)) {
if (!(CellType.Provisioned in appInfo.cell_info.mewsfeed[0])) {
throw new Error('mewsfeed cell not provisioned');
}
const { cell_id } = appInfo.cell_info.mewsfeed[0][CellType.Provisioned];
const adminWs = await AdminWebsocket.connect(
`ws://localhost:${import.meta.env.VITE_HC_ADMIN_PORT}`
);
await adminWs.authorizeSigningCredentials(cell_id);
console.log('Holochain app client authorized for zome calls');
}
};
2 changes: 2 additions & 0 deletions ui/src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { AppAgentWebsocket, type AppAgentClient } from '@holochain/client';
import * as path from 'path';
import { setContext } from 'svelte';
import { clientContext } from '../contexts';
import { setupHolochain } from '$lib/utils/client';

export const load: PageLoad = async () => {
setupHolochain();
// const hAppPath = new URL(`ws://localhost:35899`);
// const client = await AppAgentWebsocket.connect(hAppPath, 'requests-and-offers');
// setContext(clientContext, {
Expand Down
22 changes: 0 additions & 22 deletions ui/zip.js

This file was deleted.

22 changes: 22 additions & 0 deletions ui/zip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import fs from 'fs';
import { bestzip } from 'bestzip';
// import { execSync } from 'child_process';

fs.renameSync('./build/200.html', './build/index.html');

// Change working directory to 'build' and zip its contents
try {
process.chdir('./build');
bestzip({
source: './*',
destination: '../dist.zip'
})
.then(() => {
console.log('Zip file was created successfully.');
})
.catch((err) => {
console.error(err.stack);
});
} catch (err) {
console.error(`chdir: ${err}`);
}

0 comments on commit 8de76e2

Please sign in to comment.