steamworks.js-timmy 0.1.1 → 0.1.3

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.
@@ -0,0 +1,5 @@
1
+ export function init(appId?: number): Omit<Client, "init" | "runCallbacks">;
2
+ export function restartAppIfNecessary(appId: number): boolean;
3
+ export function electronEnableSteamOverlay(disableEachFrameInvalidation?: boolean): void;
4
+ export type Client = typeof import("./client.d");
5
+ export const SteamCallback: typeof import("./client.d").callback.SteamCallback;
@@ -0,0 +1,77 @@
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'>}
27
+ */
28
+ module.exports.init = (appId) => {
29
+ const { init: internalInit, runCallbacks, restartAppIfNecessary, ...api } = nativeBinding
30
+
31
+ internalInit(appId)
32
+
33
+ clearInterval(runCallbacksInterval)
34
+ runCallbacksInterval = setInterval(runCallbacks, 1000 / 30)
35
+
36
+ return api
37
+ }
38
+
39
+ /**
40
+ * @param {number} appId - App ID of the game to load
41
+ * {@link https://partner.steamgames.com/doc/api/steam_api#SteamAPI_RestartAppIfNecessary}
42
+ * @returns {boolean}
43
+ */
44
+ module.exports.restartAppIfNecessary = (appId) => nativeBinding.restartAppIfNecessary(appId);
45
+
46
+ /**
47
+ * Enable the steam overlay on electron
48
+ * @param {boolean} [disableEachFrameInvalidation] - Should attach a single pixel to be rendered each frame
49
+ */
50
+ module.exports.electronEnableSteamOverlay = (disableEachFrameInvalidation) => {
51
+ const electron = require('electron')
52
+ if (!electron) {
53
+ throw new Error('Electron module not found')
54
+ }
55
+
56
+ electron.app.commandLine.appendSwitch('in-process-gpu')
57
+ electron.app.commandLine.appendSwitch('disable-direct-composition')
58
+
59
+ if (!disableEachFrameInvalidation) {
60
+ /** @param {electron.BrowserWindow} browserWindow */
61
+ const attachFrameInvalidator = (browserWindow) => {
62
+ browserWindow.steamworksRepaintInterval = setInterval(() => {
63
+ if (browserWindow.isDestroyed()) {
64
+ clearInterval(browserWindow.steamworksRepaintInterval)
65
+ } else if (!browserWindow.webContents.isPainting()) {
66
+ browserWindow.webContents.invalidate()
67
+ }
68
+ }, 1000 / 60)
69
+ }
70
+
71
+ electron.BrowserWindow.getAllWindows().forEach(attachFrameInvalidator)
72
+ electron.app.on('browser-window-created', (_, bw) => attachFrameInvalidator(bw))
73
+ }
74
+ }
75
+
76
+ const SteamCallback = nativeBinding.callback.SteamCallback
77
+ module.exports.SteamCallback = SteamCallback