mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Expose Electron powerMonitor API to extensions (#4844)
This commit is contained in:
parent
ab61f84364
commit
e950d3a77e
@ -6,6 +6,7 @@
|
|||||||
import * as Catalog from "./catalog";
|
import * as Catalog from "./catalog";
|
||||||
import * as Navigation from "./navigation";
|
import * as Navigation from "./navigation";
|
||||||
import * as K8sApi from "./k8s-api";
|
import * as K8sApi from "./k8s-api";
|
||||||
|
import * as Power from "./power";
|
||||||
import { IpcMain as Ipc } from "../ipc/ipc-main";
|
import { IpcMain as Ipc } from "../ipc/ipc-main";
|
||||||
import { LensMainExtension as LensExtension } from "../lens-main-extension";
|
import { LensMainExtension as LensExtension } from "../lens-main-extension";
|
||||||
|
|
||||||
@ -15,4 +16,5 @@ export {
|
|||||||
K8sApi,
|
K8sApi,
|
||||||
Ipc,
|
Ipc,
|
||||||
LensExtension,
|
LensExtension,
|
||||||
|
Power,
|
||||||
};
|
};
|
||||||
|
|||||||
51
src/extensions/main-api/power.ts
Normal file
51
src/extensions/main-api/power.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { powerMonitor } from "electron";
|
||||||
|
import type { Disposer } from "../../common/utils/disposer";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event listener for system power events
|
||||||
|
*/
|
||||||
|
export type PowerEventListener = () => void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds event listener to system suspend events
|
||||||
|
* @param listener function which will be called on system suspend
|
||||||
|
* @returns function to remove event listener
|
||||||
|
*/
|
||||||
|
export const onSuspend = (listener: PowerEventListener): Disposer => {
|
||||||
|
powerMonitor.on("suspend", listener);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
powerMonitor.off("suspend", listener);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds event listener to system resume event
|
||||||
|
* @param listener function which will be called on system resume
|
||||||
|
* @returns function to remove event listener
|
||||||
|
*/
|
||||||
|
export const onResume = (listener: PowerEventListener): Disposer => {
|
||||||
|
powerMonitor.on("resume", listener);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
powerMonitor.off("resume", listener);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds event listener to the event which is emitted when
|
||||||
|
* the system is about to reboot or shut down
|
||||||
|
* @param listener function which will be called on system shutdown
|
||||||
|
* @returns function to remove event listener
|
||||||
|
*/
|
||||||
|
export const onShutdown = (listener: PowerEventListener): Disposer => {
|
||||||
|
powerMonitor.on("shutdown", listener);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
powerMonitor.off("shutdown", listener);
|
||||||
|
};
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user