Skip to content

Commit

Permalink
Viewport now sends mediator notify
Browse files Browse the repository at this point in the history
  • Loading branch information
stricklandrbls committed May 6, 2024
1 parent 06eb06b commit 75e0fb1
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 26 deletions.
50 changes: 33 additions & 17 deletions src/dataEditor/include/omegaEdit/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
getClient,

Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 11)

'getClient' is declared but its value is never read.

Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 8)

'getClient' is declared but its value is never read.

Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 18, Java: 17)

'getClient' is declared but its value is never read.

Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 8)

'getClient' is declared but its value is never read.

Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 17)

'getClient' is declared but its value is never read.

Check failure on line 11 in src/dataEditor/include/omegaEdit/Session.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: ubuntu-20.04, Node: 16, Java: 11)

'getClient' is declared but its value is never read.
getContentType,
getLanguage,
getLogger,
getViewportData,
} from '@omega-edit/client'
import EventEmitter from 'events'
import { Viewport } from './Viewport'
Expand All @@ -31,8 +33,8 @@ export class Session {

private metadata = SessionMetadata
private metadataEventEmitter = new EventEmitter()
private viewports: Map<string, Viewport> = new Map()

// private viewports: Map<Viewport, (viewport: Viewport) => void> = new Map()
private viewports: Viewport[] = []
constructor(
response: CreateSessionResponse,
public onMetadataUpdate: (data: typeof SessionMetadata) => void
Expand All @@ -46,30 +48,44 @@ export class Session {
this.onMetadataUpdate(this.metadata)
})
}
getViewports() {
return this.viewports
}
async createViewport(
client: EditorClient,
// client: EditorClient,
offset: number,
capacity: number,
onDataEvent: (event: Viewport) => void
): Promise<void> {
return new Promise((resolve, reject) => {
createViewport(undefined, this.id, offset, capacity)
.then((response) => {
this.viewports.set(
response.getViewportId(),
new Viewport(response.getData_asU8(), capacity)
)
client
.subscribeToViewportEvents(
new EventSubscriptionRequest()
.setId(response.getViewportId())
.setInterest(
ALL_EVENTS & ~ViewportEventKind.VIEWPORT_EVT_MODIFY
)
this.viewports.push(
new Viewport(
response.getViewportId(),
response.getData_asU8(),
capacity,
onDataEvent
)
.on('data', async (event: ViewportEvent) => {
onDataEvent(new Viewport(event.getData_asU8(), 1024))
})
)
// client
// .subscribeToViewportEvents(
// new EventSubscriptionRequest()
// .setId(response.getViewportId())
// .setInterest(
// ALL_EVENTS & ~ViewportEventKind.VIEWPORT_EVT_MODIFY
// )
// )
// .on('data', async (event: ViewportEvent) => {
// getLogger().debug({
// viewportId: event.getViewportId(),
// event: event.getViewportEventKind(),
// })
// const viewport = this.viewports.find((viewport) => {
// return viewport.id == event.getViewportId()
// })
// onDataEvent(viewport!)
// })
resolve()
})
.catch((err) => {
Expand Down
12 changes: 10 additions & 2 deletions src/dataEditor/include/omegaEdit/Viewport.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { ViewportDataResponse } from '@omega-edit/client'
import { createViewport, modifyViewport } from '@omega-edit/client'

export class Viewport {
constructor(
readonly id: string,
protected data: Uint8Array,
protected capacity: number
protected capacity: number,
public onDataUpdate: (viewport: Viewport) => void
) {}
length() {
return this.data.length
}
setOffset(offset: number) {
modifyViewport(this.id, offset, this.capacity).then((response) => {
this.data = response.getData_asU8()
this.onDataUpdate(this)
})
}
}
45 changes: 38 additions & 7 deletions src/dataEditor/include/omegaEdit/omegaEditService.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { EditorClient, createSession, getClient } from '@omega-edit/client'
import {
EditorClient,
createSession,
getClient,

Check failure on line 4 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 8)

'getClient' is declared but its value is never read.

Check failure on line 4 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 17)

'getClient' is declared but its value is never read.

Check failure on line 4 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 17)

'getClient' is declared but its value is never read.

Check failure on line 4 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 11)

'getClient' is declared but its value is never read.

Check failure on line 4 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 11)

'getClient' is declared but its value is never read.

Check failure on line 4 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 16, Java: 8)

'getClient' is declared but its value is never read.

Check failure on line 4 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 8)

'getClient' is declared but its value is never read.

Check failure on line 4 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 8)

'getClient' is declared but its value is never read.

Check failure on line 4 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 16, Java: 11)

'getClient' is declared but its value is never read.

Check failure on line 4 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 11)

'getClient' is declared but its value is never read.

Check failure on line 4 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 17)

'getClient' is declared but its value is never read.

Check failure on line 4 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 16, Java: 17)

'getClient' is declared but its value is never read.
modifyViewport,

Check failure on line 5 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 8)

'modifyViewport' is declared but its value is never read.

Check failure on line 5 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 17)

'modifyViewport' is declared but its value is never read.

Check failure on line 5 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 17)

'modifyViewport' is declared but its value is never read.

Check failure on line 5 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 16, Java: 11)

'modifyViewport' is declared but its value is never read.

Check failure on line 5 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 11)

'modifyViewport' is declared but its value is never read.

Check failure on line 5 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 16, Java: 8)

'modifyViewport' is declared but its value is never read.

Check failure on line 5 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: macos-12, Node: 18, Java: 8)

'modifyViewport' is declared but its value is never read.

Check failure on line 5 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 8)

'modifyViewport' is declared but its value is never read.

Check failure on line 5 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 16, Java: 11)

'modifyViewport' is declared but its value is never read.

Check failure on line 5 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 11)

'modifyViewport' is declared but its value is never read.

Check failure on line 5 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 18, Java: 17)

'modifyViewport' is declared but its value is never read.

Check failure on line 5 in src/dataEditor/include/omegaEdit/omegaEditService.ts

View workflow job for this annotation

GitHub Actions / Build, Test, and Package (OS: windows-2019, Node: 16, Java: 17)

'modifyViewport' is declared but its value is never read.
} from '@omega-edit/client'
import { IEditService, IServiceMediator } from '../service/editorService'
import { Session } from './Session'
import { Viewport } from './Viewport'

export class OmegaEditService extends IEditService {
static ViewportCapacity = 1024
private session: Session | undefined = undefined

constructor(
Expand All @@ -19,16 +26,40 @@ export class OmegaEditService extends IEditService {
data: data,
})
})
this.session.createViewport(this.client, 0, 1024, (event) => {
this.mediator.notify({
id: 'viewport-updated',
data: event,
})
})
this.session.createViewport(
0,
OmegaEditService.ViewportCapacity,
(event) => {
this.mediator.notify({
id: 'viewport-updated',
data: event,
})
}
)
} catch {
throw new Error('Could not setup Omegaeditservice')
}
}
async destroy() {}
getViewport(byId: string): Viewport | undefined {
if (byId === '') return this.session?.getViewports()[0]
return this.session?.getViewports().find((vp) => {
return vp.id === byId
})
}
// async scrollViewport(
// offset: number,
// onViewportUpdate: (viewport: Viewport) => void
// ) {
// const first = this.session?.getViewports()[0]
// modifyViewport(first!.id, offset, OmegaEditService.ViewportCapacity).then(
// (response) => {
// const viewport = this.session?.getViewports().find((vp) => {
// return vp.id == response.getViewportId()
// })
// onViewportUpdate(viewport!)
// }
// )
// }
}
// service requires a running server
12 changes: 12 additions & 0 deletions src/dataEditor/standalone/standaloneEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ export class StandaloneEditor extends DataEditor implements vscode.Disposable {
}
initializeUI(ui: DataEditorWebviewPanel): void {
this.ui = ui
setTimeout(() => {
// Simulate UI Request to scroll viewport
const request = {
type: 'scroll',
viewportId: '',
offset: 2000,
}
console.debug('Sending scrollViewport request')
this.editService!.getViewport(request.viewportId)?.setOffset(
request.offset
)
}, 4000)
}
async getFile(): Promise<void> {
const fileUri = await vscode.window.showOpenDialog({
Expand Down

0 comments on commit 75e0fb1

Please sign in to comment.