@gtkx/runtime 1.0.0-rc.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/README.md +5 -5
  2. package/dist/application-class.d.ts +37 -0
  3. package/dist/application-class.d.ts.map +1 -0
  4. package/dist/application-class.js +78 -0
  5. package/dist/application-class.js.map +1 -0
  6. package/dist/arg.d.ts +2 -1
  7. package/dist/arg.d.ts.map +1 -1
  8. package/dist/arg.js +2 -1
  9. package/dist/arg.js.map +1 -1
  10. package/dist/bind.d.ts +11 -0
  11. package/dist/bind.d.ts.map +1 -1
  12. package/dist/bind.js +11 -0
  13. package/dist/bind.js.map +1 -1
  14. package/dist/callback.d.ts +4 -3
  15. package/dist/callback.d.ts.map +1 -1
  16. package/dist/callback.js +124 -29
  17. package/dist/callback.js.map +1 -1
  18. package/dist/closure.d.ts +26 -0
  19. package/dist/closure.d.ts.map +1 -0
  20. package/dist/closure.js +99 -0
  21. package/dist/closure.js.map +1 -0
  22. package/dist/default-application.d.ts +4 -0
  23. package/dist/default-application.d.ts.map +1 -0
  24. package/dist/default-application.js +17 -0
  25. package/dist/default-application.js.map +1 -0
  26. package/dist/descriptors.d.ts +98 -4
  27. package/dist/descriptors.d.ts.map +1 -1
  28. package/dist/descriptors.js +72 -6
  29. package/dist/descriptors.js.map +1 -1
  30. package/dist/error.d.ts +1 -0
  31. package/dist/error.d.ts.map +1 -1
  32. package/dist/error.js.map +1 -1
  33. package/dist/exit-hook.js +13 -0
  34. package/dist/exit-hook.js.map +1 -1
  35. package/dist/fn.d.ts +24 -2
  36. package/dist/fn.d.ts.map +1 -1
  37. package/dist/fn.js +67 -32
  38. package/dist/fn.js.map +1 -1
  39. package/dist/folded-lengths.d.ts +16 -0
  40. package/dist/folded-lengths.d.ts.map +1 -0
  41. package/dist/folded-lengths.js +38 -0
  42. package/dist/folded-lengths.js.map +1 -0
  43. package/dist/index.d.ts +14 -6
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +12 -4
  46. package/dist/index.js.map +1 -1
  47. package/dist/internal.d.ts +2 -0
  48. package/dist/internal.d.ts.map +1 -1
  49. package/dist/internal.js +2 -0
  50. package/dist/internal.js.map +1 -1
  51. package/dist/library.d.ts +3 -1
  52. package/dist/library.d.ts.map +1 -1
  53. package/dist/library.js +3 -1
  54. package/dist/library.js.map +1 -1
  55. package/dist/lifecycle.d.ts +58 -11
  56. package/dist/lifecycle.d.ts.map +1 -1
  57. package/dist/lifecycle.js +95 -22
  58. package/dist/lifecycle.js.map +1 -1
  59. package/dist/listeners.d.ts.map +1 -1
  60. package/dist/listeners.js +19 -5
  61. package/dist/listeners.js.map +1 -1
  62. package/dist/mixin.d.ts +3 -2
  63. package/dist/mixin.d.ts.map +1 -1
  64. package/dist/mixin.js +13 -1
  65. package/dist/mixin.js.map +1 -1
  66. package/dist/native-value.d.ts.map +1 -1
  67. package/dist/native-value.js +4 -3
  68. package/dist/native-value.js.map +1 -1
  69. package/dist/object.d.ts +40 -7
  70. package/dist/object.d.ts.map +1 -1
  71. package/dist/object.js +95 -26
  72. package/dist/object.js.map +1 -1
  73. package/dist/param-spec.d.ts +11 -0
  74. package/dist/param-spec.d.ts.map +1 -0
  75. package/dist/param-spec.js +147 -0
  76. package/dist/param-spec.js.map +1 -0
  77. package/dist/promisify.d.ts.map +1 -1
  78. package/dist/promisify.js +3 -2
  79. package/dist/promisify.js.map +1 -1
  80. package/dist/properties.d.ts +39 -7
  81. package/dist/properties.d.ts.map +1 -1
  82. package/dist/properties.js +310 -43
  83. package/dist/properties.js.map +1 -1
  84. package/dist/register-class.d.ts +147 -12
  85. package/dist/register-class.d.ts.map +1 -1
  86. package/dist/register-class.js +129 -83
  87. package/dist/register-class.js.map +1 -1
  88. package/dist/registry.d.ts +80 -21
  89. package/dist/registry.d.ts.map +1 -1
  90. package/dist/registry.js +86 -33
  91. package/dist/registry.js.map +1 -1
  92. package/dist/signal.d.ts +11 -4
  93. package/dist/signal.d.ts.map +1 -1
  94. package/dist/signal.js +85 -25
  95. package/dist/signal.js.map +1 -1
  96. package/dist/t.d.ts +2 -0
  97. package/dist/t.d.ts.map +1 -1
  98. package/dist/t.js +1 -0
  99. package/dist/t.js.map +1 -1
  100. package/dist/tuple.d.ts +6 -3
  101. package/dist/tuple.d.ts.map +1 -1
  102. package/dist/tuple.js +9 -7
  103. package/dist/tuple.js.map +1 -1
  104. package/dist/type.d.ts +2 -1
  105. package/dist/type.d.ts.map +1 -1
  106. package/dist/type.js +2 -0
  107. package/dist/type.js.map +1 -1
  108. package/dist/value.d.ts +10 -1
  109. package/dist/value.d.ts.map +1 -1
  110. package/dist/value.js +99 -24
  111. package/dist/value.js.map +1 -1
  112. package/dist/vfunc-call.d.ts +37 -0
  113. package/dist/vfunc-call.d.ts.map +1 -0
  114. package/dist/vfunc-call.js +172 -0
  115. package/dist/vfunc-call.js.map +1 -0
  116. package/dist/vfunc-seeds.d.ts +12 -0
  117. package/dist/vfunc-seeds.d.ts.map +1 -0
  118. package/dist/vfunc-seeds.js +19 -0
  119. package/dist/vfunc-seeds.js.map +1 -0
  120. package/dist/vfunc.d.ts +8 -0
  121. package/dist/vfunc.d.ts.map +1 -0
  122. package/dist/vfunc.js +29 -0
  123. package/dist/vfunc.js.map +1 -0
  124. package/package.json +14 -4
  125. package/src/application-class.ts +126 -0
  126. package/src/arg.ts +2 -1
  127. package/src/bind.ts +11 -0
  128. package/src/callback.ts +178 -34
  129. package/src/closure.ts +136 -0
  130. package/src/default-application.ts +21 -0
  131. package/src/descriptors.ts +150 -34
  132. package/src/error.ts +1 -0
  133. package/src/exit-hook.ts +18 -0
  134. package/src/fn.ts +107 -36
  135. package/src/folded-lengths.ts +64 -0
  136. package/src/index.ts +21 -6
  137. package/src/internal.ts +2 -0
  138. package/src/library.ts +3 -1
  139. package/src/lifecycle.ts +138 -25
  140. package/src/listeners.ts +25 -6
  141. package/src/mixin.ts +15 -2
  142. package/src/native-value.ts +5 -3
  143. package/src/object.ts +134 -35
  144. package/src/param-spec.ts +234 -0
  145. package/src/promisify.ts +4 -2
  146. package/src/properties.ts +473 -46
  147. package/src/register-class.ts +386 -114
  148. package/src/registry.ts +169 -49
  149. package/src/signal.ts +116 -42
  150. package/src/t.ts +3 -0
  151. package/src/tuple.ts +18 -12
  152. package/src/type.ts +3 -1
  153. package/src/value.ts +143 -23
  154. package/src/vfunc-call.ts +247 -0
  155. package/src/vfunc-seeds.ts +36 -0
  156. package/src/vfunc.ts +38 -0
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AAExB,cAAc;AACd,OAAO,EAAE,iBAAiB,EAAoB,MAAM,YAAY,CAAC;AACjE,cAAc;AACd,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC/E,cAAc;AACd,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACjE,cAAc;AACd,OAAO,EAAE,aAAa,EAAc,MAAM,YAAY,CAAC;AACvD,cAAc;AACd,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACzD,cAAc;AACd,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC5F,cAAc;AACd,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,cAAc;AACd,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,cAAc;AACd,OAAO,EACH,SAAS,EACT,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EAEpB,SAAS,EACT,YAAY,EACZ,UAAU,GACb,MAAM,eAAe,CAAC;AACvB,cAAc;AACd,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,iBAAiB,EAAsB,MAAM,aAAa,CAAC;AAC/F,cAAc;AACd,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAC3B,cAAc;AACd,OAAO,EACH,WAAW,EACX,YAAY,EACZ,UAAU,EACV,SAAS,EACT,WAAW,EACX,SAAS,EACT,UAAU,EACV,UAAU,EACV,UAAU,EACV,QAAQ,EACR,UAAU,EACV,cAAc,EACd,YAAY,EACZ,SAAS,EACT,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EACZ,WAAW,EACX,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,YAAY,EACZ,YAAY,EAEZ,YAAY,EACZ,cAAc,EACd,OAAO,EACP,QAAQ,EACR,UAAU,EACV,QAAQ,GACX,MAAM,WAAW,CAAC;AACnB,cAAc;AACd,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC1D,cAAc;AACd,OAAO,EAAE,KAAK,EAAoC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC","sourcesContent":["import \"./exit-hook.js\";\n\n/** @public */\nexport { createErrorDomain, type ErrorDomain } from \"./error.js\";\n/** @public */\nexport { onExit, quit, quitApplication, runApplication } from \"./lifecycle.js\";\n/** @public */\nexport { offSignal, onceSignal, onSignal } from \"./listeners.js\";\n/** @public */\nexport { installMixins, type Mixin } from \"./mixin.js\";\n/** @public */\nexport { fromNative, toNative } from \"./native-value.js\";\n/** @public */\nexport { getObjectProperty, newObjectWithProperties, setObjectProperty } from \"./object.js\";\n/** @public */\nexport { promisify } from \"./promisify.js\";\n/** @public */\nexport { registerClass } from \"./register-class.js\";\n/** @public */\nexport {\n getHandle,\n getInstanceType,\n getWrapperClass,\n registerInterface,\n registerWrapperClass,\n type StaticBase,\n setHandle,\n tryGetHandle,\n wrapHandle,\n} from \"./registry.js\";\n/** @public */\nexport { connectSignal, emitSignal, getSignalBaseName, type SignalHandler } from \"./signal.js\";\n/** @public */\nexport { t } from \"./t.js\";\n/** @public */\nexport {\n resolveType,\n TYPE_BOOLEAN,\n TYPE_BOXED,\n TYPE_CHAR,\n TYPE_DOUBLE,\n TYPE_ENUM,\n TYPE_FLAGS,\n TYPE_FLOAT,\n TYPE_GTYPE,\n TYPE_INT,\n TYPE_INT64,\n TYPE_INTERFACE,\n TYPE_INVALID,\n TYPE_LONG,\n TYPE_NONE,\n TYPE_OBJECT,\n TYPE_PARAM,\n TYPE_POINTER,\n TYPE_STRING,\n TYPE_UCHAR,\n TYPE_UINT,\n TYPE_UINT64,\n TYPE_ULONG,\n TYPE_UNICHAR,\n TYPE_VARIANT,\n type TypedClass,\n typeFromName,\n typeInterfaces,\n typeIsA,\n typeName,\n typeParent,\n valueIsA,\n} from \"./type.js\";\n/** @public */\nexport { getBoxedValue, setBoxedValue } from \"./value.js\";\n/** @public */\nexport { alloc, type ExternalObject, type Handle, read, setWrapper, write } from \"@gtkx/native\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AAExB,cAAc;AACd,OAAO,EAAsD,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC/G,cAAc;AACd,OAAO,EAAwB,mBAAmB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAClG,cAAc;AACd,OAAO,EAAE,iBAAiB,EAAoB,MAAM,YAAY,CAAC;AACjE,cAAc;AACd,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,cAAc,EAA6B,MAAM,gBAAgB,CAAC;AAC1G,cAAc;AACd,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACjE,cAAc;AACd,OAAO,EAAE,aAAa,EAAc,MAAM,YAAY,CAAC;AACvD,cAAc;AACd,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACzD,cAAc;AACd,O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ApplicationClass, type CommandLineApplication, createApplication } from \"./application-class.js\";\n/** @public */\nexport { type ClosureCallback, ClosureMarshalError, toClosure, tryToClosure } from \"./closure.js\";\n/** @public */\nexport { createErrorDomain, type ErrorDomain } from \"./error.js\";\n/** @public */\nexport { onExit, quit, quitApplication, runApplication, type RunApplicationResult } from \"./lifecycle.js\";\n/** @public */\nexport { offSignal, onceSignal, onSignal } from \"./listeners.js\";\n/** @public */\nexport { installMixins, type Mixin } from \"./mixin.js\";\n/** @public */\nexport { fromNative, toNative } from \"./native-value.js\";\n/** @public */\nexport {\n type ConstructBinding,\n type ConstructBindings,\n getObjectProperty,\n newObjectWithProperties,\n registerConstructProperties,\n setObjectProperty,\n} from \"./object.js\";\n/** @public */\nexport { promisify } from \"./promisify.js\";\n/** @public */\nexport { type Interface, registerClass } from \"./register-class.js\";\n/** @public */\nexport {\n getClassType,\n getHandle,\n getInstanceType,\n getWrapperClass,\n registerInterface,\n registerWrapperClass,\n type StaticBase,\n setHandle,\n wrapHandle,\n} from \"./registry.js\";\n/** @public */\nexport { connectSignal, disconnectSignal, emitSignal, getSignalBaseName, type SignalHandler } from \"./signal.js\";\n/** @public */\nexport { t } from \"./t.js\";\n/** @public */\nexport {\n resolveType,\n TYPE_BOOLEAN,\n TYPE_BOXED,\n TYPE_CHAR,\n TYPE_DOUBLE,\n TYPE_ENUM,\n TYPE_FLAGS,\n TYPE_FLOAT,\n TYPE_GTYPE,\n TYPE_INT,\n TYPE_INT64,\n TYPE_INTERFACE,\n TYPE_INVALID,\n TYPE_LONG,\n TYPE_NONE,\n TYPE_OBJECT,\n TYPE_PARAM,\n TYPE_POINTER,\n TYPE_STRING,\n TYPE_UCHAR,\n TYPE_UINT,\n TYPE_UINT64,\n TYPE_ULONG,\n TYPE_UNICHAR,\n TYPE_VARIANT,\n type TypedClass,\n typeFromName,\n typeInterfaces,\n typeIsA,\n typeName,\n typeParent,\n valueIsA,\n} from \"./type.js\";\n/** @public */\nexport { getBoxedValue, setBoxedValue } from \"./value.js\";\n/** @public */\nexport { callParent, callVfunc } from \"./vfunc-call.js\";\n/** @public */\nexport { alloc, type ExternalObject, type Handle, read, write } from \"@gtkx/native\";\n/** @public */\nexport { type AnyClass } from \"@gtkx/utils\";\n"]}
@@ -1,5 +1,7 @@
1
1
  export { checkError, createErrorDomain } from "./error.js";
2
+ export { type ApplicationInstance, getApplicationInstance } from "./lifecycle.js";
2
3
  export { registerClassType, resolveWrapperClass, wrapHandle } from "./registry.js";
4
+ export { hasSignalListener } from "./signal.js";
3
5
  export { resolveType } from "./type.js";
4
6
  export { fromValue, getBoxedValue, getValueType, inoutValueForBoxedDescriptor, newValueForDescriptor, outValueForBoxedDescriptor, toValue, } from "./value.js";
5
7
  //# sourceMappingURL=internal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EACH,SAAS,EACT,aAAa,EACb,YAAY,EACZ,4BAA4B,EAC5B,qBAAqB,EACrB,0BAA0B,EAC1B,OAAO,GACV,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,KAAK,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EACH,SAAS,EACT,aAAa,EACb,YAAY,EACZ,4BAA4B,EAC5B,qBAAqB,EACrB,0BAA0B,EAC1B,OAAO,GACV,MAAM,YAAY,CAAC"}
package/dist/internal.js CHANGED
@@ -1,5 +1,7 @@
1
1
  export { checkError, createErrorDomain } from "./error.js";
2
+ export { getApplicationInstance } from "./lifecycle.js";
2
3
  export { registerClassType, resolveWrapperClass, wrapHandle } from "./registry.js";
4
+ export { hasSignalListener } from "./signal.js";
3
5
  export { resolveType } from "./type.js";
4
6
  export { fromValue, getBoxedValue, getValueType, inoutValueForBoxedDescriptor, newValueForDescriptor, outValueForBoxedDescriptor, toValue, } from "./value.js";
5
7
  //# sourceMappingURL=internal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EACH,SAAS,EACT,aAAa,EACb,YAAY,EACZ,4BAA4B,EAC5B,qBAAqB,EACrB,0BAA0B,EAC1B,OAAO,GACV,MAAM,YAAY,CAAC","sourcesContent":["export { checkError, createErrorDomain } from \"./error.js\";\nexport { registerClassType, resolveWrapperClass, wrapHandle } from \"./registry.js\";\nexport { resolveType } from \"./type.js\";\nexport {\n fromValue,\n getBoxedValue,\n getValueType,\n inoutValueForBoxedDescriptor,\n newValueForDescriptor,\n outValueForBoxedDescriptor,\n toValue,\n} from \"./value.js\";\n"]}
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAA4B,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EACH,SAAS,EACT,aAAa,EACb,YAAY,EACZ,4BAA4B,EAC5B,qBAAqB,EACrB,0BAA0B,EAC1B,OAAO,GACV,MAAM,YAAY,CAAC","sourcesContent":["export { checkError, createErrorDomain } from \"./error.js\";\nexport { type ApplicationInstance, getApplicationInstance } from \"./lifecycle.js\";\nexport { registerClassType, resolveWrapperClass, wrapHandle } from \"./registry.js\";\nexport { hasSignalListener } from \"./signal.js\";\nexport { resolveType } from \"./type.js\";\nexport {\n fromValue,\n getBoxedValue,\n getValueType,\n inoutValueForBoxedDescriptor,\n newValueForDescriptor,\n outValueForBoxedDescriptor,\n toValue,\n} from \"./value.js\";\n"]}
package/dist/library.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import { type BoxedDescriptor, type FundamentalDescriptor } from "./descriptors.js";
2
2
  declare const LIB = "libgobject-2.0.so.0,libglib-2.0.so.0";
3
+ declare const GIO_LIB = "libgio-2.0.so.0";
3
4
  declare const VALUE_SIZE = 24;
5
+ declare const CLOSURE_SIZE = 32;
4
6
  declare const VALUE_T: BoxedDescriptor;
5
7
  declare const PARAM_T: FundamentalDescriptor;
6
8
  declare const VARIANT_T: FundamentalDescriptor;
7
- export { LIB, VALUE_SIZE, VALUE_T, PARAM_T, VARIANT_T };
9
+ export { CLOSURE_SIZE, GIO_LIB, LIB, VALUE_SIZE, VALUE_T, PARAM_T, VARIANT_T };
8
10
  //# sourceMappingURL=library.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAU,KAAK,qBAAqB,EAAgB,MAAM,kBAAkB,CAAC;AAE1G,QAAA,MAAM,GAAG,yCAAyC,CAAC;AACnD,QAAA,MAAM,UAAU,KAAK,CAAC;AACtB,QAAA,MAAM,OAAO,EAAE,eAA6F,CAAC;AAE7G,QAAA,MAAM,OAAO,EAAE,qBAGb,CAAC;AAEH,QAAA,MAAM,SAAS,EAAE,qBAGf,CAAC;AAEH,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAU,KAAK,qBAAqB,EAAgB,MAAM,kBAAkB,CAAC;AAE1G,QAAA,MAAM,GAAG,yCAAyC,CAAC;AACnD,QAAA,MAAM,OAAO,oBAAoB,CAAC;AAClC,QAAA,MAAM,UAAU,KAAK,CAAC;AACtB,QAAA,MAAM,YAAY,KAAK,CAAC;AACxB,QAAA,MAAM,OAAO,EAAE,eAA6F,CAAC;AAE7G,QAAA,MAAM,OAAO,EAAE,qBAGb,CAAC;AAEH,QAAA,MAAM,SAAS,EAAE,qBAGf,CAAC;AAEH,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC"}
package/dist/library.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { boxedT, fundamentalT } from "./descriptors.js";
2
2
  const LIB = "libgobject-2.0.so.0,libglib-2.0.so.0";
3
+ const GIO_LIB = "libgio-2.0.so.0";
3
4
  const VALUE_SIZE = 24;
5
+ const CLOSURE_SIZE = 32;
4
6
  const VALUE_T = boxedT("GValue", { sharedLibrary: LIB, getTypeFnName: "g_value_get_type" });
5
7
  const PARAM_T = fundamentalT(LIB, "g_param_spec_ref", "g_param_spec_unref", {
6
8
  ownership: "borrowed",
@@ -10,5 +12,5 @@ const VARIANT_T = fundamentalT(LIB, "g_variant_ref", "g_variant_unref", {
10
12
  ownership: "borrowed",
11
13
  typeName: "GVariant",
12
14
  });
13
- export { LIB, VALUE_SIZE, VALUE_T, PARAM_T, VARIANT_T };
15
+ export { CLOSURE_SIZE, GIO_LIB, LIB, VALUE_SIZE, VALUE_T, PARAM_T, VARIANT_T };
14
16
  //# sourceMappingURL=library.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"library.js","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,MAAM,EAA8B,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE1G,MAAM,GAAG,GAAG,sCAAsC,CAAC;AACnD,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,OAAO,GAAoB,MAAM,CAAC,QAAQ,EAAE,EAAE,aAAa,EAAE,GAAG,EAAE,aAAa,EAAE,kBAAkB,EAAE,CAAC,CAAC;AAE7G,MAAM,OAAO,GAA0B,YAAY,CAAC,GAAG,EAAE,kBAAkB,EAAE,oBAAoB,EAAE;IAC/F,SAAS,EAAE,UAAU;IACrB,QAAQ,EAAE,QAAQ;CACrB,CAAC,CAAC;AAEH,MAAM,SAAS,GAA0B,YAAY,CAAC,GAAG,EAAE,eAAe,EAAE,iBAAiB,EAAE;IAC3F,SAAS,EAAE,UAAU;IACrB,QAAQ,EAAE,UAAU;CACvB,CAAC,CAAC;AAEH,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import { type BoxedDescriptor, boxedT, type FundamentalDescriptor, fundamentalT } from \"./descriptors.js\";\n\nconst LIB = \"libgobject-2.0.so.0,libglib-2.0.so.0\";\nconst VALUE_SIZE = 24;\nconst VALUE_T: BoxedDescriptor = boxedT(\"GValue\", { sharedLibrary: LIB, getTypeFnName: \"g_value_get_type\" });\n\nconst PARAM_T: FundamentalDescriptor = fundamentalT(LIB, \"g_param_spec_ref\", \"g_param_spec_unref\", {\n ownership: \"borrowed\",\n typeName: \"GParam\",\n});\n\nconst VARIANT_T: FundamentalDescriptor = fundamentalT(LIB, \"g_variant_ref\", \"g_variant_unref\", {\n ownership: \"borrowed\",\n typeName: \"GVariant\",\n});\n\nexport { LIB, VALUE_SIZE, VALUE_T, PARAM_T, VARIANT_T };\n"]}
1
+ {"version":3,"file":"library.js","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,MAAM,EAA8B,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAE1G,MAAM,GAAG,GAAG,sCAAsC,CAAC;AACnD,MAAM,OAAO,GAAG,iBAAiB,CAAC;AAClC,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,MAAM,OAAO,GAAoB,MAAM,CAAC,QAAQ,EAAE,EAAE,aAAa,EAAE,GAAG,EAAE,aAAa,EAAE,kBAAkB,EAAE,CAAC,CAAC;AAE7G,MAAM,OAAO,GAA0B,YAAY,CAAC,GAAG,EAAE,kBAAkB,EAAE,oBAAoB,EAAE;IAC/F,SAAS,EAAE,UAAU;IACrB,QAAQ,EAAE,QAAQ;CACrB,CAAC,CAAC;AAEH,MAAM,SAAS,GAA0B,YAAY,CAAC,GAAG,EAAE,eAAe,EAAE,iBAAiB,EAAE;IAC3F,SAAS,EAAE,UAAU;IACrB,QAAQ,EAAE,UAAU;CACvB,CAAC,CAAC;AAEH,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import { type BoxedDescriptor, boxedT, type FundamentalDescriptor, fundamentalT } from \"./descriptors.js\";\n\nconst LIB = \"libgobject-2.0.so.0,libglib-2.0.so.0\";\nconst GIO_LIB = \"libgio-2.0.so.0\";\nconst VALUE_SIZE = 24;\nconst CLOSURE_SIZE = 32;\nconst VALUE_T: BoxedDescriptor = boxedT(\"GValue\", { sharedLibrary: LIB, getTypeFnName: \"g_value_get_type\" });\n\nconst PARAM_T: FundamentalDescriptor = fundamentalT(LIB, \"g_param_spec_ref\", \"g_param_spec_unref\", {\n ownership: \"borrowed\",\n typeName: \"GParam\",\n});\n\nconst VARIANT_T: FundamentalDescriptor = fundamentalT(LIB, \"g_variant_ref\", \"g_variant_unref\", {\n ownership: \"borrowed\",\n typeName: \"GVariant\",\n});\n\nexport { CLOSURE_SIZE, GIO_LIB, LIB, VALUE_SIZE, VALUE_T, PARAM_T, VARIANT_T };\n"]}
@@ -6,13 +6,16 @@
6
6
  type ApplicationLike = {
7
7
  /** Returns whether the application has already been registered. */
8
8
  getIsRegistered(): boolean;
9
+ /** Returns whether another process owns the application ID, making this one a remote instance. */
10
+ getIsRemote?(): boolean;
9
11
  /** Registers the application with the session, returning whether it succeeded. */
10
12
  register(cancellable: null): boolean;
11
13
  /** Emits `activate`, bringing up the application's initial user interface. */
12
14
  activate(): void;
13
- /** Quits the application, so `run` returns at the next main-loop iteration after `shutdown` runs. */
14
- quit(): void;
15
- /** Runs the application's main loop until it shuts down and returns the exit status. */
15
+ /**
16
+ * Runs GLib's own `g_application_run`, whose tail emits `shutdown`, destroys the application
17
+ * implementation and clears the registration.
18
+ */
16
19
  run(argv: string[]): number;
17
20
  /** Returns the windows currently attached to the application. */
18
21
  getWindows?(): object[];
@@ -20,6 +23,16 @@ type ApplicationLike = {
20
23
  removeWindow?(window: object): void;
21
24
  /** Connects a handler to the application's `activate` or `shutdown` signal. */
22
25
  on(signal: "activate" | "shutdown", handler: () => void): unknown;
26
+ /** Emits one of the application's own signals. */
27
+ emit(signal: "shutdown"): unknown;
28
+ };
29
+ type ApplicationInstance = "primary" | "remote" | "shutDown" | "unregistered";
30
+ /** What {@link runApplication} reports about the process it just started. */
31
+ type RunApplicationResult = {
32
+ /** Whether this process owns the application ID and may build a user interface. */
33
+ isPrimary: boolean;
34
+ /** The status GLib determined for the command line, which the process should exit with. */
35
+ exitStatus: number;
23
36
  };
24
37
  /**
25
38
  * Runs every registered exit callback and shuts down the native runtime. Safe to
@@ -33,20 +46,54 @@ declare const quit: () => void;
33
46
  * @param callback Invoked during shutdown.
34
47
  */
35
48
  declare const onExit: (callback: () => void) => void;
49
+ declare const getApplicationInstance: (application: ApplicationLike) => ApplicationInstance;
36
50
  /**
37
- * Registers the application if needed and activates it, keeping the runtime alive
38
- * while it is active and releasing it on shutdown.
51
+ * Hands `argv` to GLib's own command line handling, which parses the application's options, prints
52
+ * `--help`, runs `handle-local-options`, registers the application, and either activates it or
53
+ * forwards the command line to the process that already owns the application ID. The runtime is
54
+ * held alive while the application is active and released on shutdown.
55
+ *
56
+ * `g_application_run()` is not what starts the application, because it would drive its own main loop
57
+ * and freeze Node; only the local command line handling it delegates to runs here. {@link
58
+ * quitApplication} calls it once no window holds the application open, to reach the teardown only it
59
+ * performs.
60
+ *
61
+ * GLib parses a given application's command line at most once, so starting an application that has
62
+ * already run registers and activates it instead of reading `argv` again.
63
+ *
64
+ * When another process already owns the application ID, this one registers as a remote instance: no
65
+ * user interface may be built here, because a remote application has no `GtkApplicationImpl` and
66
+ * attaching a window to it crashes.
39
67
  *
40
- * @param application The application to register and activate.
68
+ * The application also claims the process-wide default `Gio.Application.getDefault()` returns, before
69
+ * its command line is parsed, so an `activate` handler and anything the host reads afterwards see the
70
+ * application being started rather than an earlier one. That holds whether the start ends registered,
71
+ * remote or unregistered: a refused command line still has to be reportable through the default, which
72
+ * is how `gtkx dev` learns which application its entry mounted. {@link quitApplication} gives the
73
+ * default back up, since GLib drops it only at finalize.
74
+ *
75
+ * @param application The application to start.
76
+ * @param argv The command line, whose first entry names the program as `--help` should print it.
77
+ * @returns Whether this process may build a user interface, and the status to exit with.
41
78
  */
42
- declare const runApplication: (application: ApplicationLike) => void;
79
+ declare const runApplication: (application: ApplicationLike, argv: string[]) => RunApplicationResult;
43
80
  /**
44
- * Detaches every window from the application and runs its main loop until it shuts
45
- * down, so pending shutdown work completes before the process exits. Does nothing
46
- * when the application was never registered.
81
+ * Detaches every window from the application and runs GLib's own shutdown, which emits `shutdown`,
82
+ * destroys the application implementation and releases the D-Bus registration. Does nothing for an
83
+ * application that is not registered, so a repeated call is a no-op.
84
+ *
85
+ * GLib's own shutdown is reachable once per application: reaching it marks the application as
86
+ * quitting, which GLib never undoes. An application that has already quit falls back to emitting
87
+ * `shutdown`, which releases the runtime and leaves the registration for GLib to drop at finalize.
88
+ *
89
+ * The process-wide default {@link runApplication} claimed is given up whichever of those paths the
90
+ * application took, including the ones that have no teardown left to do, so
91
+ * `Gio.Application.getDefault()` never hands back an application that has been torn down or that
92
+ * never registered in the first place. GLib clears that default only at finalize, which a
93
+ * garbage-collected wrapper reaches arbitrarily late or never.
47
94
  *
48
95
  * @param application The application to shut down.
49
96
  */
50
97
  declare const quitApplication: (application: ApplicationLike) => void;
51
- export { onExit, quit, runApplication, quitApplication, type ApplicationLike };
98
+ export { getApplicationInstance, onExit, quit, runApplication, quitApplication, type ApplicationInstance, type RunApplicationResult, };
52
99
  //# sourceMappingURL=lifecycle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,KAAK,eAAe,GAAG;IACnB,mEAAmE;IACnE,eAAe,IAAI,OAAO,CAAC;IAC3B,kFAAkF;IAClF,QAAQ,CAAC,WAAW,EAAE,IAAI,GAAG,OAAO,CAAC;IACrC,8EAA8E;IAC9E,QAAQ,IAAI,IAAI,CAAC;IACjB,qGAAqG;IACrG,IAAI,IAAI,IAAI,CAAC;IACb,wFAAwF;IACxF,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC5B,iEAAiE;IACjE,UAAU,CAAC,IAAI,MAAM,EAAE,CAAC;IACxB,qEAAqE;IACrE,YAAY,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,+EAA+E;IA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KAAK,mBAAmB,GAAG,SAAS,GAAG,QAAQ,GAAG,UAAU,GAAG,cAAc,CAAC;AAE9E,6EAA6E;AAC7E,KAAK,oBAAoB,GAAG;IACxB,mFAAmF;IACnF,SAAS,EAAE,OAAO,CAAC;IACnB,2FAA2F;IAC3F,UAAU,EAAE,MAAM,CAAC;CACtB,CAAC;AAMF;;;GAGG;AACH,QAAA,MAAM,IAAI,EAAE,MAAM,IAAmB,CAAC;AAoBtC;;;;;GAKG;AACH,QAAA,MAAM,MAAM,GAAI,UAAU,MAAM,IAAI,KAAG,IAEtC,CAAC;AA4BF,QAAA,MAAM,sBAAsB,GAAI,aAAa,eAAe,KAAG,mBAM9D,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,QAAA,MAAM,cAAc,GAAI,aAAa,eAAe,EAAE,MAAM,MAAM,EAAE,KAAG,oBA4BtE,CAAC;AAqBF;;;;;;;;;;;;;;;;GAgBG;AACH,QAAA,MAAM,eAAe,GAAI,aAAa,eAAe,KAAG,IAGvD,CAAC;AAEF,OAAO,EACH,sBAAsB,EACtB,MAAM,EACN,IAAI,EACJ,cAAc,EACd,eAAe,EACf,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,GAC5B,CAAC"}
package/dist/lifecycle.js CHANGED
@@ -1,6 +1,10 @@
1
1
  import { keepAlive, quit as nativeQuit } from "@gtkx/native";
2
- import { blockMatchedSignalHandlers } from "./signal.js";
2
+ import { isDerivedApplication, shutDownThroughRun } from "./application-class.js";
3
+ import { claimDefaultApplication, releaseDefaultApplication } from "./default-application.js";
3
4
  const shutdownCallbacks = [];
5
+ const startedApplications = new WeakSet();
6
+ const registeredApplications = new WeakSet();
7
+ const shutDownApplications = new WeakSet();
4
8
  /**
5
9
  * Runs every registered exit callback and shuts down the native runtime. Safe to
6
10
  * call more than once; only the first call takes effect.
@@ -28,44 +32,113 @@ function createQuit() {
28
32
  const onExit = (callback) => {
29
33
  shutdownCallbacks.push(callback);
30
34
  };
31
- /**
32
- * Registers the application if needed and activates it, keeping the runtime alive
33
- * while it is active and releasing it on shutdown.
34
- *
35
- * @param application The application to register and activate.
36
- */
37
- const runApplication = (application) => {
35
+ const startApplication = (application, argv) => {
36
+ startedApplications.add(application);
38
37
  application.on("activate", () => {
39
38
  keepAlive(true);
40
39
  });
41
40
  application.on("shutdown", () => {
42
41
  keepAlive(false);
43
42
  });
44
- if (!application.getIsRegistered()) {
45
- application.register(null);
43
+ return application.runLocalCommandLine(argv)[2];
44
+ };
45
+ const restartApplication = (application) => {
46
+ shutDownApplications.delete(application);
47
+ if (!application.register(null)) {
48
+ return 1;
46
49
  }
47
50
  application.activate();
51
+ return 0;
52
+ };
53
+ const getApplicationInstance = (application) => {
54
+ if (!application.getIsRegistered()) {
55
+ return registeredApplications.has(application) ? "shutDown" : "unregistered";
56
+ }
57
+ return application.getIsRemote?.() === true ? "remote" : "primary";
48
58
  };
49
59
  /**
50
- * Detaches every window from the application and runs its main loop until it shuts
51
- * down, so pending shutdown work completes before the process exits. Does nothing
52
- * when the application was never registered.
60
+ * Hands `argv` to GLib's own command line handling, which parses the application's options, prints
61
+ * `--help`, runs `handle-local-options`, registers the application, and either activates it or
62
+ * forwards the command line to the process that already owns the application ID. The runtime is
63
+ * held alive while the application is active and released on shutdown.
53
64
  *
54
- * @param application The application to shut down.
65
+ * `g_application_run()` is not what starts the application, because it would drive its own main loop
66
+ * and freeze Node; only the local command line handling it delegates to runs here. {@link
67
+ * quitApplication} calls it once no window holds the application open, to reach the teardown only it
68
+ * performs.
69
+ *
70
+ * GLib parses a given application's command line at most once, so starting an application that has
71
+ * already run registers and activates it instead of reading `argv` again.
72
+ *
73
+ * When another process already owns the application ID, this one registers as a remote instance: no
74
+ * user interface may be built here, because a remote application has no `GtkApplicationImpl` and
75
+ * attaching a window to it crashes.
76
+ *
77
+ * The application also claims the process-wide default `Gio.Application.getDefault()` returns, before
78
+ * its command line is parsed, so an `activate` handler and anything the host reads afterwards see the
79
+ * application being started rather than an earlier one. That holds whether the start ends registered,
80
+ * remote or unregistered: a refused command line still has to be reportable through the default, which
81
+ * is how `gtkx dev` learns which application its entry mounted. {@link quitApplication} gives the
82
+ * default back up, since GLib drops it only at finalize.
83
+ *
84
+ * @param application The application to start.
85
+ * @param argv The command line, whose first entry names the program as `--help` should print it.
86
+ * @returns Whether this process may build a user interface, and the status to exit with.
55
87
  */
56
- const quitApplication = (application) => {
57
- if (!application.getIsRegistered()) {
88
+ const runApplication = (application, argv) => {
89
+ if (!isDerivedApplication(application)) {
90
+ throw new Error("runApplication: this application was not built by GTKX, so its command line cannot be " +
91
+ "parsed and it cannot be shut down safely; render <GtkApplication> or <AdwApplication>, " +
92
+ "or construct it with createApplication from @gtkx/runtime");
93
+ }
94
+ claimDefaultApplication(application);
95
+ const exitStatus = startedApplications.has(application)
96
+ ? restartApplication(application)
97
+ : startApplication(application, argv);
98
+ const instance = getApplicationInstance(application);
99
+ if (instance !== "unregistered") {
100
+ registeredApplications.add(application);
101
+ }
102
+ const isPrimary = instance === "primary";
103
+ if (isPrimary) {
104
+ keepAlive(true);
105
+ }
106
+ return { isPrimary, exitStatus };
107
+ };
108
+ const tearDownApplication = (application) => {
109
+ if (!application.getIsRegistered() || shutDownApplications.has(application)) {
58
110
  return;
59
111
  }
60
112
  const windows = application.getWindows?.() ?? [];
61
113
  for (const window of windows) {
62
114
  application.removeWindow?.(window);
63
115
  }
64
- application.on("shutdown", () => {
65
- application.quit();
66
- });
67
- blockMatchedSignalHandlers(application, "activate");
68
- application.run([]);
116
+ shutDownThroughRun(application);
117
+ if (application.getIsRegistered()) {
118
+ shutDownApplications.add(application);
119
+ application.emit("shutdown");
120
+ }
121
+ };
122
+ /**
123
+ * Detaches every window from the application and runs GLib's own shutdown, which emits `shutdown`,
124
+ * destroys the application implementation and releases the D-Bus registration. Does nothing for an
125
+ * application that is not registered, so a repeated call is a no-op.
126
+ *
127
+ * GLib's own shutdown is reachable once per application: reaching it marks the application as
128
+ * quitting, which GLib never undoes. An application that has already quit falls back to emitting
129
+ * `shutdown`, which releases the runtime and leaves the registration for GLib to drop at finalize.
130
+ *
131
+ * The process-wide default {@link runApplication} claimed is given up whichever of those paths the
132
+ * application took, including the ones that have no teardown left to do, so
133
+ * `Gio.Application.getDefault()` never hands back an application that has been torn down or that
134
+ * never registered in the first place. GLib clears that default only at finalize, which a
135
+ * garbage-collected wrapper reaches arbitrarily late or never.
136
+ *
137
+ * @param application The application to shut down.
138
+ */
139
+ const quitApplication = (application) => {
140
+ tearDownApplication(application);
141
+ releaseDefaultApplication(application);
69
142
  };
70
- export { onExit, quit, runApplication, quitApplication };
143
+ export { getApplicationInstance, onExit, quit, runApplication, quitApplication, };
71
144
  //# sourceMappingURL=lifecycle.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AA0BzD,MAAM,iBAAiB,GAAmB,EAAE,CAAC;AAC7C;;;GAGG;AACH,MAAM,IAAI,GAAe,UAAU,EAAE,CAAC;AAEtC,SAAS,UAAU;IACf,IAAI,OAAO,GAAG,KAAK,CAAC;IAEpB,OAAO,GAAG,EAAE;QACR,IAAI,OAAO,EAAE,CAAC;YACV,OAAO;QACX,CAAC;QAED,OAAO,GAAG,IAAI,CAAC;QAEf,KAAK,MAAM,QAAQ,IAAI,iBAAiB,EAAE,CAAC;YACvC,QAAQ,EAAE,CAAC;QACf,CAAC;QAED,UAAU,EAAE,CAAC;IACjB,CAAC,CAAC;AACN,CAAC;AAED;;;;;GAKG;AACH,MAAM,MAAM,GAAG,CAAC,QAAoB,EAAQ,EAAE;IAC1C,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,cAAc,GAAG,CAAC,WAA4B,EAAQ,EAAE;IAC1D,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE;QAC5B,SAAS,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE;QAC5B,SAAS,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,EAAE,CAAC;QACjC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,WAAW,CAAC,QAAQ,EAAE,CAAC;AAC3B,CAAC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,eAAe,GAAG,CAAC,WAA4B,EAAQ,EAAE;IAC3D,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,EAAE,CAAC;QACjC,OAAO;IACX,CAAC;IAED,MAAM,OAAO,GAAG,WAAW,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC;IAEjD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC3B,WAAW,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE;QAC5B,WAAW,CAAC,IAAI,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,0BAA0B,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACpD,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AACxB,CAAC,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,eAAe,EAAwB,CAAC","sourcesContent":["import { keepAlive, quit as nativeQuit } from \"@gtkx/native\";\nimport { blockMatchedSignalHandlers } from \"./signal.js\";\n\n/**\n * The GIO and GTK application surface {@link runApplication} and {@link quitApplication} drive, so any\n * application subclass satisfies it structurally; the window members only `Gtk.Application` defines are\n * optional.\n */\ntype ApplicationLike = {\n /** Returns whether the application has already been registered. */\n getIsRegistered(): boolean;\n /** Registers the application with the session, returning whether it succeeded. */\n register(cancellable: null): boolean;\n /** Emits `activate`, bringing up the application's initial user interface. */\n activate(): void;\n /** Quits the application, so `run` returns at the next main-loop iteration after `shutdown` runs. */\n quit(): void;\n /** Runs the application's main loop until it shuts down and returns the exit status. */\n run(argv: string[]): number;\n /** Returns the windows currently attached to the application. */\n getWindows?(): object[];\n /** Detaches a window, so it no longer holds the application open. */\n removeWindow?(window: object): void;\n /** Connects a handler to the application's `activate` or `shutdown` signal. */\n on(signal: \"activate\" | \"shutdown\", handler: () => void): unknown;\n};\n\nconst shutdownCallbacks: (() => void)[] = [];\n/**\n * Runs every registered exit callback and shuts down the native runtime. Safe to\n * call more than once; only the first call takes effect.\n */\nconst quit: () => void = createQuit();\n\nfunction createQuit(): () => void {\n let hasQuit = false;\n\n return () => {\n if (hasQuit) {\n return;\n }\n\n hasQuit = true;\n\n for (const callback of shutdownCallbacks) {\n callback();\n }\n\n nativeQuit();\n };\n}\n\n/**\n * Registers a callback to run once when the process quits, before the native\n * runtime is torn down.\n *\n * @param callback Invoked during shutdown.\n */\nconst onExit = (callback: () => void): void => {\n shutdownCallbacks.push(callback);\n};\n\n/**\n * Registers the application if needed and activates it, keeping the runtime alive\n * while it is active and releasing it on shutdown.\n *\n * @param application The application to register and activate.\n */\nconst runApplication = (application: ApplicationLike): void => {\n application.on(\"activate\", () => {\n keepAlive(true);\n });\n\n application.on(\"shutdown\", () => {\n keepAlive(false);\n });\n\n if (!application.getIsRegistered()) {\n application.register(null);\n }\n\n application.activate();\n};\n\n/**\n * Detaches every window from the application and runs its main loop until it shuts\n * down, so pending shutdown work completes before the process exits. Does nothing\n * when the application was never registered.\n *\n * @param application The application to shut down.\n */\nconst quitApplication = (application: ApplicationLike): void => {\n if (!application.getIsRegistered()) {\n return;\n }\n\n const windows = application.getWindows?.() ?? [];\n\n for (const window of windows) {\n application.removeWindow?.(window);\n }\n\n application.on(\"shutdown\", () => {\n application.quit();\n });\n\n blockMatchedSignalHandlers(application, \"activate\");\n application.run([]);\n};\n\nexport { onExit, quit, runApplication, quitApplication, type ApplicationLike };\n"]}
1
+ {"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAoC,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACpH,OAAO,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAyC9F,MAAM,iBAAiB,GAAmB,EAAE,CAAC;AAC7C,MAAM,mBAAmB,GAAoB,IAAI,OAAO,EAAE,CAAC;AAC3D,MAAM,sBAAsB,GAAoB,IAAI,OAAO,EAAE,CAAC;AAC9D,MAAM,oBAAoB,GAAoB,IAAI,OAAO,EAAE,CAAC;AAC5D;;;GAGG;AACH,MAAM,IAAI,GAAe,UAAU,EAAE,CAAC;AAEtC,SAAS,UAAU;IACf,IAAI,OAAO,GAAG,KAAK,CAAC;IAEpB,OAAO,GAAG,EAAE;QACR,IAAI,OAAO,EAAE,CAAC;YACV,OAAO;QACX,CAAC;QAED,OAAO,GAAG,IAAI,CAAC;QAEf,KAAK,MAAM,QAAQ,IAAI,iBAAiB,EAAE,CAAC;YACvC,QAAQ,EAAE,CAAC;QACf,CAAC;QAED,UAAU,EAAE,CAAC;IACjB,CAAC,CAAC;AACN,CAAC;AAED;;;;;GAKG;AACH,MAAM,MAAM,GAAG,CAAC,QAAoB,EAAQ,EAAE;IAC1C,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,WAA0D,EAAE,IAAc,EAAU,EAAE;IAC5G,mBAAmB,CAAC,GAAG,CAAC,WAAW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AmB,CAAC,WAAW,CAAC,CAAC;IACjC,yBAAyB,CAAC,WAAW,CAAC,CAAC;AAC3C,CAAC,CAAC;AAEF,OAAO,EACH,sBAAsB,EACtB,MAAM,EACN,IAAI,EACJ,cAAc,EACd,eAAe,GAGlB,CAAC","sourcesContent":["import { keepAlive, quit as nativeQuit } from \"@gtkx/native\";\nimport { isDerivedApplication, type LocalCommandLineApplication, shutDownThroughRun } from \"./application-class.js\";\nimport { claimDefaultApplication, releaseDefaultApplication } from \"./default-application.js\";\n\n/**\n * The GIO and GTK application surface {@link runApplication} and {@link quitApplication} drive, so any\n * application subclass satisfies it structurally; the window members only `Gtk.Application` defines are\n * optional.\n */\ntype ApplicationLike = {\n /** Returns whether the application has already been registered. */\n getIsRegistered(): boolean;\n /** Returns whether another process owns the application ID, making this one a remote instance. */\n getIsRemote?(): boolean;\n /** Registers the application with the session, returning whether it succeeded. */\n register(cancellable: null): boolean;\n /** Emits `activate`, bringing up the application's initial user interface. */\n activate(): void;\n /**\n * Runs GLib's own `g_application_run`, whose tail emits `shutdown`, destroys the application\n * implementation and clears the registration.\n */\n run(argv: string[]): number;\n /** Returns the windows currently attached to the application. */\n getWindows?(): object[];\n /** Detaches a window, so it no longer holds the application open. */\n removeWindow?(window: object): void;\n /** Connects a handler to the application's `activate` or `shutdown` signal. */\n on(signal: \"activate\" | \"shutdown\", handler: () => void): unknown;\n /** Emits one of the application's own signals. */\n emit(signal: \"shutdown\"): unknown;\n};\n\ntype ApplicationInstance = \"primary\" | \"remote\" | \"shutDown\" | \"unregistered\";\n\n/** What {@link runApplication} reports about the process it just started. */\ntype RunApplicationResult = {\n /** Whether this process owns the application ID and may build a user interface. */\n isPrimary: boolean;\n /** The status GLib determined for the command line, which the process should exit with. */\n exitStatus: number;\n};\n\nconst shutdownCallbacks: (() => void)[] = [];\nconst startedApplications: WeakSet<object> = new WeakSet();\nconst registeredApplications: WeakSet<object> = new WeakSet();\nconst shutDownApplications: WeakSet<object> = new WeakSet();\n/**\n * Runs every registered exit callback and shuts down the native runtime. Safe to\n * call more than once; only the first call takes effect.\n */\nconst quit: () => void = createQuit();\n\nfunction createQuit(): () => void {\n let hasQuit = false;\n\n return () => {\n if (hasQuit) {\n return;\n }\n\n hasQuit = true;\n\n for (const callback of shutdownCallbacks) {\n callback();\n }\n\n nativeQuit();\n };\n}\n\n/**\n * Registers a callback to run once when the process quits, before the native\n * runtime is torn down.\n *\n * @param callback Invoked during shutdown.\n */\nconst onExit = (callback: () => void): void => {\n shutdownCallbacks.push(callback);\n};\n\nconst startApplication = (application: ApplicationLike & LocalCommandLineApplication, argv: string[]): number => {\n startedApplications.add(application);\n\n application.on(\"activate\", () => {\n keepAlive(true);\n });\n\n application.on(\"shutdown\", () => {\n keepAlive(false);\n });\n\n return application.runLocalCommandLine(argv)[2];\n};\n\nconst restartApplication = (application: ApplicationLike): number => {\n shutDownApplications.delete(application);\n\n if (!application.register(null)) {\n return 1;\n }\n\n application.activate();\n\n return 0;\n};\n\nconst getApplicationInstance = (application: ApplicationLike): ApplicationInstance => {\n if (!application.getIsRegistered()) {\n return registeredApplications.has(application) ? \"shutDown\" : \"unregistered\";\n }\n\n return application.getIsRemote?.() === true ? \"remote\" : \"primary\";\n};\n\n/**\n * Hands `argv` to GLib's own command line handling, which parses the application's options, prints\n * `--help`, runs `handle-local-options`, registers the application, and either activates it or\n * forwards the command line to the process that already owns the application ID. The runtime is\n * held alive while the application is active and released on shutdown.\n *\n * `g_application_run()` is not what starts the application, because it would drive its own main loop\n * and freeze Node; only the local command line handling it delegates to runs here. {@link\n * quitApplication} calls it once no window holds the application open, to reach the teardown only it\n * performs.\n *\n * GLib parses a given application's command line at most once, so starting an application that has\n * already run registers and activates it instead of reading `argv` again.\n *\n * When another process already owns the application ID, this one registers as a remote instance: no\n * user interface may be built here, because a remote application has no `GtkApplicationImpl` and\n * attaching a window to it crashes.\n *\n * The application also claims the process-wide default `Gio.Application.getDefault()` returns, before\n * its command line is parsed, so an `activate` handler and anything the host reads afterwards see the\n * application being started rather than an earlier one. That holds whether the start ends registered,\n * remote or unregistered: a refused command line still has to be reportable through the default, which\n * is how `gtkx dev` learns which application its entry mounted. {@link quitApplication} gives the\n * default back up, since GLib drops it only at finalize.\n *\n * @param application The application to start.\n * @param argv The command line, whose first entry names the program as `--help` should print it.\n * @returns Whether this process may build a user interface, and the status to exit with.\n */\nconst runApplication = (application: ApplicationLike, argv: string[]): RunApplicationResult => {\n if (!isDerivedApplication(application)) {\n throw new Error(\n \"runApplication: this application was not built by GTKX, so its command line cannot be \" +\n \"parsed and it cannot be shut down safely; render <GtkApplication> or <AdwApplication>, \" +\n \"or construct it with createApplication from @gtkx/runtime\",\n );\n }\n\n claimDefaultApplication(application);\n\n const exitStatus = startedApplications.has(application)\n ? restartApplication(application)\n : startApplication(application, argv);\n\n const instance = getApplicationInstance(application);\n\n if (instance !== \"unregistered\") {\n registeredApplications.add(application);\n }\n\n const isPrimary = instance === \"primary\";\n\n if (isPrimary) {\n keepAlive(true);\n }\n\n return { isPrimary, exitStatus };\n};\n\nconst tearDownApplication = (application: ApplicationLike): void => {\n if (!application.getIsRegistered() || shutDownApplications.has(application)) {\n return;\n }\n\n const windows = application.getWindows?.() ?? [];\n\n for (const window of windows) {\n application.removeWindow?.(window);\n }\n\n shutDownThroughRun(application);\n\n if (application.getIsRegistered()) {\n shutDownApplications.add(application);\n application.emit(\"shutdown\");\n }\n};\n\n/**\n * Detaches every window from the application and runs GLib's own shutdown, which emits `shutdown`,\n * destroys the application implementation and releases the D-Bus registration. Does nothing for an\n * application that is not registered, so a repeated call is a no-op.\n *\n * GLib's own shutdown is reachable once per application: reaching it marks the application as\n * quitting, which GLib never undoes. An application that has already quit falls back to emitting\n * `shutdown`, which releases the runtime and leaves the registration for GLib to drop at finalize.\n *\n * The process-wide default {@link runApplication} claimed is given up whichever of those paths the\n * application took, including the ones that have no teardown left to do, so\n * `Gio.Application.getDefault()` never hands back an application that has been torn down or that\n * never registered in the first place. GLib clears that default only at finalize, which a\n * garbage-collected wrapper reaches arbitrarily late or never.\n *\n * @param application The application to shut down.\n */\nconst quitApplication = (application: ApplicationLike): void => {\n tearDownApplication(application);\n releaseDefaultApplication(application);\n};\n\nexport {\n getApplicationInstance,\n onExit,\n quit,\n runApplication,\n quitApplication,\n type ApplicationInstance,\n type RunApplicationResult,\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"listeners.d.ts","sourceRoot":"","sources":["../src/listeners.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAE3E;;;GAGG;AACH,KAAK,iBAAiB,GAAG;IACrB,iEAAiE;IACjE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC3E,uEAAuE;IACvE,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CACvC,CAAC;AA4CF;;;;;;;;GAQG;AACH,iBAAS,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAG9G;AAED;;;;;;;;GAQG;AACH,iBAAS,UAAU,CAAC,QAAQ,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAahH;AAED;;;;;;;GAOG;AACH,iBAAS,SAAS,CAAC,QAAQ,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI,CAc5F;AAED,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"listeners.d.ts","sourceRoot":"","sources":["../src/listeners.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,aAAa,EAAqB,MAAM,aAAa,CAAC;AAE9F;;;GAGG;AACH,KAAK,iBAAiB,GAAG;IACrB,iEAAiE;IACjE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC3E,uEAAuE;IACvE,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CACvC,CAAC;AA6DF;;;;;;;;GAQG;AACH,iBAAS,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAG9G;AAED;;;;;;;;GAQG;AACH,iBAAS,UAAU,CAAC,QAAQ,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAchH;AAED;;;;;;;GAOG;AACH,iBAAS,SAAS,CAAC,QAAQ,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI,CAe5F;AAED,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC"}
package/dist/listeners.js CHANGED
@@ -1,6 +1,6 @@
1
- import { isSignalHandlerConnected } from "./signal.js";
1
+ import { isSignalHandlerConnected, untrackConnection } from "./signal.js";
2
2
  const listenerTable = new WeakMap();
3
- const findListenerHandlerId = (instance, signal, handler) => listenerTable.get(instance)?.get(signal)?.get(handler);
3
+ const findListenerHandlerId = (instance, signal, handler) => listenerTable.get(instance)?.get(signal)?.get(handler)?.at(-1);
4
4
  const trackListener = (instance, signal, handler, handlerId) => {
5
5
  let bySignal = listenerTable.get(instance);
6
6
  if (!bySignal) {
@@ -12,7 +12,19 @@ const trackListener = (instance, signal, handler, handlerId) => {
12
12
  byHandler = new Map();
13
13
  bySignal.set(signal, byHandler);
14
14
  }
15
- byHandler.set(handler, handlerId);
15
+ let handlerIds = byHandler.get(handler);
16
+ if (!handlerIds) {
17
+ handlerIds = [];
18
+ byHandler.set(handler, handlerIds);
19
+ }
20
+ handlerIds.push(handlerId);
21
+ };
22
+ const removeTrackedHandlerId = (handlerIds, handlerId) => {
23
+ const index = handlerIds.lastIndexOf(handlerId);
24
+ if (index !== -1) {
25
+ handlerIds.splice(index, 1);
26
+ }
27
+ return handlerIds.length;
16
28
  };
17
29
  const untrackHandlerId = (instance, signal, handlerId) => {
18
30
  const bySignal = listenerTable.get(instance);
@@ -20,8 +32,8 @@ const untrackHandlerId = (instance, signal, handlerId) => {
20
32
  if (byHandler === undefined) {
21
33
  return;
22
34
  }
23
- for (const [handler, id] of byHandler) {
24
- if (id === handlerId) {
35
+ for (const [handler, handlerIds] of byHandler) {
36
+ if (removeTrackedHandlerId(handlerIds, handlerId) === 0) {
25
37
  byHandler.delete(handler);
26
38
  }
27
39
  }
@@ -55,6 +67,7 @@ function onceSignal(instance, signal, handler, isAfter) {
55
67
  let handlerId = 0;
56
68
  const wrapped = (...args) => {
57
69
  untrackHandlerId(instance, signal, handlerId);
70
+ untrackConnection(instance, handlerId);
58
71
  instance.disconnect(handlerId);
59
72
  return handler(...args);
60
73
  };
@@ -76,6 +89,7 @@ function offSignal(instance, signal, handler) {
76
89
  return;
77
90
  }
78
91
  untrackHandlerId(instance, signal, handlerId);
92
+ untrackConnection(instance, handlerId);
79
93
  if (!isSignalHandlerConnected(instance, handlerId)) {
80
94
  return;
81
95
  }
@@ -1 +1 @@
1
- {"version":3,"file":"listeners.js","sourceRoot":"","sources":["../src/listeners.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAsB,MAAM,aAAa,CAAC;AAa3E,MAAM,aAAa,GAA6D,IAAI,OAAO,EAAE,CAAC;AAE9F,MAAM,qBAAqB,GAAG,CAAC,QAAgB,EAAE,MAAc,EAAE,OAAsB,EAAsB,EAAE,CAC3G,aAAa,CAAC,GAAG,CAA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CAAC,wBAAwB,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,CAAC;QACjD,OAAO;IACX,CAAC;IAED,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import { isSignalHandlerConnected, type SignalHandler } from \"./signal.js\";\n\n/**\n * The connect and disconnect surface {@link onSignal}, {@link onceSignal} and {@link offSignal}\n * drive on an emitter.\n */\ntype SignalConnectable = {\n /** Connects a handler to a signal and returns its handler id. */\n connect(signal: string, handler: SignalHandler, isAfter?: boolean): number;\n /** Disconnects the handler previously connected under the given id. */\n disconnect(handlerId: number): void;\n};\n\nconst listenerTable: WeakMap<object, Map<string, Map<SignalHandler, number>>> = new WeakMap();\n\nconst findListenerHandlerId = (instance: object, signal: string, handler: SignalHandler): number | undefined =>\n listenerTable.get(instance)?.get(signal)?.get(handler);\n\nconst trackListener = (instance: object, signal: string, handler: SignalHandler, handlerId: number): void => {\n let bySignal = listenerTable.get(instance);\n\n if (!bySignal) {\n bySignal = new Map();\n listenerTable.set(instance, bySignal);\n }\n\n let byHandler = bySignal.get(signal);\n\n if (!byHandler) {\n byHandler = new Map();\n bySignal.set(signal, byHandler);\n }\n\n byHandler.set(handler, handlerId);\n};\n\nconst untrackHandlerId = (instance: object, signal: string, handlerId: number): void => {\n const bySignal = listenerTable.get(instance);\n const byHandler = bySignal?.get(signal);\n\n if (byHandler === undefined) {\n return;\n }\n\n for (const [handler, id] of byHandler) {\n if (id === handlerId) {\n byHandler.delete(handler);\n }\n }\n\n if (byHandler.size === 0) {\n bySignal?.delete(signal);\n }\n};\n\n/**\n * Connects a handler to a signal and tracks it so it can later be removed with\n * {@link offSignal}.\n *\n * @param instance The object emitting the signal.\n * @param signal The signal name to connect to.\n * @param handler The callback invoked on each emission.\n * @param isAfter When true, run the handler after the default handler.\n */\nfunction onSignal(instance: SignalConnectable, signal: string, handler: SignalHandler, isAfter?: boolean): void {\n const handlerId = instance.connect(signal, handler, isAfter);\n trackListener(instance, signal, handler, handlerId);\n}\n\n/**\n * Connects a handler that runs at most once, disconnecting itself after the first\n * emission.\n *\n * @param instance The object emitting the signal.\n * @param signal The signal name to connect to.\n * @param handler The callback invoked on the first emission.\n * @param isAfter When true, run the handler after the default handler.\n */\nfunction onceSignal(instance: SignalConnectable, signal: string, handler: SignalHandler, isAfter?: boolean): void {\n let handlerId = 0;\n\n const wrapped: SignalHandler = (...args) => {\n untrackHandlerId(instance, signal, handlerId);\n instance.disconnect(handlerId);\n\n return handler(...args);\n };\n\n handlerId = instance.connect(signal, wrapped, isAfter);\n trackListener(instance, signal, wrapped, handlerId);\n trackListener(instance, signal, handler, handlerId);\n}\n\n/**\n * Disconnects a handler previously connected with {@link onSignal} or\n * {@link onceSignal}. Does nothing if the handler is not currently connected.\n *\n * @param instance The object the handler was connected to.\n * @param signal The signal name the handler was connected to.\n * @param handler The handler to disconnect.\n */\nfunction offSignal(instance: SignalConnectable, signal: string, handler: SignalHandler): void {\n const handlerId = findListenerHandlerId(instance, signal, handler);\n\n if (handlerId === undefined) {\n return;\n }\n\n untrackHandlerId(instance, signal, handlerId);\n\n if (!isSignalHandlerConnected(instance, handlerId)) {\n return;\n }\n\n instance.disconnect(handlerId);\n}\n\nexport { onSignal, onceSignal, offSignal };\n"]}
1
+ {"version":3,"file":"listeners.js","sourceRoot":"","sources":["../src/listeners.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAsB,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAa9F,MAAM,aAAa,GAA+D,IAAI,OAAO,EAAE,CAAC;AAEhG,MAAM,qBAAqB,GAAG,CAAC,QAAgB,EAAE,MAAc,EAAE,OAAsB,EAAsB,EAAE,CAC3G,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,CA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AAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACvD,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IACpD,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AACxD,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,SAAS,CAAC,QAA2B,EAAE,MAAc,EAAE,OAAsB;IAClF,MAAM,SAAS,GAAG,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnE,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO;IACX,CAAC;IAED,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAC9C,iBAAiB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAEvC,IAAI,CAAC,wBAAwB,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,CAAC;QACjD,OAAO;IACX,CAAC;IAED,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC;AAED,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import { isSignalHandlerConnected, type SignalHandler, untrackConnection } from \"./signal.js\";\n\n/**\n * The connect and disconnect surface {@link onSignal}, {@link onceSignal} and {@link offSignal}\n * drive on an emitter.\n */\ntype SignalConnectable = {\n /** Connects a handler to a signal and returns its handler id. */\n connect(signal: string, handler: SignalHandler, isAfter?: boolean): number;\n /** Disconnects the handler previously connected under the given id. */\n disconnect(handlerId: number): void;\n};\n\nconst listenerTable: WeakMap<object, Map<string, Map<SignalHandler, number[]>>> = new WeakMap();\n\nconst findListenerHandlerId = (instance: object, signal: string, handler: SignalHandler): number | undefined =>\n listenerTable.get(instance)?.get(signal)?.get(handler)?.at(-1);\n\nconst trackListener = (instance: object, signal: string, handler: SignalHandler, handlerId: number): void => {\n let bySignal = listenerTable.get(instance);\n\n if (!bySignal) {\n bySignal = new Map();\n listenerTable.set(instance, bySignal);\n }\n\n let byHandler = bySignal.get(signal);\n\n if (!byHandler) {\n byHandler = new Map();\n bySignal.set(signal, byHandler);\n }\n\n let handlerIds = byHandler.get(handler);\n\n if (!handlerIds) {\n handlerIds = [];\n byHandler.set(handler, handlerIds);\n }\n\n handlerIds.push(handlerId);\n};\n\nconst removeTrackedHandlerId = (handlerIds: number[], handlerId: number): number => {\n const index = handlerIds.lastIndexOf(handlerId);\n\n if (index !== -1) {\n handlerIds.splice(index, 1);\n }\n\n return handlerIds.length;\n};\n\nconst untrackHandlerId = (instance: object, signal: string, handlerId: number): void => {\n const bySignal = listenerTable.get(instance);\n const byHandler = bySignal?.get(signal);\n\n if (byHandler === undefined) {\n return;\n }\n\n for (const [handler, handlerIds] of byHandler) {\n if (removeTrackedHandlerId(handlerIds, handlerId) === 0) {\n byHandler.delete(handler);\n }\n }\n\n if (byHandler.size === 0) {\n bySignal?.delete(signal);\n }\n};\n\n/**\n * Connects a handler to a signal and tracks it so it can later be removed with\n * {@link offSignal}.\n *\n * @param instance The object emitting the signal.\n * @param signal The signal name to connect to.\n * @param handler The callback invoked on each emission.\n * @param isAfter When true, run the handler after the default handler.\n */\nfunction onSignal(instance: SignalConnectable, signal: string, handler: SignalHandler, isAfter?: boolean): void {\n const handlerId = instance.connect(signal, handler, isAfter);\n trackListener(instance, signal, handler, handlerId);\n}\n\n/**\n * Connects a handler that runs at most once, disconnecting itself after the first\n * emission.\n *\n * @param instance The object emitting the signal.\n * @param signal The signal name to connect to.\n * @param handler The callback invoked on the first emission.\n * @param isAfter When true, run the handler after the default handler.\n */\nfunction onceSignal(instance: SignalConnectable, signal: string, handler: SignalHandler, isAfter?: boolean): void {\n let handlerId = 0;\n\n const wrapped: SignalHandler = (...args) => {\n untrackHandlerId(instance, signal, handlerId);\n untrackConnection(instance, handlerId);\n instance.disconnect(handlerId);\n\n return handler(...args);\n };\n\n handlerId = instance.connect(signal, wrapped, isAfter);\n trackListener(instance, signal, wrapped, handlerId);\n trackListener(instance, signal, handler, handlerId);\n}\n\n/**\n * Disconnects a handler previously connected with {@link onSignal} or\n * {@link onceSignal}. Does nothing if the handler is not currently connected.\n *\n * @param instance The object the handler was connected to.\n * @param signal The signal name the handler was connected to.\n * @param handler The handler to disconnect.\n */\nfunction offSignal(instance: SignalConnectable, signal: string, handler: SignalHandler): void {\n const handlerId = findListenerHandlerId(instance, signal, handler);\n\n if (handlerId === undefined) {\n return;\n }\n\n untrackHandlerId(instance, signal, handlerId);\n untrackConnection(instance, handlerId);\n\n if (!isSignalHandlerConnected(instance, handlerId)) {\n return;\n }\n\n instance.disconnect(handlerId);\n}\n\nexport { onSignal, onceSignal, offSignal };\n"]}
package/dist/mixin.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyClass } from "@gtkx/utils";
1
+ import { type AnyClass } from "@gtkx/utils";
2
2
  /**
3
3
  * The signal plumbing every base class passed to a {@link Mixin} provides, so mixed-in interface
4
4
  * members can connect and emit without knowing the concrete class.
@@ -22,5 +22,6 @@ type Mixin = (base: AnyClass<MixinReceiver>) => AnyClass;
22
22
  * @param mixins The mixins to apply, in order.
23
23
  */
24
24
  declare function installMixins(target: AnyClass, mixins: Mixin[]): void;
25
- export { installMixins, type MixinReceiver, type Mixin };
25
+ declare function insertMixinLayer(target: AnyClass, mixin: Mixin, inheritedNames: Set<string>): void;
26
+ export { insertMixinLayer, installMixins, type MixinReceiver, type Mixin };
26
27
  //# sourceMappingURL=mixin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mixin.d.ts","sourceRoot":"","sources":["../src/mixin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C;;;GAGG;AACH,KAAK,aAAa,GAAG;IACjB,iEAAiE;IACjE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAA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AAK,EAAE,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAK3F;AAED,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,KAAK,EAAE,CAAC"}
package/dist/mixin.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { getParentClass } from "@gtkx/utils";
1
2
  function isDefinedInClassChain(prototype, key) {
2
3
  let current = prototype;
3
4
  while (current !== null && current !== Object.prototype) {
@@ -45,5 +46,16 @@ function installMixins(target, mixins) {
45
46
  copyLayerMembers(target, mixin(empty).prototype);
46
47
  }
47
48
  }
48
- export { installMixins };
49
+ function dropLayerMembers(layer, names) {
50
+ for (const name of names) {
51
+ Reflect.deleteProperty(layer.prototype, name);
52
+ }
53
+ }
54
+ function insertMixinLayer(target, mixin, inheritedNames) {
55
+ const layer = mixin(getParentClass(target));
56
+ dropLayerMembers(layer, inheritedNames);
57
+ Object.setPrototypeOf(target.prototype, layer.prototype);
58
+ Object.setPrototypeOf(target, layer);
59
+ }
60
+ export { insertMixinLayer, installMixins };
49
61
  //# sourceMappingURL=mixin.js.map
package/dist/mixin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mixin.js","sourceRoot":"","sources":["../src/mixin.ts"],"names":[],"mappings":"AAmBA,SAAS,qBAAqB,CAAC,SAAiB,EAAE,GAAW;IACzD,IAAI,OAAO,GAAkB,SAAS,CAAC;IAEvC,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,MAAM,CAAC,SAAS,EAAE,CAAC;QACtD,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAS,eAAe,CAAC,MAAgB,EAAE,KAAa,EAAE,GAAW;IACjE,IAAI,GAAG,KAAK,aAAa,EAAE,CAAC;QACxB,OAAO;IACX,CAAC;IAED,IAAI,qBAAqB,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE,CAAC;QAC/C,OAAO;IACX,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAE/D,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;IAC7D,CAAC;AACL,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAgB,EAAE,KAAa;IACrD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC;QAClD,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;IACxC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,SAAS,aAAa,CAAC,MAAgB,EAAE,MAAe;IACpD,MAAM,KAAK,GAA4B;QACnC,OAAO;YACH,OAAO,CAAC,CAAC;QACb,CAAC;QAED,IAAI;YACA,OAAO,SAAS,CAAC;QACrB,CAAC;KACJ,CAAC;IAEF,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACzB,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;AACL,CAAC;AAED,OAAO,EAAE,aAAa,EAAkC,CAAC","sourcesContent":["import type { AnyClass } from \"@gtkx/utils\";\n\n/**\n * The signal plumbing every base class passed to a {@link Mixin} provides, so mixed-in interface\n * members can connect and emit without knowing the concrete class.\n */\ntype MixinReceiver = {\n /** Connects a handler to a signal and returns its handler id. */\n connect(signal: string, handler: (...args: unknown[]) => unknown, isAfter?: boolean): number;\n /** Emits a signal with the given arguments and returns whatever the emission produced. */\n emit(signal: string, ...args: unknown[]): unknown;\n};\n\n/**\n * A factory that, given a base class, returns a subclass adding extra members to\n * be merged onto a target prototype.\n */\ntype Mixin = (base: AnyClass<MixinReceiver>) => AnyClass;\n\nfunction isDefinedInClassChain(prototype: object, key: string): boolean {\n let current: object | null = prototype;\n\n while (current !== null && current !== Object.prototype) {\n if (Object.hasOwn(current, key)) {\n return true;\n }\n\n current = Reflect.getPrototypeOf(current);\n }\n\n return false;\n}\n\nfunction copyLayerMember(target: AnyClass, layer: object, key: string): void {\n if (key === \"constructor\") {\n return;\n }\n\n if (isDefinedInClassChain(target.prototype, key)) {\n return;\n }\n\n const descriptor = Object.getOwnPropertyDescriptor(layer, key);\n\n if (descriptor !== undefined) {\n Object.defineProperty(target.prototype, key, descriptor);\n }\n}\n\nfunction copyLayerMembers(target: AnyClass, layer: object): void {\n for (const key of Object.getOwnPropertyNames(layer)) {\n copyLayerMember(target, layer, key);\n }\n}\n\n/**\n * Copies each mixin's prototype members onto the target class prototype, skipping\n * any member already defined anywhere in the target's class chain.\n *\n * @param target The class whose prototype receives the mixin members.\n * @param mixins The mixins to apply, in order.\n */\nfunction installMixins(target: AnyClass, mixins: Mixin[]): void {\n const empty: AnyClass<MixinReceiver> = class {\n connect(): number {\n return 0;\n }\n\n emit(): unknown {\n return undefined;\n }\n };\n\n for (const mixin of mixins) {\n copyLayerMembers(target, mixin(empty).prototype);\n }\n}\n\nexport { installMixins, type MixinReceiver, type Mixin };\n"]}
1
+ {"version":3,"file":"mixin.js","sourceRoot":"","sources":["../src/mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,cAAc,EAAE,MAAM,aAAa,CAAC;AAmB5D,SAAS,qBAAqB,CAAC,SAAiB,EAAE,GAAW;IACzD,IAAI,OAAO,GAAkB,SAAS,CAAC;IAEvC,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,MAAM,CAAC,SAAS,EAAE,CAAC;QACtD,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,GAA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AI,KAAK,EAAE,CAAC;QACvB,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;AACL,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAgB,EAAE,KAAY,EAAE,cAA2B;IACjF,MAAM,KAAK,GAAG,KAAK,CAAC,cAAc,CAAC,MAAM,CAA4B,CAAC,CAAC;IACvE,gBAAgB,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IACxC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IACzD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACzC,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAkC,CAAC","sourcesContent":["import { type AnyClass, getParentClass } from \"@gtkx/utils\";\n\n/**\n * The signal plumbing every base class passed to a {@link Mixin} provides, so mixed-in interface\n * members can connect and emit without knowing the concrete class.\n */\ntype MixinReceiver = {\n /** Connects a handler to a signal and returns its handler id. */\n connect(signal: string, handler: (...args: unknown[]) => unknown, isAfter?: boolean): number;\n /** Emits a signal with the given arguments and returns whatever the emission produced. */\n emit(signal: string, ...args: unknown[]): unknown;\n};\n\n/**\n * A factory that, given a base class, returns a subclass adding extra members to\n * be merged onto a target prototype.\n */\ntype Mixin = (base: AnyClass<MixinReceiver>) => AnyClass;\n\nfunction isDefinedInClassChain(prototype: object, key: string): boolean {\n let current: object | null = prototype;\n\n while (current !== null && current !== Object.prototype) {\n if (Object.hasOwn(current, key)) {\n return true;\n }\n\n current = Reflect.getPrototypeOf(current);\n }\n\n return false;\n}\n\nfunction copyLayerMember(target: AnyClass, layer: object, key: string): void {\n if (key === \"constructor\") {\n return;\n }\n\n if (isDefinedInClassChain(target.prototype, key)) {\n return;\n }\n\n const descriptor = Object.getOwnPropertyDescriptor(layer, key);\n\n if (descriptor !== undefined) {\n Object.defineProperty(target.prototype, key, descriptor);\n }\n}\n\nfunction copyLayerMembers(target: AnyClass, layer: object): void {\n for (const key of Object.getOwnPropertyNames(layer)) {\n copyLayerMember(target, layer, key);\n }\n}\n\n/**\n * Copies each mixin's prototype members onto the target class prototype, skipping\n * any member already defined anywhere in the target's class chain.\n *\n * @param target The class whose prototype receives the mixin members.\n * @param mixins The mixins to apply, in order.\n */\nfunction installMixins(target: AnyClass, mixins: Mixin[]): void {\n const empty: AnyClass<MixinReceiver> = class {\n connect(): number {\n return 0;\n }\n\n emit(): unknown {\n return undefined;\n }\n };\n\n for (const mixin of mixins) {\n copyLayerMembers(target, mixin(empty).prototype);\n }\n}\n\nfunction dropLayerMembers(layer: AnyClass, names: Set<string>): void {\n for (const name of names) {\n Reflect.deleteProperty(layer.prototype, name);\n }\n}\n\nfunction insertMixinLayer(target: AnyClass, mixin: Mixin, inheritedNames: Set<string>): void {\n const layer = mixin(getParentClass(target) as AnyClass<MixinReceiver>);\n dropLayerMembers(layer, inheritedNames);\n Object.setPrototypeOf(target.prototype, layer.prototype);\n Object.setPrototypeOf(target, layer);\n}\n\nexport { insertMixinLayer, installMixins, type MixinReceiver, type Mixin };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"native-value.d.ts","sourceRoot":"","sources":["../src/native-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA0B,MAAM,cAAc,CAAC;AA+DvE;;;;;;;GAOG;AACH,iBAAS,UAAU,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAyBnE;AAiBD;;;;;;;GAOG;AACH,iBAAS,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAmBjE;AAED,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC"}
1
+ {"version":3,"file":"native-value.d.ts","sourceRoot":"","sources":["../src/native-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA0B,MAAM,cAAc,CAAC;AA+DvE;;;;;;;GAOG;AACH,iBAAS,UAAU,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAyBnE;AAiBD;;;;;;;GAOG;AACH,iBAAS,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAqBjE;AAED,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC"}
@@ -1,4 +1,4 @@
1
- import { getWrapperClass, tryGetHandle, wrapHandle } from "./registry.js";
1
+ import { getHandle, getWrapperClass, wrapCallScopedObject, wrapHandle, wrapObject } from "./registry.js";
2
2
  import { resolveDescriptorType } from "./type.js";
3
3
  const MARSHALLED_KINDS = new Set([
4
4
  "object",
@@ -51,7 +51,7 @@ function fromNative(descriptor, value) {
51
51
  }
52
52
  switch (descriptor.kind) {
53
53
  case "object": {
54
- return wrapHandle(value);
54
+ return descriptor.isCallScoped === true ? wrapCallScopedObject(value) : wrapObject(value);
55
55
  }
56
56
  case "struct": {
57
57
  return wrapHandle(value, descriptor.wrapperClass);
@@ -99,7 +99,8 @@ function toNative(descriptor, value) {
99
99
  case "struct":
100
100
  case "boxed":
101
101
  case "fundamental": {
102
- return tryGetHandle(value) ?? null;
102
+ const instance = value;
103
+ return instance == null ? null : getHandle(instance);
103
104
  }
104
105
  case "array": {
105
106
  return collectionToNative(descriptor, value);