Skip to content

Commit

Permalink
Merge pull request #10 from fakoua/system-features01
Browse files Browse the repository at this point in the history
Implemetation of:
  • Loading branch information
fakoua authored Dec 23, 2023
2 parents ab20a57 + 199c5d0 commit befc3c6
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 6 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Speaks the text your specify by using the Speech library (SAPI) that comes with

```ts
import * as swissKnife from "https://deno.land/x/swissKnife/mod.ts"
let res = await swissKnife.speak("Hello from the other world")
await swissKnife.speak("Hello from the other world")
```

Run your script file:
Expand All @@ -34,7 +34,7 @@ You can also set the rate and the volume:

```ts
import * as swissKnife from "https://deno.land/x/swissKnife/mod.ts"
let res = await swissKnife.speak("Hello from the other world", {rate: 3, volume: 80})
await swissKnife.speak("Hello from the other world", {rate: 3, volume: 80})
//rate: -10 -> 10
//volume: 0% -> 100%
```
Expand Down Expand Up @@ -88,28 +88,28 @@ With swissKnife you can take a screenshot of the full screen, dual screen and ac

```ts
//Save the primary screen image.
let res = await swissKnife.screenshot("c:\\myfolder\\myfile.png")
await swissKnife.screenshot("c:\\myfolder\\myfile.png")
```

Also you can specify Dual monitor:

```ts
//take a screenshot of both screens
let res = await swissKnife.screenshot("c:\\myfolder\\myfile.png", "Dual")
await swissKnife.screenshot("c:\\myfolder\\myfile.png", "Dual")
```

Also you can specify the current active window:

```ts
//take a screenshot of both screens
let res = await swissKnife.screenshot("c:\\myfolder\\myfile.png", "Window")
await swissKnife.screenshot("c:\\myfolder\\myfile.png", "Window")
```

The third parameter allows you to specify the coordinates, width and height of the area:

```ts
//take a screenshot of both screens
let res = await swissKnife.screenshot("c:\\myfolder\\myfile.png", "Single", {
await swissKnife.screenshot("c:\\myfolder\\myfile.png", "Single", {
x: 10,
y: 30,
width: 200,
Expand Down Expand Up @@ -163,6 +163,19 @@ This method allows you to hide, show, minimize, maximize, flush ... windows form
await swissKnife.winAction("Untit", "Contains", "Flash")
```

## Window Power
This method allows you to Logoff, Power Off and Stand by the system.

`power(mode:PowerMode)`

- mode: Supported values Logoff, Power off and Standby

```ts
import * as swissKnife from "https://deno.land/x/swissKnife/mod.ts"
//Standby the system
await swissKnife.power("StandBy")
```

## License

[MIT](LICENSE)
Expand Down
59 changes: 59 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Screen, Monitor } from "./src/models/screen.ts"
import type { SpeakOptions } from "./src/models/speakOptions.ts"
import type { Find } from "./src/models/findMode.ts"
import type { WinActions } from "./src/models/winActions.ts"
import { PowerMode } from "./src/models/powerMode.ts";


/**
Expand Down Expand Up @@ -327,6 +328,64 @@ export async function playMp3(mp3Path: string): Promise<boolean> {
return exitCode === 0
}


/**
* Turn off the monitor
* @date 12/23/2023 - 4:28:24 PM
*
* @example
* ```ts
* import * as swissKnife from "https://deno.land/x/swissKnife/mod.ts"
* await swissKnife.monitorOff() //turn off the monitor
* ```
* @export
* @async
* @returns {Promise<number>} process exit code.
*/
export async function monitorOff(): Promise<number> {
const args = [
"monitor",
"off",
]
const exitCode = await runNirCmd(args);
return exitCode
}


/**
* Windows Power
* @date 12/23/2023 - 4:35:59 PM
*
* @example
* ```ts
* import * as swissKnife from "https://deno.land/x/swissKnife/mod.ts"
* await swissKnife.power("StandBy") //Windows standby
* //Supported: StandBy, Logoff and Poweroff
* ```
* @export
* @async
* @param {PowerMode} mode standby, logoff, poweroff
* @returns {Promise<number>} process exit code
*/
export async function power(mode:PowerMode): Promise<number> {
const args = [];
switch (mode) {
case "Logoff":
args.push("exitwin")
args.push("logoff")
break;
case "StandBy":
args.push("standby")
break;
case "PowerOff":
args.push("exitwin")
args.push("poweroff")
break;
}
const exitCode = await runNirCmd(args);
return exitCode
}

async function runNirCmd(args: Array<string>): Promise<number> {
const OS = utils.getOS();

Expand Down
1 change: 1 addition & 0 deletions src/models/powerMode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type PowerMode = "StandBy" | "Logoff" | "PowerOff"

0 comments on commit befc3c6

Please # to comment.