@sweet-search/bg-priority 2.6.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.
- package/index.d.ts +10 -0
- package/index.js +80 -0
- package/package.json +34 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Enter (`enable = true`) or leave (`enable = false`) OS background mode for the
|
|
4
|
+
* calling process/thread (Windows PROCESS_MODE_BACKGROUND_BEGIN/END, macOS
|
|
5
|
+
* per-thread QOS_CLASS_BACKGROUND/restore).
|
|
6
|
+
*
|
|
7
|
+
* Returns `true` when a native demotion/restoration was applied on this
|
|
8
|
+
* platform, `false` when this platform has no native lever. Never throws.
|
|
9
|
+
*/
|
|
10
|
+
export function setBackgroundMode(enable: boolean): boolean;
|
package/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// Loader for @sweet-search/bg-priority napi addon.
|
|
3
|
+
//
|
|
4
|
+
// Resolves the per-platform prebuilt binary: a locally-built `.node` (dev /
|
|
5
|
+
// `npm run build:bg-priority`) takes precedence, otherwise the matching
|
|
6
|
+
// per-platform optionalDependency package. If neither is present this module
|
|
7
|
+
// throws on require — which is exactly what os-priority.mjs's
|
|
8
|
+
// `loadNativePriorityAddon()` catches to fall back to the spawn-based levers.
|
|
9
|
+
//
|
|
10
|
+
// napi-rs (v3) emits the cdylib `.node` but not always this JS shim, so it is
|
|
11
|
+
// committed alongside the crate sources.
|
|
12
|
+
|
|
13
|
+
const { existsSync } = require('fs');
|
|
14
|
+
const { join } = require('path');
|
|
15
|
+
|
|
16
|
+
const { platform, arch } = process;
|
|
17
|
+
|
|
18
|
+
function localBinary(name) {
|
|
19
|
+
return join(__dirname, name);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function tryLoad(localName, pkgName) {
|
|
23
|
+
const local = localBinary(localName);
|
|
24
|
+
if (existsSync(local)) return require(local);
|
|
25
|
+
return require(pkgName);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let binding = null;
|
|
29
|
+
|
|
30
|
+
switch (platform) {
|
|
31
|
+
case 'darwin':
|
|
32
|
+
if (arch === 'arm64') {
|
|
33
|
+
binding = tryLoad(
|
|
34
|
+
'sweet-search-bg-priority.darwin-arm64.node',
|
|
35
|
+
'@sweet-search/bg-priority-darwin-arm64',
|
|
36
|
+
);
|
|
37
|
+
} else if (arch === 'x64') {
|
|
38
|
+
binding = tryLoad(
|
|
39
|
+
'sweet-search-bg-priority.darwin-x64.node',
|
|
40
|
+
'@sweet-search/bg-priority-darwin-x64',
|
|
41
|
+
);
|
|
42
|
+
} else {
|
|
43
|
+
throw new Error(`Unsupported macOS arch for bg-priority: ${arch}`);
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
case 'win32':
|
|
47
|
+
if (arch === 'x64') {
|
|
48
|
+
binding = tryLoad(
|
|
49
|
+
'sweet-search-bg-priority.win32-x64-msvc.node',
|
|
50
|
+
'@sweet-search/bg-priority-win32-x64-msvc',
|
|
51
|
+
);
|
|
52
|
+
} else if (arch === 'arm64') {
|
|
53
|
+
binding = tryLoad(
|
|
54
|
+
'sweet-search-bg-priority.win32-arm64-msvc.node',
|
|
55
|
+
'@sweet-search/bg-priority-win32-arm64-msvc',
|
|
56
|
+
);
|
|
57
|
+
} else {
|
|
58
|
+
throw new Error(`Unsupported Windows arch for bg-priority: ${arch}`);
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
case 'linux':
|
|
62
|
+
if (arch === 'x64') {
|
|
63
|
+
binding = tryLoad(
|
|
64
|
+
'sweet-search-bg-priority.linux-x64-gnu.node',
|
|
65
|
+
'@sweet-search/bg-priority-linux-x64-gnu',
|
|
66
|
+
);
|
|
67
|
+
} else if (arch === 'arm64') {
|
|
68
|
+
binding = tryLoad(
|
|
69
|
+
'sweet-search-bg-priority.linux-arm64-gnu.node',
|
|
70
|
+
'@sweet-search/bg-priority-linux-arm64-gnu',
|
|
71
|
+
);
|
|
72
|
+
} else {
|
|
73
|
+
throw new Error(`Unsupported Linux arch for bg-priority: ${arch}`);
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
throw new Error(`Unsupported platform for bg-priority: ${platform}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
module.exports.setBackgroundMode = binding.setBackgroundMode;
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sweet-search/bg-priority",
|
|
3
|
+
"version": "2.6.0",
|
|
4
|
+
"description": "Optional napi-rs addon: process/thread background OS scheduling (macOS QOS_CLASS_BACKGROUND) for the sweet-search index-maintainer daemon. Per-platform prebuilt binaries ship as optionalDependencies (darwin + linux); a missing/failed native build is non-fatal — os-priority.mjs falls back to spawn-based taskpolicy/ionice/chrt + os.setPriority.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"index.js",
|
|
10
|
+
"index.d.ts"
|
|
11
|
+
],
|
|
12
|
+
"napi": {
|
|
13
|
+
"binaryName": "sweet-search-bg-priority",
|
|
14
|
+
"targets": [
|
|
15
|
+
"aarch64-apple-darwin",
|
|
16
|
+
"x86_64-apple-darwin",
|
|
17
|
+
"x86_64-unknown-linux-gnu",
|
|
18
|
+
"aarch64-unknown-linux-gnu"
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
"optionalDependencies": {
|
|
22
|
+
"@sweet-search/bg-priority-darwin-arm64": "2.6.0",
|
|
23
|
+
"@sweet-search/bg-priority-darwin-x64": "2.6.0",
|
|
24
|
+
"@sweet-search/bg-priority-linux-x64-gnu": "2.6.0",
|
|
25
|
+
"@sweet-search/bg-priority-linux-arm64-gnu": "2.6.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "napi build --platform --release",
|
|
29
|
+
"build:debug": "napi build --platform"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@napi-rs/cli": "^3.5.1"
|
|
33
|
+
}
|
|
34
|
+
}
|