@dimensional-innovations/electron-background 2.3.1 → 3.0.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.
Files changed (36) hide show
  1. package/README.md +340 -49
  2. package/dist/InitContext.d.ts +40 -0
  3. package/dist/InitContext.js +23 -0
  4. package/dist/InitPlugin.d.ts +39 -0
  5. package/dist/InitPlugin.js +2 -0
  6. package/dist/index.d.ts +12 -8
  7. package/dist/index.js +12 -8
  8. package/dist/init.d.ts +10 -92
  9. package/dist/init.js +46 -59
  10. package/dist/{AutoUpdater.d.ts → plugins/AutoUpdater.d.ts} +8 -5
  11. package/dist/{AutoUpdater.js → plugins/AutoUpdater.js} +5 -5
  12. package/dist/{DevTools.d.ts → plugins/DevTools.d.ts} +4 -3
  13. package/dist/{NodeHeartbeat.d.ts → plugins/NodeHeartbeat.d.ts} +8 -5
  14. package/dist/{NodeHeartbeat.js → plugins/NodeHeartbeat.js} +3 -3
  15. package/dist/{PrivilegedSchemes.d.ts → plugins/PrivilegedSchemes.d.ts} +2 -2
  16. package/dist/plugins/PrivilegedSchemes.js +27 -0
  17. package/dist/{SingleInstance.d.ts → plugins/SingleInstance.d.ts} +3 -2
  18. package/dist/{SingleInstance.js → plugins/SingleInstance.js} +3 -4
  19. package/dist/plugins/StaticFileDir.d.ts +16 -0
  20. package/dist/{StaticFileDir.js → plugins/StaticFileDir.js} +0 -1
  21. package/dist/{TouchEvents.d.ts → plugins/TouchEvents.d.ts} +2 -2
  22. package/dist/plugins/TouchEvents.js +14 -0
  23. package/dist/windows/AppBrowserWindow.d.ts +28 -0
  24. package/dist/{TouchEvents.js → windows/AppBrowserWindow.js} +16 -6
  25. package/dist/windows/FullScreenBrowserWindow.d.ts +17 -0
  26. package/dist/windows/FullScreenBrowserWindow.js +55 -0
  27. package/dist/windows/KioskBrowserWindow.d.ts +15 -0
  28. package/dist/windows/KioskBrowserWindow.js +32 -0
  29. package/dist/windows/util.d.ts +11 -0
  30. package/dist/windows/util.js +25 -0
  31. package/package.json +1 -1
  32. package/dist/BrowserWindow.d.ts +0 -47
  33. package/dist/BrowserWindow.js +0 -139
  34. package/dist/PrivilegedSchemes.js +0 -37
  35. package/dist/StaticFileDir.d.ts +0 -26
  36. /package/dist/{DevTools.js → plugins/DevTools.js} +0 -0
@@ -0,0 +1,15 @@
1
+ import { AppBrowserWindow, AppBrowserWindowConstructorOptions } from "./AppBrowserWindow";
2
+ export interface KioskBrowserWindowConstructorOptions extends AppBrowserWindowConstructorOptions {
3
+ /**
4
+ * The screen the window should occupy. Use 'primary' for the primary display,
5
+ * 'secondary' for the first non-primary display, or a number for the display
6
+ * at that index in the list returned by screen.getAllDisplays(). Defaults to 'primary'.
7
+ */
8
+ screen?: 'primary' | 'secondary' | number;
9
+ }
10
+ /**
11
+ * Enables kiosk mode in the BrowserWindow when the application is packaged.
12
+ */
13
+ export declare class KioskBrowserWindow extends AppBrowserWindow {
14
+ constructor({ screen: target, ...options }: KioskBrowserWindowConstructorOptions, enabled?: boolean);
15
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.KioskBrowserWindow = void 0;
18
+ const electron_1 = require("electron");
19
+ const lodash_merge_1 = __importDefault(require("lodash.merge"));
20
+ const AppBrowserWindow_1 = require("./AppBrowserWindow");
21
+ const util_1 = require("./util");
22
+ /**
23
+ * Enables kiosk mode in the BrowserWindow when the application is packaged.
24
+ */
25
+ class KioskBrowserWindow extends AppBrowserWindow_1.AppBrowserWindow {
26
+ constructor(_a, enabled) {
27
+ var { screen: target = 'primary' } = _a, options = __rest(_a, ["screen"]);
28
+ if (enabled === void 0) { enabled = electron_1.app.isPackaged; }
29
+ super((0, lodash_merge_1.default)(enabled ? Object.assign({ acceptFirstMouse: true, alwaysOnTop: true, autoHideMenuBar: true, fullscreen: true, kiosk: true, minimizable: false, movable: false }, (0, util_1.getTargetDisplay)(target).bounds) : {}, options));
30
+ }
31
+ }
32
+ exports.KioskBrowserWindow = KioskBrowserWindow;
@@ -0,0 +1,11 @@
1
+ import { Display } from "electron";
2
+ /**
3
+ * Looks up the target display using the 'primary' or 'secondary' notions.
4
+ *
5
+ * @param target - The display to look up. The following values are supported:
6
+ * - 'primary': Get the primary display, as defined by the os.
7
+ * - 'secondary': Get the first display, not set as the primary display.
8
+ * - number: Returns the display at the specified index, or the primary display if not found.
9
+ * @returns - The specified display.
10
+ */
11
+ export declare function getTargetDisplay(target: 'primary' | 'secondary' | number): Display;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTargetDisplay = getTargetDisplay;
4
+ const electron_1 = require("electron");
5
+ /**
6
+ * Looks up the target display using the 'primary' or 'secondary' notions.
7
+ *
8
+ * @param target - The display to look up. The following values are supported:
9
+ * - 'primary': Get the primary display, as defined by the os.
10
+ * - 'secondary': Get the first display, not set as the primary display.
11
+ * - number: Returns the display at the specified index, or the primary display if not found.
12
+ * @returns - The specified display.
13
+ */
14
+ function getTargetDisplay(target) {
15
+ var _a, _b;
16
+ const displays = electron_1.screen.getAllDisplays();
17
+ if (target === 'primary') {
18
+ return electron_1.screen.getPrimaryDisplay();
19
+ }
20
+ if (target === 'secondary') {
21
+ const primaryId = electron_1.screen.getPrimaryDisplay().id;
22
+ return (_a = displays.find(d => d.id !== primaryId)) !== null && _a !== void 0 ? _a : electron_1.screen.getPrimaryDisplay();
23
+ }
24
+ return (_b = displays[target]) !== null && _b !== void 0 ? _b : electron_1.screen.getPrimaryDisplay();
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dimensional-innovations/electron-background",
3
- "version": "2.3.1",
3
+ "version": "3.0.0",
4
4
  "description": "the background script for electron apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,47 +0,0 @@
1
- import { BrowserWindowConstructorOptions } from "electron";
2
- import { BrowserWindowInitContext, InitContext, InitPlugin } from "./init";
3
- /**
4
- * Applies default options to the browser window. If `appHeight`, `appWidth`, or `backgroundColor` are included in
5
- * app config, they will be added to the window options as well.
6
- */
7
- export declare class DefaultBrowserWindow implements InitPlugin {
8
- protected readonly options: BrowserWindowConstructorOptions;
9
- /**
10
- * @constructor
11
- *
12
- * @param options - Additional options to apply to the browser window.
13
- */
14
- constructor(options?: BrowserWindowConstructorOptions);
15
- afterReady(context: InitContext): Promise<void>;
16
- protected getDefaultWindowOptions(): BrowserWindowConstructorOptions;
17
- }
18
- /**
19
- * Enables kiosk mode in the BrowserWindow when the application is packaged.
20
- */
21
- export declare class KioskBrowserWindow extends DefaultBrowserWindow {
22
- private readonly enabled;
23
- /**
24
- * @constructor
25
- *
26
- * @param options - Additional options to apply to the BrowserWindow.
27
- * @param enableKioskMode - Indicates if the plugin is enabled. Used to disabled kiosk mode in development. Defaults to `app.isPackaged`
28
- */
29
- constructor(options?: BrowserWindowConstructorOptions, enabled?: boolean);
30
- protected getDefaultWindowOptions(): BrowserWindowConstructorOptions;
31
- }
32
- /**
33
- * Ensures the browser window will always be fullscreen. Generally, KioskBrowserWindow is preferred
34
- * over this plugin, but there are times when app cannot be in kiosk mode.
35
- */
36
- export declare class FullScreenBrowserWindow extends DefaultBrowserWindow {
37
- private readonly enabled;
38
- /**
39
- * @constructor
40
- *
41
- * @param options - Additional options to apply to the BrowserWindow.
42
- * @param enabled - Indicates if the plugin is enabled. Used to disable the plugin in development. Defaults to `app.isPackaged`.
43
- */
44
- constructor(options?: BrowserWindowConstructorOptions, enabled?: boolean);
45
- beforeLoad({ browserWindow }: BrowserWindowInitContext): Promise<void>;
46
- protected getDefaultWindowOptions(): BrowserWindowConstructorOptions;
47
- }
@@ -1,139 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- var __importDefault = (this && this.__importDefault) || function (mod) {
45
- return (mod && mod.__esModule) ? mod : { "default": mod };
46
- };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.FullScreenBrowserWindow = exports.KioskBrowserWindow = exports.DefaultBrowserWindow = void 0;
49
- const electron_1 = require("electron");
50
- const lodash_merge_1 = __importDefault(require("lodash.merge"));
51
- /**
52
- * Applies default options to the browser window. If `appHeight`, `appWidth`, or `backgroundColor` are included in
53
- * app config, they will be added to the window options as well.
54
- */
55
- class DefaultBrowserWindow {
56
- /**
57
- * @constructor
58
- *
59
- * @param options - Additional options to apply to the browser window.
60
- */
61
- constructor(options = {}) {
62
- this.options = options;
63
- }
64
- afterReady(context) {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- context.browserWindowOptions = (0, lodash_merge_1.default)({}, this.getDefaultWindowOptions(), context.browserWindowOptions, this.options, { closable: true });
67
- });
68
- }
69
- getDefaultWindowOptions() {
70
- return {
71
- webPreferences: {
72
- nodeIntegration: true,
73
- contextIsolation: false,
74
- webSecurity: false
75
- }
76
- };
77
- }
78
- }
79
- exports.DefaultBrowserWindow = DefaultBrowserWindow;
80
- /**
81
- * Enables kiosk mode in the BrowserWindow when the application is packaged.
82
- */
83
- class KioskBrowserWindow extends DefaultBrowserWindow {
84
- /**
85
- * @constructor
86
- *
87
- * @param options - Additional options to apply to the BrowserWindow.
88
- * @param enableKioskMode - Indicates if the plugin is enabled. Used to disabled kiosk mode in development. Defaults to `app.isPackaged`
89
- */
90
- constructor(options = {}, enabled = electron_1.app.isPackaged) {
91
- super(options);
92
- this.enabled = enabled;
93
- }
94
- getDefaultWindowOptions() {
95
- if (!this.enabled) {
96
- return super.getDefaultWindowOptions();
97
- }
98
- return Object.assign(Object.assign({}, super.getDefaultWindowOptions()), { acceptFirstMouse: true, alwaysOnTop: true, autoHideMenuBar: true, fullscreen: true, kiosk: true, minimizable: false, movable: false, x: 0, y: 0 });
99
- }
100
- }
101
- exports.KioskBrowserWindow = KioskBrowserWindow;
102
- /**
103
- * Ensures the browser window will always be fullscreen. Generally, KioskBrowserWindow is preferred
104
- * over this plugin, but there are times when app cannot be in kiosk mode.
105
- */
106
- class FullScreenBrowserWindow extends DefaultBrowserWindow {
107
- /**
108
- * @constructor
109
- *
110
- * @param options - Additional options to apply to the BrowserWindow.
111
- * @param enabled - Indicates if the plugin is enabled. Used to disable the plugin in development. Defaults to `app.isPackaged`.
112
- */
113
- constructor(options = {}, enabled = electron_1.app.isPackaged) {
114
- super(options);
115
- this.enabled = enabled;
116
- }
117
- beforeLoad(_a) {
118
- return __awaiter(this, arguments, void 0, function* ({ browserWindow }) {
119
- if (!this.enabled) {
120
- return;
121
- }
122
- const { screen } = yield Promise.resolve().then(() => __importStar(require('electron')));
123
- const resizeWindow = () => {
124
- browserWindow.setBounds(screen.getPrimaryDisplay().bounds);
125
- };
126
- resizeWindow();
127
- screen.on('display-added', resizeWindow);
128
- screen.on('display-metrics-changed', resizeWindow);
129
- screen.on('display-removed', resizeWindow);
130
- });
131
- }
132
- getDefaultWindowOptions() {
133
- if (!this.enabled) {
134
- return super.getDefaultWindowOptions();
135
- }
136
- return Object.assign(Object.assign({}, super.getDefaultWindowOptions()), { alwaysOnTop: true, resizable: false, movable: false, frame: false });
137
- }
138
- }
139
- exports.FullScreenBrowserWindow = FullScreenBrowserWindow;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.PrivilegedSchemes = void 0;
13
- const electron_1 = require("electron");
14
- /**
15
- * Registers schemes as privileged.
16
- */
17
- class PrivilegedSchemes {
18
- /**
19
- * @constructor
20
- *
21
- * @param schemes - The schemes to register as privileged.
22
- */
23
- constructor(schemes) {
24
- this.schemes = schemes;
25
- }
26
- beforeReady() {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const customSchemes = this.schemes
29
- .map((scheme) => ({
30
- scheme,
31
- privileges: { secure: true, standard: true, supportFetchAPI: true },
32
- }));
33
- electron_1.protocol.registerSchemesAsPrivileged(customSchemes);
34
- });
35
- }
36
- }
37
- exports.PrivilegedSchemes = PrivilegedSchemes;
@@ -1,26 +0,0 @@
1
- import { InitPlugin } from './init';
2
- /**
3
- * Registers a custom scheme to serve static files.
4
- */
5
- export declare class StaticFileDir implements InitPlugin {
6
- private readonly scheme;
7
- private readonly dir;
8
- /**
9
- * @constructor
10
- *
11
- * @param scheme - The scheme to serve the files from.
12
- * @param dir - The directory where the static files are located.
13
- */
14
- constructor(scheme: string, dir: string);
15
- afterReady(): Promise<void>;
16
- }
17
- /**
18
- * Wrapper around `protocol.registerFileProtocol` that serves files from the given source directory.
19
- * The handler will convert any url with the custom scheme to a file path in the source directory in
20
- * order to find the file to serve. For example, with "media" passed in for scheme and `/public` passed
21
- * in for sourceDirectory "media://videos/demo.mp4" would resolve to "/public/media/videos/demo.mp4".
22
- *
23
- * @param scheme - The scheme to register.
24
- * @param sourceDirectory - The directory where files are served from.
25
- */
26
- export declare function createFileProtocol(scheme: string, sourceDirectory: string): void;
File without changes