Comparing version 0.0.2 to 0.0.3
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
exports.__esModule = true; | ||
exports.getHWnd = exports.readBufferByOS = exports.SWP_NOSIZE = exports.SWP_NOMOVE = exports.HWND_BOTTOM = exports.WM_WINDOWPOSCHANGING = exports.SWP_NOZORDER = exports.WINDOWPOS = exports.GWLP_HWNDPARENT = exports.DWMWA_EXCLUDED_FROM_PEEK = void 0; | ||
var ref_napi_1 = __importDefault(require("ref-napi")); | ||
var ffi_napi_1 = __importDefault(require("ffi-napi")); | ||
var os_1 = __importDefault(require("os")); | ||
var ref_struct_di_1 = __importDefault(require("ref-struct-di")); | ||
var electron_1 = require("electron"); | ||
exports.DWMWA_EXCLUDED_FROM_PEEK = 12; | ||
exports.GWLP_HWNDPARENT = -8; | ||
var StructType = ref_struct_di_1["default"](ref_napi_1["default"]); | ||
exports.WINDOWPOS = StructType({ | ||
hwnd: ref_napi_1["default"].types.int32, | ||
hwndInsertAfter: ref_napi_1["default"].types.int32, | ||
x: ref_napi_1["default"].types.int32, | ||
y: ref_napi_1["default"].types.int32, | ||
cx: ref_napi_1["default"].types.int32, | ||
cy: ref_napi_1["default"].types.int32, | ||
flags: ref_napi_1["default"].types.uint32 | ||
}); | ||
exports.SWP_NOZORDER = 4; | ||
exports.WM_WINDOWPOSCHANGING = 70; | ||
exports.HWND_BOTTOM = 1; | ||
exports.SWP_NOMOVE = 2; | ||
exports.SWP_NOSIZE = 1; | ||
function readBufferByOS(buf) { | ||
return os_1["default"].endianness() == 'LE' ? buf.readInt32LE() : buf.readInt32BE(); | ||
} | ||
exports.readBufferByOS = readBufferByOS; | ||
; | ||
function getHWnd(win) { | ||
if (win instanceof electron_1.BrowserWindow) | ||
return readBufferByOS(win.getNativeWindowHandle()); | ||
else if (win instanceof Buffer) | ||
return readBufferByOS(win); | ||
else | ||
throw new Error('Type that doesn\'t support.'); | ||
} | ||
exports.getHWnd = getHWnd; | ||
; | ||
var electget = new /** @class */ (function () { | ||
function Electget() { | ||
this.platform = process.platform; | ||
if (this.platform !== 'win32') { | ||
console.warn('It does not support OS other than Windows.'); | ||
} | ||
else { | ||
this.user32 = new ffi_napi_1["default"].Library('user32', { | ||
FindWindowExA: ['ulong', ['ulong', 'ulong', 'string', 'ulong']], | ||
GetDesktopWindow: ['ulong', []], | ||
SetWindowLongPtrA: ['ulong', ['int', 'int', 'int']], | ||
SetWindowPos: ['bool', ['ulong', 'ulong', 'int', 'int', 'int', 'int', 'uint']] | ||
}); | ||
this.dwmapi = new ffi_napi_1["default"].Library('dwmapi.dll', { | ||
DwmSetWindowAttribute: ['ulong', ['long', 'ulong', 'bool*', 'ulong']] | ||
}); | ||
this.kernel32 = new ffi_napi_1["default"].Library('kernel32.dll', { | ||
GetLastError: ['ulong', []] | ||
}); | ||
} | ||
} | ||
Electget.prototype.preventFromAeroPeek = function (win) { | ||
if (!this.dwmapi) | ||
return false; | ||
var hWnd = getHWnd(win); | ||
var bool = ref_napi_1["default"].alloc('bool', true); | ||
this.dwmapi.DwmSetWindowAttribute(hWnd, exports.DWMWA_EXCLUDED_FROM_PEEK, bool.ref(), ref_napi_1["default"].sizeof.int32); | ||
return true; | ||
}; | ||
Electget.prototype.preventFromShowDesktop = function (win) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
if (!this.user32) | ||
return false; | ||
var hWnd = getHWnd(win); | ||
var progman = (_a = this.user32) === null || _a === void 0 ? void 0 : _a.FindWindowExA(ref_napi_1["default"].NULL, ref_napi_1["default"].NULL, 'Progman', ref_napi_1["default"].NULL); | ||
var defView = (_b = this.user32) === null || _b === void 0 ? void 0 : _b.FindWindowExA(progman, ref_napi_1["default"].NULL, 'SHELLDLL_DefView', ref_napi_1["default"].NULL); | ||
if (!defView) { // find again | ||
var desktopHWnd = (_d = (_c = this.user32) === null || _c === void 0 ? void 0 : _c.GetDesktopWindow()) !== null && _d !== void 0 ? _d : 0; | ||
var workerW = 0; | ||
do { | ||
workerW = (_e = this.user32) === null || _e === void 0 ? void 0 : _e.FindWindowExA(desktopHWnd, workerW, 'WorkerW', ref_napi_1["default"].NULL); | ||
defView = (_f = this.user32) === null || _f === void 0 ? void 0 : _f.FindWindowExA(workerW, ref_napi_1["default"].NULL, 'SHELLDLL_DefView', ref_napi_1["default"].NULL); | ||
} while (!defView && workerW); | ||
} | ||
if (!defView) | ||
return false; | ||
(_g = this.user32) === null || _g === void 0 ? void 0 : _g.SetWindowLongPtrA(hWnd, exports.GWLP_HWNDPARENT, defView); | ||
return true; | ||
}; | ||
Electget.prototype.cancelPreventFromShowDesktop = function (win) { | ||
if (!this.user32) | ||
return false; | ||
var hWnd = getHWnd(win); | ||
this.user32.SetWindowLongPtrA(hWnd, exports.GWLP_HWNDPARENT, this.user32.GetDesktopWindow()); | ||
}; | ||
Electget.prototype.preventChangeZOrder = function (browserWindow) { | ||
browserWindow.hookWindowMessage(exports.WM_WINDOWPOSCHANGING, function (wParam, lParam) { | ||
var buf = Buffer.alloc(8); | ||
buf.type = ref_napi_1["default"].refType(exports.WINDOWPOS); | ||
lParam.copy(buf); | ||
var actualStructDataBuffer = buf.deref(); | ||
var windowPos = actualStructDataBuffer.deref(); | ||
var newFlags = windowPos.flags | exports.SWP_NOZORDER; | ||
actualStructDataBuffer.writeUInt32LE(newFlags, 6); | ||
}); | ||
return function cancelPreventChangeZOrder() { | ||
browserWindow.unhookWindowMessage(exports.WM_WINDOWPOSCHANGING); | ||
}; | ||
}; | ||
Electget.prototype.moveToBottom = function (win) { | ||
if (!this.user32) | ||
return false; | ||
var hWnd = getHWnd(win); | ||
this.user32.SetWindowPos(hWnd, exports.HWND_BOTTOM, 0, 0, 0, 0, exports.SWP_NOMOVE | exports.SWP_NOSIZE); | ||
}; | ||
Electget.prototype.alwaysOnBottom = function (browserWindow) { | ||
var hWnd = browserWindow.getNativeWindowHandle(); | ||
this.moveToBottom(hWnd); | ||
this.preventChangeZOrder(browserWindow); | ||
this.preventFromShowDesktop(hWnd); | ||
}; | ||
Electget.prototype.cancelAlwaysOnBottom = function (browserWindow) { | ||
var hWnd = browserWindow.getNativeWindowHandle(); | ||
browserWindow.unhookWindowMessage(exports.WM_WINDOWPOSCHANGING); | ||
this.cancelPreventFromShowDesktop(hWnd); | ||
}; | ||
return Electget; | ||
}()); | ||
var electget_1 = require("./electget"); | ||
var electget = new electget_1.Electget(); | ||
exports["default"] = electget; |
@@ -1,124 +0,3 @@ | ||
import ref from 'ref-napi'; | ||
import ffi from 'ffi-napi'; | ||
import os from 'os'; | ||
import di from 'ref-struct-di'; | ||
import { BrowserWindow } from 'electron'; | ||
export var DWMWA_EXCLUDED_FROM_PEEK = 12; | ||
export var GWLP_HWNDPARENT = -8; | ||
var StructType = di(ref); | ||
export var WINDOWPOS = StructType({ | ||
hwnd: ref.types.int32, | ||
hwndInsertAfter: ref.types.int32, | ||
x: ref.types.int32, | ||
y: ref.types.int32, | ||
cx: ref.types.int32, | ||
cy: ref.types.int32, | ||
flags: ref.types.uint32 | ||
}); | ||
export var SWP_NOZORDER = 4; | ||
export var WM_WINDOWPOSCHANGING = 70; | ||
export var HWND_BOTTOM = 1; | ||
export var SWP_NOMOVE = 2; | ||
export var SWP_NOSIZE = 1; | ||
export function readBufferByOS(buf) { | ||
return os.endianness() == 'LE' ? buf.readInt32LE() : buf.readInt32BE(); | ||
} | ||
; | ||
export function getHWnd(win) { | ||
if (win instanceof BrowserWindow) | ||
return readBufferByOS(win.getNativeWindowHandle()); | ||
else if (win instanceof Buffer) | ||
return readBufferByOS(win); | ||
else | ||
throw new Error('Type that doesn\'t support.'); | ||
} | ||
; | ||
var electget = new /** @class */ (function () { | ||
function Electget() { | ||
this.platform = process.platform; | ||
if (this.platform !== 'win32') { | ||
console.warn('It does not support OS other than Windows.'); | ||
} | ||
else { | ||
this.user32 = new ffi.Library('user32', { | ||
FindWindowExA: ['ulong', ['ulong', 'ulong', 'string', 'ulong']], | ||
GetDesktopWindow: ['ulong', []], | ||
SetWindowLongPtrA: ['ulong', ['int', 'int', 'int']], | ||
SetWindowPos: ['bool', ['ulong', 'ulong', 'int', 'int', 'int', 'int', 'uint']] | ||
}); | ||
this.dwmapi = new ffi.Library('dwmapi.dll', { | ||
DwmSetWindowAttribute: ['ulong', ['long', 'ulong', 'bool*', 'ulong']] | ||
}); | ||
this.kernel32 = new ffi.Library('kernel32.dll', { | ||
GetLastError: ['ulong', []] | ||
}); | ||
} | ||
} | ||
Electget.prototype.preventFromAeroPeek = function (win) { | ||
if (!this.dwmapi) | ||
return false; | ||
var hWnd = getHWnd(win); | ||
var bool = ref.alloc('bool', true); | ||
this.dwmapi.DwmSetWindowAttribute(hWnd, DWMWA_EXCLUDED_FROM_PEEK, bool.ref(), ref.sizeof.int32); | ||
return true; | ||
}; | ||
Electget.prototype.preventFromShowDesktop = function (win) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
if (!this.user32) | ||
return false; | ||
var hWnd = getHWnd(win); | ||
var progman = (_a = this.user32) === null || _a === void 0 ? void 0 : _a.FindWindowExA(ref.NULL, ref.NULL, 'Progman', ref.NULL); | ||
var defView = (_b = this.user32) === null || _b === void 0 ? void 0 : _b.FindWindowExA(progman, ref.NULL, 'SHELLDLL_DefView', ref.NULL); | ||
if (!defView) { // find again | ||
var desktopHWnd = (_d = (_c = this.user32) === null || _c === void 0 ? void 0 : _c.GetDesktopWindow()) !== null && _d !== void 0 ? _d : 0; | ||
var workerW = 0; | ||
do { | ||
workerW = (_e = this.user32) === null || _e === void 0 ? void 0 : _e.FindWindowExA(desktopHWnd, workerW, 'WorkerW', ref.NULL); | ||
defView = (_f = this.user32) === null || _f === void 0 ? void 0 : _f.FindWindowExA(workerW, ref.NULL, 'SHELLDLL_DefView', ref.NULL); | ||
} while (!defView && workerW); | ||
} | ||
if (!defView) | ||
return false; | ||
(_g = this.user32) === null || _g === void 0 ? void 0 : _g.SetWindowLongPtrA(hWnd, GWLP_HWNDPARENT, defView); | ||
return true; | ||
}; | ||
Electget.prototype.cancelPreventFromShowDesktop = function (win) { | ||
if (!this.user32) | ||
return false; | ||
var hWnd = getHWnd(win); | ||
this.user32.SetWindowLongPtrA(hWnd, GWLP_HWNDPARENT, this.user32.GetDesktopWindow()); | ||
}; | ||
Electget.prototype.preventChangeZOrder = function (browserWindow) { | ||
browserWindow.hookWindowMessage(WM_WINDOWPOSCHANGING, function (wParam, lParam) { | ||
var buf = Buffer.alloc(8); | ||
buf.type = ref.refType(WINDOWPOS); | ||
lParam.copy(buf); | ||
var actualStructDataBuffer = buf.deref(); | ||
var windowPos = actualStructDataBuffer.deref(); | ||
var newFlags = windowPos.flags | SWP_NOZORDER; | ||
actualStructDataBuffer.writeUInt32LE(newFlags, 6); | ||
}); | ||
return function cancelPreventChangeZOrder() { | ||
browserWindow.unhookWindowMessage(WM_WINDOWPOSCHANGING); | ||
}; | ||
}; | ||
Electget.prototype.moveToBottom = function (win) { | ||
if (!this.user32) | ||
return false; | ||
var hWnd = getHWnd(win); | ||
this.user32.SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); | ||
}; | ||
Electget.prototype.alwaysOnBottom = function (browserWindow) { | ||
var hWnd = browserWindow.getNativeWindowHandle(); | ||
this.moveToBottom(hWnd); | ||
this.preventChangeZOrder(browserWindow); | ||
this.preventFromShowDesktop(hWnd); | ||
}; | ||
Electget.prototype.cancelAlwaysOnBottom = function (browserWindow) { | ||
var hWnd = browserWindow.getNativeWindowHandle(); | ||
browserWindow.unhookWindowMessage(WM_WINDOWPOSCHANGING); | ||
this.cancelPreventFromShowDesktop(hWnd); | ||
}; | ||
return Electget; | ||
}()); | ||
import { Electget } from './electget'; | ||
var electget = new Electget(); | ||
export default electget; |
@@ -1,47 +0,3 @@ | ||
/// <reference types="node" /> | ||
import ref from 'ref-napi'; | ||
import ffi from 'ffi-napi'; | ||
import di from 'ref-struct-di'; | ||
import { BrowserWindow } from 'electron'; | ||
export declare const DWMWA_EXCLUDED_FROM_PEEK = 12; | ||
export declare const GWLP_HWNDPARENT = -8; | ||
export declare const WINDOWPOS: di.StructType<{ | ||
hwnd: ref.Type<number>; | ||
hwndInsertAfter: ref.Type<number>; | ||
x: ref.Type<number>; | ||
y: ref.Type<number>; | ||
cx: ref.Type<number>; | ||
cy: ref.Type<number>; | ||
flags: ref.Type<number>; | ||
}>; | ||
export declare const SWP_NOZORDER = 4; | ||
export declare const WM_WINDOWPOSCHANGING = 70; | ||
export declare const HWND_BOTTOM = 1; | ||
export declare const SWP_NOMOVE = 2; | ||
export declare const SWP_NOSIZE = 1; | ||
export declare type Win = BrowserWindow | Buffer; | ||
export declare function readBufferByOS(buf: Buffer): number; | ||
export declare function getHWnd(win: Win): number; | ||
declare const electget: { | ||
platform: NodeJS.Platform; | ||
user32?: { | ||
FindWindowExA: ffi.ForeignFunction<string | number, [string | number, string | number, string | null, string | number]>; | ||
GetDesktopWindow: ffi.ForeignFunction<string | number, []>; | ||
SetWindowLongPtrA: ffi.ForeignFunction<string | number, [number, number, number]>; | ||
SetWindowPos: ffi.ForeignFunction<boolean, [string | number, string | number, number, number, number, number, number]>; | ||
} | undefined; | ||
dwmapi?: { | ||
DwmSetWindowAttribute: ffi.ForeignFunction<string | number, [string | number, string | number, ref.Pointer<boolean>, string | number]>; | ||
} | undefined; | ||
kernel32?: { | ||
GetLastError: ffi.ForeignFunction<string | number, []>; | ||
} | undefined; | ||
preventFromAeroPeek(win: Win): boolean; | ||
preventFromShowDesktop(win: Win): boolean; | ||
cancelPreventFromShowDesktop(win: Win): false | undefined; | ||
preventChangeZOrder(browserWindow: BrowserWindow): () => void; | ||
moveToBottom(win: Win): false | undefined; | ||
alwaysOnBottom(browserWindow: BrowserWindow): void; | ||
cancelAlwaysOnBottom(browserWindow: BrowserWindow): void; | ||
}; | ||
import { Electget } from './electget'; | ||
declare const electget: Electget; | ||
export default electget; |
{ | ||
"name": "electget", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Electron tools for creating Windows widgets that are fixed to desktop.", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js", |
# Electget | ||
`Electron` tools for creating Windows widgets that are fixed to desktop. | ||
`Electron` tools for creating Windows widgets that are fixed to desktop. | ||
@@ -14,2 +14,3 @@ This package provides features for widget creation of your Electron application. | ||
## Install | ||
This package uses `ffi-napi`, so you must meet the [ffi-napi requirements](https://github.com/node-ffi-napi/node-ffi-napi#installation) before installation. | ||
@@ -22,2 +23,3 @@ | ||
## Usage | ||
Electget is available in the Electron main process. | ||
@@ -32,3 +34,3 @@ | ||
height: 600, | ||
width: 800 | ||
width: 800, | ||
}); | ||
@@ -55,9 +57,12 @@ | ||
### Methods | ||
#### `alwaysOnBottom(browserWindow)` | ||
- `win` BrowserWindow - Target BrowserWindow object. | ||
`BrowserWindow` is fixed to the bottom without being minimized. | ||
Apply `moveToBottom`, `preventChangeZOrder`, `preventFromShowDesktop` at once. | ||
Apply `moveToBottom`, `preventChangeZOrder`, `preventFromShowDesktop` at once. | ||
#### `cancelAlwaysOnBottom(browserWindow)` | ||
- `win` BrowserWindow - Target BrowserWindow object. | ||
@@ -68,2 +73,3 @@ | ||
#### `preventFromAeroPeek(win)` | ||
- `win` Buffer|BrowserWindow - Target BrowserWindow object or Buffer returned by getNativeWindowHandle. | ||
@@ -74,2 +80,3 @@ | ||
#### `preventFromShowDesktop(win)` | ||
- `win` Buffer|BrowserWindow - Target BrowserWindow object or Buffer returned by getNativeWindowHandle. | ||
@@ -80,2 +87,3 @@ | ||
#### `cancelPreventFromShowDesktop(win)` | ||
- `win` Buffer|BrowserWindow - Target BrowserWindow object or Buffer returned by getNativeWindowHandle. | ||
@@ -86,2 +94,3 @@ | ||
#### `preventChangeZOrder(browserWindow)` | ||
- `win` BrowserWindow - Target BrowserWindow object. | ||
@@ -93,3 +102,12 @@ | ||
#### `cancelPreventChangeZOrder(browserWindow)` | ||
- `win` BrowserWindow - Target BrowserWindow object. | ||
Returns `function` - Cancel of `preventChangeZOrder` method. | ||
Cancel of `preventChangeZOrder` method. | ||
#### `moveToBottom(win)` | ||
- `win` Buffer|BrowserWindow - Target BrowserWindow object or Buffer returned by getNativeWindowHandle. | ||
@@ -99,4 +117,4 @@ | ||
## Guidelines for Using Webpack | ||
## Guidelines for Using Webpack | ||
Because `Webpack` bundles the source code, the following error occurs when `Webpack` is used for the main process: `Error: No native build was found ...` | ||
@@ -103,0 +121,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
33572
23
653
129
1