Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Connoropolous committed Feb 1, 2024
1 parent d6f5fdf commit 180b99b
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 141 deletions.
4 changes: 2 additions & 2 deletions scripts/build-webhapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
set -e

yarn workspace acorn-ui build
yarn run zip-we-applet
npx bestzip web/dist.zip web/dist/*
cd we-applet
hc web-app pack workdir --recursive
hc web-app pack . --recursive
Binary file added we-applet/acorn-applet.webhapp
Binary file not shown.
2 changes: 1 addition & 1 deletion we-applet/web-happ.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
manifest_version: "1"
name: acorn-applet
ui:
bundled: "../ui/dist.zip"
bundled: "../web/dist.zip"
happ_manifest:
bundled: "./talking-stickies.happ"
4 changes: 2 additions & 2 deletions web/src/api/callZome.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AppWebsocket, CellId } from '@holochain/client'
import { AppAgentClient, CellId } from '@holochain/client'

export default async function callZome<InputType, OutputType>(
appWebsocket: AppWebsocket,
appWebsocket: AppAgentClient,
cellId: CellId,
zomeName: string,
fnName: string,
Expand Down
4 changes: 2 additions & 2 deletions web/src/api/hdkCrud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ActionHashB64,
UpdateInput,
} from '../types/shared'
import { AppWebsocket, CellId } from '@holochain/client'
import { AppAgentClient, CellId } from '@holochain/client'
import callZome from './callZome'

export interface WireRecord<EntryType> {
Expand Down Expand Up @@ -42,7 +42,7 @@ export function deleteEntryName(entryType: string) {
}

export function createCrudFunctions<EntryType>(
appWebsocket: AppWebsocket,
appWebsocket: AppAgentClient,
zomeName: string,
entryType: string
): EntryTypeApi<EntryType, WireRecord<EntryType>> {
Expand Down
8 changes: 4 additions & 4 deletions web/src/api/profilesApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppWebsocket, CellId } from '@holochain/client'
import { AppAgentClient, CellId } from '@holochain/client'
import { PROFILES_ZOME_NAME } from '../holochainConfig'
import { Profile, WhoAmIOutput } from '../types'
import { AgentPubKeyB64, UpdateInput } from '../types/shared'
Expand All @@ -14,7 +14,7 @@ const ZOME_FN_NAMES = {
FETCH_AGENT_ADDRESS: 'fetch_agent_address',
}

const ProfilesApi = (appWebsocket: AppWebsocket) => {
const ProfilesApi = (appWebsocket: AppAgentClient) => {
return {
createWhoami: async (
cellId: CellId,
Expand Down Expand Up @@ -83,9 +83,9 @@ const ProfilesApi = (appWebsocket: AppWebsocket) => {
}

export default class ProfilesZomeApi {
appWebsocket: AppWebsocket
appWebsocket: AppAgentClient
profile: ReturnType<typeof ProfilesApi>
constructor(appWebsocket: AppWebsocket) {
constructor(appWebsocket: AppAgentClient) {
this.appWebsocket = appWebsocket
this.profile = ProfilesApi(appWebsocket)
}
Expand Down
24 changes: 12 additions & 12 deletions web/src/api/projectsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Tag,
} from '../types'
import { createCrudFunctions, WireRecord } from './hdkCrud'
import { AppWebsocket, CellId } from '@holochain/client'
import { AppAgentClient, CellId } from '@holochain/client'
import { PROJECTS_ZOME_NAME } from '../holochainConfig'
import callZome from './callZome'
import { ActionHashB64 } from '../types/shared'
Expand Down Expand Up @@ -42,7 +42,7 @@ const ZOME_FN_NAMES = {
FETCH_MEMBERS: 'fetch_members',
}

const OutcomeApi = (appWebsocket: AppWebsocket) => {
const OutcomeApi = (appWebsocket: AppAgentClient) => {
const outcomeCrud = createCrudFunctions<Outcome>(
appWebsocket,
PROJECTS_ZOME_NAME,
Expand Down Expand Up @@ -76,28 +76,28 @@ const OutcomeApi = (appWebsocket: AppWebsocket) => {
},
}
}
const ConnectionApi = (appWebsocket: AppWebsocket) => {
const ConnectionApi = (appWebsocket: AppAgentClient) => {
return createCrudFunctions<Connection>(
appWebsocket,
PROJECTS_ZOME_NAME,
ENTRY_TYPE_NAMES.CONNECTION
)
}
const OutcomeCommentApi = (appWebsocket: AppWebsocket) => {
const OutcomeCommentApi = (appWebsocket: AppAgentClient) => {
return createCrudFunctions<OutcomeComment>(
appWebsocket,
PROJECTS_ZOME_NAME,
ENTRY_TYPE_NAMES.OUTCOME_COMMENT
)
}
const OutcomeMemberApi = (appWebsocket: AppWebsocket) => {
const OutcomeMemberApi = (appWebsocket: AppAgentClient) => {
return createCrudFunctions<OutcomeMember>(
appWebsocket,
PROJECTS_ZOME_NAME,
ENTRY_TYPE_NAMES.OUTCOME_MEMBER
)
}
const EntryPointApi = (appWebsocket: AppWebsocket) => {
const EntryPointApi = (appWebsocket: AppAgentClient) => {
const entryPointCrud = createCrudFunctions<EntryPoint>(
appWebsocket,
PROJECTS_ZOME_NAME,
Expand All @@ -118,7 +118,7 @@ const EntryPointApi = (appWebsocket: AppWebsocket) => {
},
}
}
const ProjectMetaApi = (appWebsocket: AppWebsocket) => {
const ProjectMetaApi = (appWebsocket: AppAgentClient) => {
const projectMetaCrud = createCrudFunctions<ProjectMeta>(
appWebsocket,
PROJECTS_ZOME_NAME,
Expand Down Expand Up @@ -161,7 +161,7 @@ const ProjectMetaApi = (appWebsocket: AppWebsocket) => {
}
}

const RealtimeInfoSignalApi = (appWebsocket: AppWebsocket) => {
const RealtimeInfoSignalApi = (appWebsocket: AppAgentClient) => {
return {
send: async (cellId: CellId, payload: RealtimeInfoInput) => {
return callZome(
Expand All @@ -175,7 +175,7 @@ const RealtimeInfoSignalApi = (appWebsocket: AppWebsocket) => {
}
}

const MembersApi = (appWebsocket: AppWebsocket) => {
const MembersApi = (appWebsocket: AppAgentClient) => {
return {
fetch: async (cellId: CellId): Promise<Array<WireRecord<Member>>> => {
return callZome(
Expand All @@ -189,7 +189,7 @@ const MembersApi = (appWebsocket: AppWebsocket) => {
}
}

const TagApi = (appWebsocket: AppWebsocket) => {
const TagApi = (appWebsocket: AppAgentClient) => {
return createCrudFunctions<Tag>(
appWebsocket,
PROJECTS_ZOME_NAME,
Expand All @@ -198,7 +198,7 @@ const TagApi = (appWebsocket: AppWebsocket) => {
}

export default class ProjectsZomeApi {
appWebsocket: AppWebsocket
appWebsocket: AppAgentClient
outcome: ReturnType<typeof OutcomeApi>
entryPoint: ReturnType<typeof EntryPointApi>
connection: ReturnType<typeof ConnectionApi>
Expand All @@ -211,7 +211,7 @@ export default class ProjectsZomeApi {

// one per entry type that uses hdk_crud
// projectMeta, realtimeInfoSignal and member don't use hdk_crud
constructor(appWebsocket: AppWebsocket) {
constructor(appWebsocket: AppAgentClient) {
this.appWebsocket = appWebsocket
this.outcome = OutcomeApi(appWebsocket)
this.outcomeComment = OutcomeCommentApi(appWebsocket)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ export default function ProjectSettingsModal({
// const uid = passphraseToUid(projectPassphrase)
// const installedAppId = `${PROJECT_APP_PREFIX}-${uid}`
useEffect(() => {
getAllApps().then((apps) => {
const appForCell = Object.entries(apps).find(([appId, appInfo]) => {
return appInfo.cellIdString === cellIdString
})
if (appForCell) {
setInstalledAppId(appForCell[0])
}
})
// getAllApps().then((apps) => {
// const appForCell = Object.entries(apps).find(([appId, appInfo]) => {
// return appInfo.cellIdString === cellIdString
// })
// if (appForCell) {
// setInstalledAppId(appForCell[0])
// }
// })
}, [cellIdString])

return (
Expand Down
54 changes: 38 additions & 16 deletions web/src/hcWebsockets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { AppWebsocket, AdminWebsocket } from '@holochain/client'
import {
AdminWebsocket,
AppAgentWebsocket,
AppAgentClient,
} from '@holochain/client'
import { MAIN_APP_ID } from './holochainConfig'

// export for use by holochainMiddleware (redux)

Expand All @@ -8,8 +13,8 @@ export const APP_WS_URL = new URL(`ws://localhost:${__APP_PORT__}`)
// @ts-ignore
const ADMIN_WS_URL = new URL(`ws://localhost:${__ADMIN_PORT__}`)

let appWs: AppWebsocket
let appWsPromise: Promise<AppWebsocket>
let appWs: AppAgentClient
let appWsPromise: Promise<AppAgentClient>
let adminWs: AdminWebsocket
let agentPubKey

Expand All @@ -18,6 +23,7 @@ export async function getAdminWs(): Promise<AdminWebsocket> {
return adminWs
} else {
adminWs = await AdminWebsocket.connect(ADMIN_WS_URL)
// keepalive
setInterval(() => {
if (adminWs.client.socket.readyState === adminWs.client.socket.OPEN) {
adminWs.listDnas()
Expand All @@ -30,20 +36,27 @@ export async function getAdminWs(): Promise<AdminWebsocket> {
}
}

export async function getAppWs(): Promise<AppWebsocket> {
export async function getAppWs(): Promise<AppAgentClient> {
async function connect() {
// undefined is for default request timeout
appWsPromise = AppWebsocket.connect(APP_WS_URL)
appWsPromise = AppAgentWebsocket.connect(APP_WS_URL, MAIN_APP_ID)
appWs = await appWsPromise
appWsPromise = null
appWs.client.socket.addEventListener('close', async () => {
console.log('app websocket closed, trying to re-open')
await connect()
console.log('app websocket reconnected')
})
;(appWs as AppAgentWebsocket).appWebsocket.client.socket.addEventListener(
'close',
async () => {
console.log('app websocket closed, trying to re-open')
await connect()
console.log('app websocket reconnected')
}
)
}

if (appWs && appWs.client.socket.readyState === appWs.client.socket.OPEN) {
if (
appWs &&
(appWs as AppAgentWebsocket).appWebsocket.client.socket.readyState ===
(appWs as AppAgentWebsocket).appWebsocket.client.socket.OPEN
) {
return appWs
} else if (appWsPromise) {
// connection must have been lost
Expand All @@ -55,13 +68,15 @@ export async function getAppWs(): Promise<AppWebsocket> {
await connect()
// set up logic for auto-reconnection
setInterval(async () => {
if (appWs.client.socket.readyState === appWs.client.socket.OPEN) {
if (
(appWs as AppAgentWebsocket).appWebsocket.client.socket.readyState ===
(appWs as AppAgentWebsocket).appWebsocket.client.socket.OPEN
) {
// random call just to keep the connection open
appWs.appInfo({
installed_app_id: 'test',
})
appWs.appInfo()
} else if (
appWs.client.socket.readyState === appWs.client.socket.CLOSED
(appWs as AppAgentWebsocket).appWebsocket.client.socket.readyState ===
(appWs as AppAgentWebsocket).appWebsocket.client.socket.CLOSED
) {
// try to reconnect
await connect()
Expand All @@ -72,6 +87,13 @@ export async function getAppWs(): Promise<AppWebsocket> {
}
}

export function setAdminWs(setAs: AdminWebsocket) {
adminWs = setAs
}
export function setAppWs(setAs: AppAgentClient) {
appWs = setAs
}

export function getAgentPubKey() {
return agentPubKey
}
Expand Down
1 change: 1 addition & 0 deletions web/src/hooks/useProjectStatusInfos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type ProjectStatusInfos = {
const getNewInfos = async (
projects: { cellId: CellIdString; hasProjectMeta: boolean }[]
): Promise<ProjectStatusInfos> => {
return {}
const allApps = await getAllApps()
const appWs = await getAppWs()
const agentPubKey = await getAgentPubKey()
Expand Down
21 changes: 18 additions & 3 deletions web/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,27 @@
import 'core-js/stable'
import 'regenerator-runtime/runtime'

import { WeClient, isWeContext } from '@lightningrodlabs/we-applet'
import main from './indexForElectron'
import { WeClient, isWeContext, initializeHotReload } from '@lightningrodlabs/we-applet'
import createStoreAndRenderToDom, { electronInit } from './indexForElectron'
import { getAdminWs, getAppWs, setAppWs } from './hcWebsockets'

console.log('HELLLLLLO')

if (!isWeContext) {
// electron
main()
;(async () => {
const appWs = await getAppWs()
const adminWs = await getAdminWs()
const store = await createStoreAndRenderToDom(appWs)
await electronInit(store, adminWs, appWs)
})()
} else {
console.log('hello2')
;(async () => {
await initializeHotReload();
console.log('hello3')
const weClient = await WeClient.connect()
console.log('hello4')
if (
weClient.renderInfo.type !== 'applet-view' ||
weClient.renderInfo.view.type !== 'main'
Expand All @@ -28,6 +40,9 @@ if (!isWeContext) {
const appAgentClient = weClient.renderInfo.appletClient
const profilesClient = weClient.renderInfo.profilesClient

setAppWs(appAgentClient)
console.log('made it here')
const store = await createStoreAndRenderToDom(appAgentClient)
console.log('made it here2')
})()
}
Loading

0 comments on commit 180b99b

Please sign in to comment.