Skip to content

Commit eb520b3

Browse files
committed
improved typing & actions bug fixes
1 parent 02dc483 commit eb520b3

File tree

2 files changed

+102
-78
lines changed

2 files changed

+102
-78
lines changed

src/instance.js

Lines changed: 86 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class WebSocketClient {
113113
/**
114114
* @type {import('./sdk').GetInstanceJSFn}
115115
*/
116-
function getInstanceJs(parentClass, addonTriggers, C3) {
116+
export function getInstanceJs(parentClass, addonTriggers, C3) {
117117
return class Pipelab extends parentClass {
118118
/**
119119
* @type {WebSocketClient}
@@ -337,25 +337,25 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
337337
/** @type [import("@pipelab/core").Paths, string][] */
338338
const paths = [
339339
// app.getPath(name)
340-
['home', '_homeFolder' ],
341-
['appData', '_appDataFolder' ],
342-
['userData', '_userDataFolder' ],
343-
['sessionData', '_sessionDataFolder' ],
344-
['temp', '_tempFolder' ],
345-
['exe', '_exeFolder' ],
346-
['module', '_moduleFolder' ],
347-
['desktop', '_desktopFolder' ],
348-
['documents', '_documentsFolder' ],
349-
['downloads', '_downloadsFolder' ],
350-
['music', '_musicFolder' ],
351-
['pictures', '_picturesFolder' ],
352-
['videos', '_videosFolder' ],
353-
['recent', '_recentFolder' ],
354-
['logs', '_logsFolder' ],
355-
['crashDumps', '_crashDumpsFolder' ],
340+
['home', '_homeFolder'],
341+
['appData', '_appDataFolder'],
342+
['userData', '_userDataFolder'],
343+
['sessionData', '_sessionDataFolder'],
344+
['temp', '_tempFolder'],
345+
['exe', '_exeFolder'],
346+
['module', '_moduleFolder'],
347+
['desktop', '_desktopFolder'],
348+
['documents', '_documentsFolder'],
349+
['downloads', '_downloadsFolder'],
350+
['music', '_musicFolder'],
351+
['pictures', '_picturesFolder'],
352+
['videos', '_videosFolder'],
353+
['recent', '_recentFolder'],
354+
['logs', '_logsFolder'],
355+
['crashDumps', '_crashDumpsFolder'],
356356
// app.getAppPath
357-
['app', '_appFolder' ],
358-
['project', '_projectFilesFolder' ],
357+
['app', '_appFolder'],
358+
['project', '_projectFilesFolder'],
359359
]
360360

361361
const promises = paths.map(async (name) => {
@@ -370,12 +370,11 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
370370
}
371371
}
372372

373-
/**
374-
* @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessagePaths, 'output'>}
375-
*/
376373
const pathFolder = await this.ws?.sendAndWaitForResponse(orderPath)
377-
// console.log('pathFolder', pathFolder.body.data)
378-
this[name[1]] = pathFolder.body.data
374+
if (pathFolder) {
375+
// console.log('pathFolder', pathFolder.body.data)
376+
this[name[1]] = pathFolder.body.data
377+
}
379378

380379
})
381380

@@ -390,11 +389,14 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
390389
}
391390

392391
/**
393-
* @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessageEngine, 'output'>}
392+
* @type {(import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessageEngine, 'output'>) | undefined}
394393
*/
394+
// @ts-expect-error
395395
const engineResponse = await this.ws.sendAndWaitForResponse(orderEngine)
396-
// console.log('engineResponse', engineResponse.body.engine)
397-
this._engine = engineResponse.body.engine
396+
if (engineResponse) {
397+
// console.log('engineResponse', engineResponse.body.engine)
398+
this._engine = engineResponse.body.engine
399+
}
398400

399401
this._isInitialized = true
400402

@@ -500,7 +502,7 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
500502
const order = {
501503
url: '/window/set-always-on-top',
502504
body: {
503-
value: true
505+
value: mode === 'enable' ? true : false
504506
}
505507
}
506508

@@ -550,7 +552,7 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
550552
const order = {
551553
url: '/window/set-resizable',
552554
body: {
553-
value: true
555+
value: resizable === 'enable' ? true : false
554556
}
555557
}
556558

@@ -610,7 +612,7 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
610612
const order = {
611613
url: '/window/show-dev-tools',
612614
body: {
613-
value: true
615+
value: toggle === 'show' ? true : false
614616
}
615617
}
616618

@@ -645,6 +647,7 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
645647
}
646648

647649
/** @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessageShowFolderDialog, 'output'> | undefined} */
650+
// @ts-expect-error
648651
const answer = await this.ws?.sendAndWaitForResponse(order)
649652
// console.log('answer', answer)
650653

@@ -670,16 +673,20 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
670673
/**
671674
* @type {import('@pipelab/core').FileFilter[]}
672675
*/
673-
const filters = accept.split(',').map(filter => {
674-
// console.log('filter', filter)
675-
const [name, extensions] = filter.split('|')
676-
if (name && extensions) {
677-
return {
678-
name,
679-
extensions: extensions.split(';')
676+
const filters = accept.split(',')
677+
.map(filter => {
678+
// console.log('filter', filter)
679+
const [name, extensions] = filter.split('|')
680+
if (name && extensions) {
681+
/** @type {import("electron").FileFilter} */
682+
const result = {
683+
name,
684+
extensions: extensions.split(';')
685+
}
686+
return result
680687
}
681-
}
682-
})
688+
})
689+
.filter(x => !!x)
683690

684691
// console.log('filters', filters)
685692

@@ -710,16 +717,20 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
710717
/**
711718
* @type {import('@pipelab/core').FileFilter[]}
712719
*/
713-
const filters = accept.split(',').map(filter => {
714-
// console.log('filter', filter)
715-
const [name, extensions] = filter.split('|')
716-
if (name && extensions) {
717-
return {
718-
name,
719-
extensions: extensions.split(';')
720+
const filters = accept.split(',')
721+
.map(filter => {
722+
// console.log('filter', filter)
723+
const [name, extensions] = filter.split('|')
724+
if (name && extensions) {
725+
/** @type {import("electron").FileFilter} */
726+
const result = {
727+
name,
728+
extensions: extensions.split(';')
729+
}
730+
return result
720731
}
721-
}
722-
})
732+
})
733+
.filter(x => !!x)
723734

724735
/** @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessageShowSaveDialog, 'input'>} */
725736
const order = {
@@ -873,8 +884,8 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
873884
}, this.unsupportedEngine)
874885

875886
/**
876-
* @param {IObjectClass} objectClass
877-
* @return {IBinaryDataInstance | null} objectClass
887+
* @param {import("./sdk").IObjectClass} objectClass
888+
* @return {import("./sdk").IBinaryDataInstance | null} objectClass
878889
*/
879890
__GetBinaryDataSdkInstance(objectClass) {
880891
// console.log('this._inst', this._inst)
@@ -897,36 +908,36 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
897908
// console.log('C3', C3)
898909
// console.log('this', this)
899910

900-
const sdkInst = this.__GetBinaryDataSdkInstance(source);
911+
// const sdkInst = this.__GetBinaryDataSdkInstance(source);
901912

902-
if (!sdkInst) {
903-
throw new Error("SDK instance not found")
904-
}
913+
// if (!sdkInst) {
914+
// throw new Error("SDK instance not found")
915+
// }
905916

906-
// console.log('sdkInst', sdkInst)
917+
// // console.log('sdkInst', sdkInst)
907918

908-
const buffer = sdkInst.getArrayBufferReadOnly();
919+
// const buffer = sdkInst.getArrayBufferReadOnly();
909920

910-
// console.log('buffer', buffer)
921+
// // console.log('buffer', buffer)
911922

912-
/** @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessageWriteFile, 'input'>} */
913-
const order = {
914-
url: '/fs/file/write',
915-
body: {
916-
path,
917-
contents: buffer,
918-
encoding: undefined
919-
}
920-
}
923+
// /** @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessageWriteFile, 'input'>} */
924+
// const order = {
925+
// url: '/fs/file/write',
926+
// body: {
927+
// path,
928+
// contents: buffer,
929+
// encoding: undefined
930+
// }
931+
// }
921932

922-
const answer = await this.ws?.sendAndWaitForResponse(order)
923-
if (!answer || answer.body.success === false) {
924-
this._currentTag = tag;
925-
await this.TriggerAsync(C3.Plugins.pipelab.Cnds.OnAnyBinaryFileRead)
926-
this._currentTag = tag;
927-
await this.TriggerAsync(C3.Plugins.pipelab.Cnds.OnBinaryFileRead)
928-
this._currentTag = ''
929-
}
933+
// const answer = await this.ws?.sendAndWaitForResponse(order)
934+
// if (!answer || answer.body.success === false) {
935+
// this._currentTag = tag;
936+
// await this.TriggerAsync(C3.Plugins.pipelab.Cnds.OnAnyBinaryFileRead)
937+
// this._currentTag = tag;
938+
// await this.TriggerAsync(C3.Plugins.pipelab.Cnds.OnBinaryFileRead)
939+
// this._currentTag = ''
940+
// }
930941
}, this.unsupportedEngine)
931942

932943
_FetchFileSize = this.wrap(super._FetchFileSize, async (path) => {
@@ -941,6 +952,7 @@ function getInstanceJs(parentClass, addonTriggers, C3) {
941952
/**
942953
* @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessageFileSize, 'output'>}
943954
*/
955+
// @ts-expect-error
944956
const answer = await this.ws?.sendAndWaitForResponse(order)
945957
// console.log('answer', answer)
946958
this._fileSize = answer?.body.size ?? -1

src/sdk.d.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// DO NOT TOUCH: autogenerated
1+
declare global {
2+
/** The SDK version available at runtime. */
3+
const sdk: "v1" | "v2";
4+
}
25

36
type Config<T extends string> = import("c3ide2-types").Plugin<T>
47

@@ -101,7 +104,7 @@ type ActionParamToType<T extends ActionParam> = T['type'] extends 'string'
101104
: T['type'] extends 'number'
102105
? number
103106
: T['type'] extends 'object'
104-
? unknown
107+
? import("./sdk").IObjectClass
105108
: T['type'] extends 'combo'
106109
? keyof UnionToIntersection<DeepWriteable<T['items'][number]>>
107110
: never
@@ -178,6 +181,8 @@ type StaticMethodsParentClass = {
178181
_trigger(trigger: OpaqueCnds): void
179182

180183
_getInitProperties(): {}
184+
185+
_inst: any
181186
}
182187

183188
type ParentClass = DynamicMethodsActsParentClass & DynamicMethodsCndsParentClass & DynamicMethodsExpsParentClass & StaticMethodsParentClass
@@ -201,5 +206,12 @@ interface C3 {
201206
export type GetInstanceJSFn = (
202207
parentClass: new (...args: any[]) => ParentClass,
203208
addonTriggers: string[],
204-
C3: C3
205-
) => new (...args: any[]) => ParentClass
209+
C3: C3,
210+
) => new (...args: any[]) => ParentClass
211+
212+
export type IObjectClass = {
213+
getFirstPickedInstance: (inst: unknown) => IBinaryDataInstance | null
214+
}
215+
export type IBinaryDataInstance = {
216+
setArrayBufferCopy: (buff: ArrayBuffer) => void
217+
}

0 commit comments

Comments
 (0)