@kmamal/sdl 0.10.4 → 0.10.7

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.
package/README.md CHANGED
@@ -515,7 +515,7 @@ Check [`sdl.video.displays`](#sdlvideodisplays) to get the new list of displays.
515
515
  * `x, y, width, height: <Rect>` The position and size of the display's geometry.
516
516
  * `usable: <object>` Similar to `geometry`, but excludes areas taken up by the OS or window manager such as menus, docks, e.t.c.
517
517
  * `x, y, width, height: <Rect>` The position and size of the display's usable region.
518
- * `dpi: <object>` Return pixel density for the display in dots/pixels-per-inch units.
518
+ * `dpi: <object>|<null>` Return pixel density for the display in dots/pixels-per-inch units. Might be `null` on some devices if DPI info can't be retrieved.
519
519
  * `horizontal: <number>` The horizontal density.
520
520
  * `vertical: <number>` The vertical density.
521
521
  * `diagonal: <number>` The diagonal density.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.10.4",
2
+ "version": "0.10.7",
3
3
  "name": "@kmamal/sdl",
4
4
  "description": "SDL bindings for Node.js",
5
5
  "keywords": [
@@ -60,7 +60,7 @@
60
60
  "clean": "cd scripts && node clean.mjs"
61
61
  },
62
62
  "dependencies": {
63
- "tar": "^6.2.1"
63
+ "tar": "^7.1.0"
64
64
  },
65
65
  "sdl": {
66
66
  "owner": "kmamal",
@@ -70,7 +70,7 @@
70
70
  "devDependencies": {
71
71
  "@kmamal/evdev": "^0.0.1",
72
72
  "@kmamal/testing": "^0.0.30",
73
- "@types/node": "^20.11.30",
73
+ "@types/node": "^20.12.8",
74
74
  "node-addon-api": "^8.0.0",
75
75
  "node-gyp": "^10.1.0"
76
76
  }
@@ -3,7 +3,7 @@ import Path from 'node:path'
3
3
  import { once } from 'node:events'
4
4
  import C from './util/common.js'
5
5
  import { fetch } from './util/fetch.js'
6
- import Tar from 'tar'
6
+ import * as Tar from 'tar'
7
7
 
8
8
  const url = `https://github.com/${C.sdl.owner}/${C.sdl.repo}/archive/refs/tags/v${C.sdl.version}.tar.gz`
9
9
 
@@ -2,7 +2,7 @@ import Fs from 'node:fs'
2
2
  import { once } from 'node:events'
3
3
  import C from './util/common.js'
4
4
  import { fetch } from './util/fetch.js'
5
- import Tar from 'tar'
5
+ import * as Tar from 'tar'
6
6
 
7
7
  const url = `https://github.com/${C.owner}/${C.repo}/releases/download/v${C.version}/${C.assetName}`
8
8
 
@@ -2,16 +2,22 @@ import Fs from 'node:fs'
2
2
  import { once } from 'node:events'
3
3
  import C from './util/common.js'
4
4
  import { fetch } from './util/fetch.js'
5
- import Tar from 'tar'
5
+ import * as Tar from 'tar'
6
6
 
7
7
  const url = `https://github.com/${C.sdl.owner}/${C.sdl.repo}/releases/download/v${C.sdl.version}/${C.sdl.assetName}`
8
8
 
9
9
  console.log("fetch", url)
10
- const response = await fetch(url)
10
+ try {
11
+ const response = await fetch(url)
11
12
 
12
- console.log("unpack to", C.dir.sdl)
13
- await Fs.promises.rm(C.dir.sdl, { recursive: true }).catch(() => {})
14
- await Fs.promises.mkdir(C.dir.sdl, { recursive: true })
15
- const tar = Tar.extract({ gzip: true, C: C.dir.sdl })
16
- response.stream().pipe(tar)
17
- await once(tar, 'finish')
13
+
14
+ console.log("unpack to", C.dir.sdl)
15
+ await Fs.promises.rm(C.dir.sdl, { recursive: true }).catch(() => {})
16
+ await Fs.promises.mkdir(C.dir.sdl, { recursive: true })
17
+ const tar = Tar.extract({ gzip: true, C: C.dir.sdl })
18
+ response.stream().pipe(tar)
19
+ await once(tar, 'finish')
20
+ } catch (error) {
21
+ console.log(error)
22
+ throw error
23
+ }
@@ -67,19 +67,18 @@ video::getDisplays(const Napi::CallbackInfo &info)
67
67
  usable.Set("width", Napi::Number::New(env, rect.w));
68
68
  usable.Set("height", Napi::Number::New(env, rect.h));
69
69
 
70
+ Napi::Value dpi;
70
71
  float ddpi, hdpi, vdpi;
71
72
  if (SDL_GetDisplayDPI(i, &ddpi, &hdpi, &vdpi) < 0) {
72
- std::ostringstream message;
73
- message << "SDL_GetDisplayDPI(" << i << ") error: " << SDL_GetError();
74
- SDL_ClearError();
75
- throw Napi::Error::New(env, message.str());
73
+ dpi = env.Null();
74
+ } else {
75
+ Napi::Object dpi_obj = Napi::Object::New(env);
76
+ dpi_obj.Set("diagonal", Napi::Number::New(env, ddpi));
77
+ dpi_obj.Set("horizontal", Napi::Number::New(env, hdpi));
78
+ dpi_obj.Set("vertical", Napi::Number::New(env, vdpi));
79
+ dpi = dpi_obj;
76
80
  }
77
81
 
78
- Napi::Object dpi = Napi::Object::New(env);
79
- dpi.Set("diagonal", Napi::Number::New(env, ddpi));
80
- dpi.Set("horizontal", Napi::Number::New(env, hdpi));
81
- dpi.Set("vertical", Napi::Number::New(env, vdpi));
82
-
83
82
  Napi::Object display = Napi::Object::New(env);
84
83
  display.Set("name", Napi::String::New(env, name));
85
84
  display.Set("format", video::formats[(SDL_PixelFormatEnum) mode.format]);
@@ -371,7 +371,7 @@ export namespace Sdl {
371
371
  readonly horizontal: number
372
372
  readonly vertical: number
373
373
  readonly diagonal: number
374
- }
374
+ } | null
375
375
  }
376
376
 
377
377
  export class Window {
@@ -400,7 +400,7 @@ export namespace Sdl {
400
400
  on (event: 'dropText', listener: (event: Events.Window.DropText) => void): this
401
401
  on (event: 'dropFile', listener: (event: Events.Window.DropFile) => void): this
402
402
  on (event: 'dropComplete', listener: (event: Events.Window.DropComplete) => void): this
403
- on (event: '*', listener: (event: Events.Window.Any) => void): this
403
+ on (event: '*', listener: (type: string, event: Events.Window.Any) => void): this
404
404
 
405
405
  readonly id: number
406
406
 
@@ -476,7 +476,7 @@ export namespace Sdl {
476
476
  on (event: 'displayAdd', listener: (event: Events.Display.Add) => void): this
477
477
  on (event: 'displayRemove', listener: (event: Events.Display.Remove) => void): this
478
478
  on (event: 'displayOrient', listener: (event: Events.Display.Orient) => void): this
479
- on (event: '*', listener: (event: Events.Display.Any) => void): this
479
+ on (event: '*', listener: (type: string, event: Events.Display.Any) => void): this
480
480
 
481
481
  readonly displays: Display[]
482
482
 
@@ -873,7 +873,7 @@ export namespace Sdl {
873
873
  on (event: 'buttonUp', listener: (event: Events.Joystick.ButtonUp) => void): this
874
874
  on (event: 'hatMotion', listener: (event: Events.Joystick.HatMotion) => void): this
875
875
  on (event: 'close', listener: (event: Events.Joystick.Close) => void): this
876
- on (event: '*', listener: (event: Events.Joystick.Any) => void): this
876
+ on (event: '*', listener: (type: string, event: Events.Joystick.Any) => void): this
877
877
 
878
878
  readonly device: Device
879
879
  readonly firmwareVersion: number
@@ -907,7 +907,7 @@ export namespace Sdl {
907
907
  interface Module {
908
908
  on (event: 'deviceAdd', listener: (event: Events.JoystickDevice.Add) => void): this
909
909
  on (event: 'deviceRemove', listener: (event: Events.JoystickDevice.Remove) => void): this
910
- on (event: '*', listener: (event: Events.JoystickDevice.Any) => void): this
910
+ on (event: '*', listener: (type: string, event: Events.JoystickDevice.Any) => void): this
911
911
 
912
912
  readonly devices: Device[]
913
913
 
@@ -965,7 +965,7 @@ export namespace Sdl {
965
965
  on (event: 'buttonUp', listener: (event: Events.Controller.ButtonUp) => void): this
966
966
  on (event: 'remap', listener: (event: Events.Controller.Remap) => void): this
967
967
  on (event: 'close', listener: (event: Events.Controller.Close) => void): this
968
- on (event: '*', listener: (event: Events.Controller.Any) => void): this
968
+ on (event: '*', listener: (type: string, event: Events.Controller.Any) => void): this
969
969
 
970
970
  readonly device: Device
971
971
  readonly firmwareVersion: number
@@ -1025,7 +1025,7 @@ export namespace Sdl {
1025
1025
  interface Module {
1026
1026
  on (event: 'deviceAdd', listener: (event: Events.ControllerDevice.Add) => void): this
1027
1027
  on (event: 'deviceRemove', listener: (event: Events.ControllerDevice.Remove) => void): this
1028
- on (event: '*', listener: (event: Events.ControllerDevice.Any) => void): this
1028
+ on (event: '*', listener: (type: string, event: Events.ControllerDevice.Any) => void): this
1029
1029
 
1030
1030
  addMappings (mappings: string[]): void
1031
1031
 
@@ -1064,7 +1064,7 @@ export namespace Sdl {
1064
1064
  export class SensorInstance {
1065
1065
  on (event: 'update', listener: (event: Events.Sensor.Update) => void): this
1066
1066
  on (event: 'close', listener: (event: Events.Sensor.Close) => void): this
1067
- on (event: '*', listener: (event: Events.Sensor.Any) => void): this
1067
+ on (event: '*', listener: (type: string, event: Events.Sensor.Any) => void): this
1068
1068
 
1069
1069
  readonly device: Device
1070
1070
 
@@ -1121,7 +1121,7 @@ export namespace Sdl {
1121
1121
 
1122
1122
  export class AudioInstance {
1123
1123
  on (event: 'close', listener: (event: Events.Audio.Close) => void): this
1124
- on (event: '*', listener: (event: Events.Audio.Any) => void): this
1124
+ on (event: '*', listener: (type: string, event: Events.Audio.Any) => void): this
1125
1125
 
1126
1126
  readonly id: number
1127
1127
  readonly device: Device
@@ -1167,7 +1167,7 @@ export namespace Sdl {
1167
1167
  interface Module {
1168
1168
  on (event: 'deviceAdd', listener: (event: Events.AudioDevice.Add) => void): this
1169
1169
  on (event: 'deviceRemove', listener: (event: Events.AudioDevice.Remove) => void): this
1170
- on (event: '*', listener: (event: Events.AudioDevice.Any) => void): this
1170
+ on (event: '*', listener: (type: string, event: Events.AudioDevice.Any) => void): this
1171
1171
 
1172
1172
  readonly devices: Device[]
1173
1173
 
@@ -1187,7 +1187,7 @@ export namespace Sdl {
1187
1187
 
1188
1188
  interface Module {
1189
1189
  on (event: 'update', listener: (event: Events.Clipboard.Update) => void): this
1190
- on (event: '*', listener: (event: Events.Clipboard.Any) => void): this
1190
+ on (event: '*', listener: (type: string, event: Events.Clipboard.Any) => void): this
1191
1191
 
1192
1192
  readonly text: string
1193
1193
  setText (text: string): void