@hagicode/steamworks.js 0.0.0-stage → 0.1.6-dev.17

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.
Binary file
Binary file
Binary file
Binary file
package/index.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ // Re-export all types from client.d.ts
2
+ export type * from './client.d';
3
+ export function init(appId?: number): Omit<Client, "init" | "runCallbacks" | "shutdown">;
4
+ export function shutdown(): void;
5
+ export function isConnected(): boolean;
6
+ export function restartAppIfNecessary(appId: number): boolean;
7
+ export function electronEnableSteamOverlay(disableEachFrameInvalidation?: boolean): void;
8
+ export type Client = typeof import("./client.d");
9
+ export const SteamCallback: typeof import("./client.d").callback.SteamCallback;
package/index.js ADDED
@@ -0,0 +1,94 @@
1
+ const { platform, arch } = process
2
+
3
+ /** @typedef {typeof import('./client.d')} Client */
4
+ /** @type {Client} */
5
+ let nativeBinding = undefined
6
+
7
+ if (platform === 'win32' && arch === 'x64') {
8
+ nativeBinding = require('./dist/win64/steamworksjs.win32-x64-msvc.node')
9
+ } else if (platform === 'linux' && arch === 'x64') {
10
+ nativeBinding = require('./dist/linux64/steamworksjs.linux-x64-gnu.node')
11
+ } else if (platform === 'darwin') {
12
+ if (arch === 'x64') {
13
+ nativeBinding = require('./dist/osx/steamworksjs.darwin-x64.node')
14
+ } else if (arch === 'arm64') {
15
+ nativeBinding = require('./dist/osx/steamworksjs.darwin-arm64.node')
16
+ }
17
+ } else {
18
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
19
+ }
20
+
21
+ let runCallbacksInterval = undefined
22
+
23
+ /**
24
+ * Initialize the steam client or throw an error if it fails
25
+ * @param {number} [appId] - App ID of the game to load, if undefined, will search for a steam_appid.txt file
26
+ * @returns {Omit<Client, 'init' | 'runCallbacks' | 'shutdown'>}
27
+ */
28
+ module.exports.init = (appId) => {
29
+ const { init: internalInit, runCallbacks, restartAppIfNecessary, shutdown, ...api } = nativeBinding
30
+
31
+ internalInit(appId)
32
+
33
+ clearInterval(runCallbacksInterval)
34
+ runCallbacksInterval = setInterval(runCallbacks, 1000 / 30)
35
+
36
+ return api
37
+ }
38
+
39
+ /**
40
+ * Shuts down the Steam client connection and releases resources.
41
+ * This should be called when you want to disconnect from Steam.
42
+ * After calling shutdown(), you can call init() again to re-establish the connection.
43
+ */
44
+ module.exports.shutdown = () => {
45
+ clearInterval(runCallbacksInterval)
46
+ runCallbacksInterval = undefined
47
+ nativeBinding.shutdown()
48
+ }
49
+
50
+ /**
51
+ * @param {number} appId - App ID of the game to load
52
+ * {@link https://partner.steamgames.com/doc/api/steam_api#SteamAPI_RestartAppIfNecessary}
53
+ * @returns {boolean}
54
+ */
55
+ module.exports.restartAppIfNecessary = (appId) => nativeBinding.restartAppIfNecessary(appId);
56
+
57
+ /**
58
+ * Check if the Steam client is currently connected and initialized.
59
+ * @returns {boolean} true if Steam client is connected, false otherwise
60
+ */
61
+ module.exports.isConnected = () => nativeBinding.isConnected();
62
+
63
+ /**
64
+ * Enable the steam overlay on electron
65
+ * @param {boolean} [disableEachFrameInvalidation] - Should attach a single pixel to be rendered each frame
66
+ */
67
+ module.exports.electronEnableSteamOverlay = (disableEachFrameInvalidation) => {
68
+ const electron = require('electron')
69
+ if (!electron) {
70
+ throw new Error('Electron module not found')
71
+ }
72
+
73
+ electron.app.commandLine.appendSwitch('in-process-gpu')
74
+ electron.app.commandLine.appendSwitch('disable-direct-composition')
75
+
76
+ if (!disableEachFrameInvalidation) {
77
+ /** @param {electron.BrowserWindow} browserWindow */
78
+ const attachFrameInvalidator = (browserWindow) => {
79
+ browserWindow.steamworksRepaintInterval = setInterval(() => {
80
+ if (browserWindow.isDestroyed()) {
81
+ clearInterval(browserWindow.steamworksRepaintInterval)
82
+ } else if (!browserWindow.webContents.isPainting()) {
83
+ browserWindow.webContents.invalidate()
84
+ }
85
+ }, 1000 / 60)
86
+ }
87
+
88
+ electron.BrowserWindow.getAllWindows().forEach(attachFrameInvalidator)
89
+ electron.app.on('browser-window-created', (_, bw) => attachFrameInvalidator(bw))
90
+ }
91
+ }
92
+
93
+ const SteamCallback = nativeBinding.callback.SteamCallback
94
+ module.exports.SteamCallback = SteamCallback
package/package.json CHANGED
@@ -1,6 +1,67 @@
1
1
  {
2
- "name": "@hagicode/steamworks.js",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@hagicode/steamworks.js",
3
+ "description": "Node.js and Electron bindings for the Steamworks SDK: Steam Workshop, achievements, stats, cloud, overlay, networking.",
4
+ "keywords": [
5
+ "steam",
6
+ "steamworks",
7
+ "steamworks-sdk",
8
+ "workshop",
9
+ "ugc",
10
+ "napi",
11
+ "electron"
12
+ ],
13
+ "homepage": "https://github.com/HagiCode-org/steamworks.js#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/HagiCode-org/steamworks.js/issues"
16
+ },
17
+ "version": "0.1.6-dev.17",
18
+ "main": "index.js",
19
+ "types": "index.d.ts",
20
+ "napi": {
21
+ "name": "steamworksjs",
22
+ "triples": {
23
+ "additional": [
24
+ "x86_64-pc-windows-msvc",
25
+ "x86_64-unknown-linux-gnu",
26
+ "x86_64-apple-darwin",
27
+ "aarch64-apple-darwin"
28
+ ]
29
+ }
30
+ },
31
+ "files": [
32
+ "dist/*",
33
+ "index.js",
34
+ "*.d.ts",
35
+ "README.md"
36
+ ],
37
+ "license": "MIT",
38
+ "devDependencies": {
39
+ "@napi-rs/cli": "2.18.4",
40
+ "electron": "24.2.0",
41
+ "rimraf": "6.0.1",
42
+ "typescript": "5.5.3"
43
+ },
44
+ "dependencies": {
45
+ "@types/node": "*"
46
+ },
47
+ "engines": {
48
+ "node": ">= 14"
49
+ },
50
+ "scripts": {
51
+ "build": "node build --release",
52
+ "build:debug": "node build",
53
+ "prune": "rimraf dist target client.d.ts",
54
+ "format": "cargo clippy --fix --allow-staged && cargo fmt",
55
+ "prepack": "node scripts/check-package.js",
56
+ "test:offline": "node test/offline-smoke-test.js",
57
+ "test:types": "cd test/typescript && pnpm run compile"
58
+ },
59
+ "repository": {
60
+ "type": "git",
61
+ "url": "https://github.com/HagiCode-org/steamworks.js"
62
+ },
63
+ "publishConfig": {
64
+ "access": "public"
65
+ },
66
+ "packageManager": "pnpm@12.16.1"
67
+ }