@dimensional-innovations/electron-background 2.0.4 → 2.0.7

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.
@@ -1,4 +1,4 @@
1
- import { InitContext, InitPlugin } from './init';
1
+ import { BrowserWindowInitContext, InitPlugin } from './init';
2
2
  /**
3
3
  * Starts the auto update process, checking for updates every 3 minutes
4
4
  * and automatically installing the update once one is found.
@@ -13,6 +13,6 @@ export declare class AutoUpdater implements InitPlugin {
13
13
  * @param enabled - Indicates if the plugin is enabled. Used to disable the plugin in development. Defaults to `app.isPackaged`.
14
14
  */
15
15
  constructor(enabled?: boolean);
16
- afterLoad(context: InitContext): Promise<void>;
16
+ afterLoad({ config, log }: BrowserWindowInitContext): Promise<void>;
17
17
  private startAutoUpdater;
18
18
  }
@@ -13,9 +13,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.AutoUpdater = void 0;
16
- const electron_updater_1 = require("electron-updater");
17
- const electron_log_1 = __importDefault(require("electron-log"));
18
16
  const electron_1 = require("electron");
17
+ const electron_log_1 = __importDefault(require("electron-log"));
18
+ const electron_updater_1 = require("electron-updater");
19
19
  /**
20
20
  * Starts the auto update process, checking for updates every 3 minutes
21
21
  * and automatically installing the update once one is found.
@@ -31,14 +31,14 @@ class AutoUpdater {
31
31
  constructor(enabled = electron_1.app.isPackaged) {
32
32
  this.enabled = enabled;
33
33
  }
34
- afterLoad(context) {
34
+ afterLoad({ config, log }) {
35
35
  return __awaiter(this, void 0, void 0, function* () {
36
- const { autoUpdaterChannel } = context.config;
36
+ const { autoUpdaterChannel } = config;
37
37
  if (this.enabled && autoUpdaterChannel) {
38
38
  this.startAutoUpdater(autoUpdaterChannel);
39
39
  }
40
40
  else if (this.enabled) {
41
- context.log.warn('autoUpdaterChannel was not set in the settings. AutoUpdater was not started.');
41
+ log.warn('autoUpdaterChannel was not set in the settings. AutoUpdater was not started.');
42
42
  }
43
43
  });
44
44
  }
@@ -1,5 +1,5 @@
1
1
  import { BrowserWindowConstructorOptions } from "electron";
2
- import { InitContext, InitPlugin } from "./init";
2
+ import { BrowserWindowInitContext, InitContext, InitPlugin } from "./init";
3
3
  /**
4
4
  * Applies default options to the browser window. If `appHeight`, `appWidth`, or `backgroundColor` are included in
5
5
  * app config, they will be added to the window options as well.
@@ -43,6 +43,6 @@ export declare class FullScreenBrowserWindow extends DefaultBrowserWindow {
43
43
  * @param enabled - Indicates if the plugin is enabled. Used to disable the plugin in development. Defaults to `app.isPackaged`.
44
44
  */
45
45
  constructor(options?: BrowserWindowConstructorOptions, enabled?: boolean);
46
- beforeLoad(context: InitContext): Promise<void>;
46
+ beforeLoad({ browserWindow }: BrowserWindowInitContext): Promise<void>;
47
47
  protected getDefaultWindowOptions(): BrowserWindowConstructorOptions;
48
48
  }
@@ -113,16 +113,11 @@ class FullScreenBrowserWindow extends DefaultBrowserWindow {
113
113
  super(options);
114
114
  this.enabled = enabled;
115
115
  }
116
- beforeLoad(context) {
116
+ beforeLoad({ browserWindow }) {
117
117
  return __awaiter(this, void 0, void 0, function* () {
118
118
  if (!this.enabled) {
119
119
  return;
120
120
  }
121
- const browserWindow = context.browserWindow;
122
- if (!browserWindow) {
123
- context.log.error('browserWindow is undefined');
124
- return;
125
- }
126
121
  const { screen } = yield Promise.resolve().then(() => __importStar(require('electron')));
127
122
  const resizeWindow = () => {
128
123
  browserWindow.setBounds(screen.getPrimaryDisplay().bounds);
@@ -1,5 +1,5 @@
1
1
  import { VUEJS3_DEVTOOLS } from 'electron-devtools-installer';
2
- import { InitContext, InitPlugin } from './init';
2
+ import { BrowserWindowInitContext, InitPlugin } from './init';
3
3
  export type Extension = string | typeof VUEJS3_DEVTOOLS;
4
4
  /**
5
5
  * Installs dev tools extensions and opens the devTools panel.
@@ -14,5 +14,5 @@ export declare class DevTools implements InitPlugin {
14
14
  * @param enabled - Indicates if the plugin is enabled. Used to disable the plugin when the app is packaged. Defaults to `!app.isPackaged`.
15
15
  */
16
16
  constructor(devTools: Array<Extension>, enabled?: boolean);
17
- beforeLoad(context: InitContext): Promise<void>;
17
+ beforeLoad({ browserWindow }: BrowserWindowInitContext): Promise<void>;
18
18
  }
package/dist/DevTools.js CHANGED
@@ -29,11 +29,12 @@ class DevTools {
29
29
  this.devTools = devTools;
30
30
  this.enabled = enabled;
31
31
  }
32
- beforeLoad(context) {
32
+ beforeLoad({ browserWindow }) {
33
33
  return __awaiter(this, void 0, void 0, function* () {
34
34
  if (!this.enabled) {
35
35
  return;
36
36
  }
37
+ browserWindow.on('ready-to-show', () => browserWindow.webContents.openDevTools());
37
38
  try {
38
39
  yield (0, electron_devtools_installer_1.default)(this.devTools);
39
40
  }
@@ -41,10 +42,6 @@ class DevTools {
41
42
  console.error(`Failed to install dev tools: ${this.devTools.join(',')}`);
42
43
  console.error(error);
43
44
  }
44
- if (context.browserWindow) {
45
- const browserWindow = context.browserWindow;
46
- browserWindow.on('ready-to-show', () => browserWindow.webContents.openDevTools());
47
- }
48
45
  });
49
46
  }
50
47
  }
package/dist/init.d.ts CHANGED
@@ -16,11 +16,6 @@ export declare class InitContext {
16
16
  * `beforeLoad` methods to change the created BrowserWindow.
17
17
  */
18
18
  browserWindowOptions: BrowserWindowConstructorOptions;
19
- /**
20
- * The main browser window that the app is loaded into. This is available in the context
21
- * in the `afterLoad` method.
22
- */
23
- browserWindow: BrowserWindow | null;
24
19
  /**
25
20
  * The log instance. This should be used over `console` in plugin implementations.
26
21
  */
@@ -39,16 +34,26 @@ export declare class InitContext {
39
34
  * `beforeLoad` methods to change the created BrowserWindow.
40
35
  */
41
36
  browserWindowOptions: BrowserWindowConstructorOptions,
42
- /**
43
- * The main browser window that the app is loaded into. This is available in the context
44
- * in the `afterLoad` method.
45
- */
46
- browserWindow: BrowserWindow | null,
47
37
  /**
48
38
  * The log instance. This should be used over `console` in plugin implementations.
49
39
  */
50
40
  log: Pick<Console, 'error' | 'warn' | 'info' | 'debug'>);
41
+ /**
42
+ * The main browser window that the app is loaded into. This is available in the context
43
+ * in the `beforeLoad` and `afterLoad` method.
44
+ */
45
+ browserWindow?: BrowserWindow;
51
46
  }
47
+ /**
48
+ * Represents the InitContext before the BrowserWindow has been set. Used in the
49
+ * "beforeReady" and "afterReady" methods.
50
+ */
51
+ export type NonBrowserWindowInitContext = Omit<InitContext, 'browserWindow'>;
52
+ /**
53
+ * Represents the InitContext after the BrowserWindow has been set. Used in the
54
+ * "beforeLoad" and "afterLoad" methods.
55
+ */
56
+ export type BrowserWindowInitContext = Omit<InitContext, 'browserWindow'> & Required<Pick<InitContext, 'browserWindow'>>;
52
57
  /**
53
58
  * A plugin is used to execute logic at various stages during the init process.
54
59
  *
@@ -61,33 +66,37 @@ export interface InitPlugin {
61
66
  *
62
67
  * @param context - The current InitContext instance.
63
68
  */
64
- beforeReady?(context: InitContext): Promise<void>;
69
+ beforeReady?(context: NonBrowserWindowInitContext): Promise<void>;
65
70
  /**
66
71
  * afterReady is executed after the `app.whenReady()` promise resolves, but before the
67
72
  * BrowserWindow is created.
68
73
  *
69
74
  * @param context - The current InitContext instance.
70
75
  */
71
- afterReady?(context: InitContext): Promise<void>;
76
+ afterReady?(context: NonBrowserWindowInitContext): Promise<void>;
72
77
  /**
73
78
  * beforeLoad is executed after the browserWindow is created, but before the application
74
79
  * has been loaded into the window.
75
80
  *
76
81
  * @param context - The current InitContext instance.
77
82
  */
78
- beforeLoad?(context: InitContext): Promise<void>;
83
+ beforeLoad?(context: BrowserWindowInitContext): Promise<void>;
79
84
  /**
80
85
  * afterLoad is executed after the application has been loaded into the browserWindow.
81
86
  *
82
87
  * @param context - The current InitContext instance.
83
88
  */
84
- afterLoad?(context: InitContext): Promise<void>;
89
+ afterLoad?(context: BrowserWindowInitContext): Promise<void>;
85
90
  }
86
91
  export interface InitOptions {
87
92
  /**
88
93
  * The url to load once the the app has been created.
89
94
  */
90
95
  appUrl: string;
96
+ /**
97
+ * The default browser window options
98
+ */
99
+ browserWindowOptions?: BrowserWindowConstructorOptions;
91
100
  /**
92
101
  * The default application settings.
93
102
  */
@@ -103,4 +112,4 @@ export interface InitOptions {
103
112
  * @param options - Options used to define how the application is initialized.
104
113
  * @returns - The final state of the init context, including the created browser window for additional setup.
105
114
  */
106
- export declare function init({ appUrl, config, plugins, }: InitOptions): Promise<InitContext>;
115
+ export declare function init({ appUrl, browserWindowOptions, config, plugins, }: InitOptions): Promise<InitContext>;
package/dist/init.js CHANGED
@@ -33,11 +33,6 @@ class InitContext {
33
33
  * `beforeLoad` methods to change the created BrowserWindow.
34
34
  */
35
35
  browserWindowOptions,
36
- /**
37
- * The main browser window that the app is loaded into. This is available in the context
38
- * in the `afterLoad` method.
39
- */
40
- browserWindow,
41
36
  /**
42
37
  * The log instance. This should be used over `console` in plugin implementations.
43
38
  */
@@ -45,7 +40,6 @@ class InitContext {
45
40
  this.appUrl = appUrl;
46
41
  this.config = config;
47
42
  this.browserWindowOptions = browserWindowOptions;
48
- this.browserWindow = browserWindow;
49
43
  this.log = log;
50
44
  }
51
45
  }
@@ -56,7 +50,7 @@ exports.InitContext = InitContext;
56
50
  * @param options - Options used to define how the application is initialized.
57
51
  * @returns - The final state of the init context, including the created browser window for additional setup.
58
52
  */
59
- function init({ appUrl, config = {}, plugins = [], }) {
53
+ function init({ appUrl, browserWindowOptions = { height: 1920, width: 1080, backgroundColor: '#000' }, config = {}, plugins = [], }) {
60
54
  return __awaiter(this, void 0, void 0, function* () {
61
55
  process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true';
62
56
  electron_1.app.on('window-all-closed', electron_1.app.quit);
@@ -65,7 +59,7 @@ function init({ appUrl, config = {}, plugins = [], }) {
65
59
  electron_1.app.quit();
66
60
  });
67
61
  process.on('SIGTERM', electron_1.app.quit);
68
- const context = new InitContext(appUrl, config, { height: 1920, width: 1080, backgroundColor: '#000' }, null, electron_log_1.default);
62
+ const context = new InitContext(appUrl, config, browserWindowOptions, electron_log_1.default);
69
63
  for (const plugin of plugins) {
70
64
  if (plugin.beforeReady) {
71
65
  yield plugin.beforeReady(context);
@@ -78,7 +72,6 @@ function init({ appUrl, config = {}, plugins = [], }) {
78
72
  }
79
73
  }
80
74
  context.browserWindow = new electron_1.BrowserWindow(context.browserWindowOptions);
81
- context.browserWindow.on('closed', () => context.browserWindow = null);
82
75
  for (const plugin of plugins) {
83
76
  if (plugin.beforeLoad) {
84
77
  yield plugin.beforeLoad(context);
@@ -87,9 +80,10 @@ function init({ appUrl, config = {}, plugins = [], }) {
87
80
  yield context.browserWindow.loadURL(context.appUrl);
88
81
  for (const plugin of plugins) {
89
82
  if (plugin.afterLoad) {
90
- plugin.afterLoad(context);
83
+ yield plugin.afterLoad(context);
91
84
  }
92
85
  }
86
+ context.browserWindow.on('closed', () => context.browserWindow = undefined);
93
87
  return context;
94
88
  });
95
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dimensional-innovations/electron-background",
3
- "version": "2.0.4",
3
+ "version": "2.0.7",
4
4
  "description": "the background script for electron apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,11 +11,12 @@
11
11
  "build": "tsc",
12
12
  "lint": "eslint ./src/**/*",
13
13
  "lint:fix": "eslint ./src/**/* --fix",
14
- "generate:docs": "jsdoc2md ./dist/* > API.md"
14
+ "generate:docs": "jsdoc2md ./dist/* > API.md",
15
+ "prepublish": "tsc"
15
16
  },
16
17
  "repository": {
17
18
  "type": "git",
18
- "url": "git+https://gitlab.com/dimensional-innovations/electron-background.git"
19
+ "url": "git+https://github.com/ditech/electron-background.git"
19
20
  },
20
21
  "keywords": [
21
22
  "vue",
@@ -25,9 +26,9 @@
25
26
  "author": "Edgar Esparza",
26
27
  "license": "ISC",
27
28
  "bugs": {
28
- "url": "https://gitlab.com/dimensional-innovations/electron-background/issues"
29
+ "url": "https://github.com/ditech/electron-background/issues"
29
30
  },
30
- "homepage": "https://gitlab.com/dimensional-innovations/electron-background#readme",
31
+ "homepage": "https://github.com/ditech/electron-background",
31
32
  "dependencies": {
32
33
  "axios": "^1.6.7",
33
34
  "electron-devtools-installer": "^3.1.1",