@cjser/lock-system 3.0.1-cjser.2
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/dist-cjser/index.cjs +90 -0
- package/index.d.ts +13 -0
- package/index.js +68 -0
- package/license +9 -0
- package/lock +0 -0
- package/package.json +69 -0
- package/readme.md +39 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// packages/@cjser/lock-system.tmp-26-1778153327145/index.js
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
default: () => lockSystem
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(index_exports);
|
|
35
|
+
var import_node_process = __toESM(require("node:process"), 1);
|
|
36
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
37
|
+
var import_node_child_process = __toESM(require("node:child_process"), 1);
|
|
38
|
+
var import_node_url = require("node:url");
|
|
39
|
+
var import_meta = {};
|
|
40
|
+
var __dirname = import_node_path.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
41
|
+
var getExistingLinuxCommand = () => {
|
|
42
|
+
const commands = [{
|
|
43
|
+
name: "xdg-screensaver",
|
|
44
|
+
argument: "lock"
|
|
45
|
+
}, {
|
|
46
|
+
name: "gnome-screensaver-command",
|
|
47
|
+
argument: "--lock"
|
|
48
|
+
}, {
|
|
49
|
+
name: "cinnamon-screensaver-command",
|
|
50
|
+
argument: "--lock"
|
|
51
|
+
}, {
|
|
52
|
+
name: "dm-tool",
|
|
53
|
+
argument: "lock"
|
|
54
|
+
}];
|
|
55
|
+
return commands.find((command) => {
|
|
56
|
+
try {
|
|
57
|
+
const result = import_node_child_process.default.execFileSync("which", [command.name], {
|
|
58
|
+
encoding: "utf8",
|
|
59
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
60
|
+
});
|
|
61
|
+
return result && result.length > 0;
|
|
62
|
+
} catch {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
function lockSystem() {
|
|
68
|
+
switch (import_node_process.default.platform) {
|
|
69
|
+
case "darwin": {
|
|
70
|
+
import_node_child_process.default.execFileSync(import_node_path.default.join(__dirname, "lock"), { stdio: "ignore" });
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case "win32": {
|
|
74
|
+
import_node_child_process.default.execFileSync("rundll32.exe", ["user32.dll,LockWorkStation"], { stdio: "ignore" });
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
case "linux": {
|
|
78
|
+
const existingCommand = getExistingLinuxCommand();
|
|
79
|
+
if (existingCommand) {
|
|
80
|
+
import_node_child_process.default.execFileSync(existingCommand.name, [existingCommand.argument], { stdio: "ignore" });
|
|
81
|
+
} else {
|
|
82
|
+
throw new Error("No applicable command found. Please consider installing xdg-screensaver, gnome-screensaver, cinnamon-screensaver, or dm-tool, and try again.");
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
default: {
|
|
87
|
+
throw new Error(`Unsupported OS: ${import_node_process.default.platform}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Lock your system. Shows the login screen the next time you use the computer.
|
|
3
|
+
|
|
4
|
+
Throws an error if executing the lock command fails or if the OS is not supported.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import lockSystem from '@cjser/lock-system';
|
|
9
|
+
|
|
10
|
+
lockSystem();
|
|
11
|
+
```
|
|
12
|
+
*/
|
|
13
|
+
export default function lockSystem(): void;
|
package/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import childProcess from 'node:child_process';
|
|
4
|
+
import {fileURLToPath} from 'node:url';
|
|
5
|
+
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
|
|
8
|
+
const getExistingLinuxCommand = () => {
|
|
9
|
+
// See: https://askubuntu.com/questions/184728/how-do-i-lock-the-screen-from-a-terminal
|
|
10
|
+
const commands = [{
|
|
11
|
+
name: 'xdg-screensaver',
|
|
12
|
+
argument: 'lock',
|
|
13
|
+
}, {
|
|
14
|
+
name: 'gnome-screensaver-command',
|
|
15
|
+
argument: '--lock',
|
|
16
|
+
}, {
|
|
17
|
+
name: 'cinnamon-screensaver-command',
|
|
18
|
+
argument: '--lock',
|
|
19
|
+
}, {
|
|
20
|
+
name: 'dm-tool',
|
|
21
|
+
argument: 'lock',
|
|
22
|
+
}];
|
|
23
|
+
|
|
24
|
+
return commands.find(command => {
|
|
25
|
+
try {
|
|
26
|
+
const result = childProcess.execFileSync('which', [command.name], {
|
|
27
|
+
encoding: 'utf8',
|
|
28
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return result && result.length > 0;
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default function lockSystem() {
|
|
39
|
+
switch (process.platform) {
|
|
40
|
+
case 'darwin': {
|
|
41
|
+
// Binary: https://github.com/sindresorhus/macos-lock
|
|
42
|
+
childProcess.execFileSync(path.join(__dirname, 'lock'), {stdio: 'ignore'});
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
case 'win32': {
|
|
47
|
+
// See: https://superuser.com/questions/21179/command-line-cmd-command-to-lock-a-windows-machine
|
|
48
|
+
childProcess.execFileSync('rundll32.exe', ['user32.dll,LockWorkStation'], {stdio: 'ignore'});
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
case 'linux': {
|
|
53
|
+
const existingCommand = getExistingLinuxCommand();
|
|
54
|
+
|
|
55
|
+
if (existingCommand) {
|
|
56
|
+
childProcess.execFileSync(existingCommand.name, [existingCommand.argument], {stdio: 'ignore'});
|
|
57
|
+
} else {
|
|
58
|
+
throw new Error('No applicable command found. Please consider installing xdg-screensaver, gnome-screensaver, cinnamon-screensaver, or dm-tool, and try again.');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
default: {
|
|
65
|
+
throw new Error(`Unsupported OS: ${process.platform}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
package/license
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/lock
ADDED
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cjser/lock-system",
|
|
3
|
+
"version": "3.0.1-cjser.2",
|
|
4
|
+
"description": "Lock your system",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://code.moenext.com/3rdeye/cjser.git"
|
|
9
|
+
},
|
|
10
|
+
"funding": "https://github.com/sponsors/sindresorhus",
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Sindre Sorhus",
|
|
13
|
+
"email": "sindresorhus@gmail.com",
|
|
14
|
+
"url": "https://sindresorhus.com"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
"require": "./dist-cjser/index.cjs",
|
|
19
|
+
"default": "./index.js"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "xo && ava && tsd"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"index.js",
|
|
29
|
+
"index.d.ts",
|
|
30
|
+
"lock",
|
|
31
|
+
"dist-cjser"
|
|
32
|
+
],
|
|
33
|
+
"keywords": [
|
|
34
|
+
"lock",
|
|
35
|
+
"system",
|
|
36
|
+
"macos",
|
|
37
|
+
"mac",
|
|
38
|
+
"linux",
|
|
39
|
+
"windows",
|
|
40
|
+
"screen",
|
|
41
|
+
"os",
|
|
42
|
+
"login",
|
|
43
|
+
"password"
|
|
44
|
+
],
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"ava": "^3.15.0",
|
|
47
|
+
"tsd": "^0.17.0",
|
|
48
|
+
"xo": "^0.44.0"
|
|
49
|
+
},
|
|
50
|
+
"main": "./dist-cjser/index.cjs",
|
|
51
|
+
"cjser": {
|
|
52
|
+
"sourceVersion": "3.0.1",
|
|
53
|
+
"cjserVersion": 2,
|
|
54
|
+
"original": {
|
|
55
|
+
"name": "lock-system",
|
|
56
|
+
"version": "3.0.1",
|
|
57
|
+
"exports": "./index.js",
|
|
58
|
+
"repository": "sindresorhus/lock-system",
|
|
59
|
+
"files": [
|
|
60
|
+
"index.js",
|
|
61
|
+
"index.d.ts",
|
|
62
|
+
"lock"
|
|
63
|
+
],
|
|
64
|
+
"scripts": {
|
|
65
|
+
"test": "xo && ava && tsd"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# lock-system
|
|
2
|
+
|
|
3
|
+
> Lock your system
|
|
4
|
+
|
|
5
|
+
Shows the login screen the next time you use the computer.
|
|
6
|
+
|
|
7
|
+
Supports macOS, Linux, and Windows.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install lock-system
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import lockSystem from 'lock-system';
|
|
19
|
+
|
|
20
|
+
lockSystem();
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## API
|
|
24
|
+
|
|
25
|
+
### lockSystem()
|
|
26
|
+
|
|
27
|
+
Locks the system.
|
|
28
|
+
|
|
29
|
+
Throws an error if executing the lock command fails or if the OS is not supported.
|
|
30
|
+
|
|
31
|
+
## Related
|
|
32
|
+
|
|
33
|
+
- [lock-cli](https://github.com/sindresorhus/lock-cli) - CLI for this module
|
|
34
|
+
- [alfred-lock](https://github.com/sindresorhus/alfred-lock) - Alfred workflow
|
|
35
|
+
|
|
36
|
+
## cjser
|
|
37
|
+
|
|
38
|
+
This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
|
|
39
|
+
Original repository: https://github.com/sindresorhus/lock-system
|