electron-suites
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "electron-suites", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A collection of useful electron packages for vue-front-end-boilerplate.", | ||
@@ -25,2 +25,3 @@ "main": "dist/esuites.js", | ||
"dependencies": { | ||
"asar": "^2.0.3", | ||
"electron": "^5.0.6", | ||
@@ -42,4 +43,10 @@ "electron-debug": "^3.0.1", | ||
"peerDependencies": { | ||
"electron": "^5.0.6" | ||
"asar": "^2.0.3", | ||
"electron": "^5.0.6", | ||
"electron-debug": "^3.0.1", | ||
"electron-devtools-installer": "^2.2.4", | ||
"electron-store": "^5.0.0", | ||
"electron-updater": "^4.2.0", | ||
"log4js": "^6.1.0" | ||
} | ||
} |
import { app, ipcMain } from 'electron' | ||
import { initializeMainWindows } from '../window' | ||
import { initializeUpdater } from './updater' | ||
import { handleEvent } from '../util/shared' | ||
@@ -7,3 +8,3 @@ import { installDevTool, registerEventHandlers, onAllClosed } from './handlers' | ||
export const initializeApp = ({ events, shortcuts, devTool } = {}) => { | ||
export const initializeApp = ({ events, shortcuts, devTool } = {}, updater) => { | ||
// regist events with default handler and customer handlers | ||
@@ -16,2 +17,3 @@ app.on('ready', launchInfo => { | ||
handleEvent(events, 'ready', app, launchInfo) | ||
initializeUpdater(updater) | ||
}) | ||
@@ -18,0 +20,0 @@ app.on('activate', (event, hasVisibleWindows) => { |
@@ -5,3 +5,3 @@ import { setupRuntimeEnv } from './setup' | ||
import { initializeIpc } from './ipc' | ||
import { initializeUpdater } from './updater' | ||
export { windows } from './window' | ||
@@ -14,5 +14,4 @@ | ||
initializeStore(store) | ||
initializeApp(app) | ||
initializeApp(app, updater) | ||
initializeIpc(ipcEvents) | ||
initializeUpdater(updater) | ||
} |
@@ -5,3 +5,3 @@ import log4js from 'log4js' | ||
import { handleEvent } from '../util/shared' | ||
import { createChildWindow } from '../window' | ||
import { createChildWindow, switchNamespace } from '../window' | ||
@@ -28,2 +28,7 @@ const logger = log4js.getLogger('ipc') | ||
ipcMain.on('switch-namespace', (evnet, namespace) => { | ||
logger.debug('Trying to switch namespace from', global.__namespace, 'to', namespace) | ||
switchNamespace(namespace) | ||
}) | ||
// Register customer event handlers | ||
@@ -30,0 +35,0 @@ Object.keys(events).forEach(name => { |
@@ -0,1 +1,2 @@ | ||
import path from 'path' | ||
import log4js from 'log4js' | ||
@@ -51,2 +52,11 @@ | ||
global.__port = config.port // port | ||
global.__namespace = config.namespace // namespace | ||
global.__resources = ['app'] // available asar resources | ||
// folder for asar resources | ||
global.__root = global.__dev | ||
? path.posix.normalize(config.cache) | ||
: path.posix.normalize(config.root.split(`${config.namespace}.asar`)[0]) | ||
// baseUrl | ||
@@ -57,5 +67,2 @@ global.__baseUrl = global.__dev | ||
// namespace | ||
global.__namespace = config.namespace | ||
// resource and devtools | ||
@@ -62,0 +69,0 @@ if (global.__dev) { |
@@ -8,3 +8,4 @@ import Store from 'electron-store' | ||
main: { width: 340, height: 550 } | ||
} | ||
}, | ||
resources: {} | ||
} | ||
@@ -11,0 +12,0 @@ } |
@@ -26,16 +26,1 @@ import log4js from 'log4js' | ||
} | ||
/** | ||
* Send IPC message to renderer process. | ||
* @param {BrowserWindow} window instance of Electron BrowserWindow. | ||
* @param {String} topic message topic. | ||
* @param {String | Object} message message content. | ||
*/ | ||
export const sendIpcMessage = (window, topic, message) => { | ||
if (!window || !topic || window.webContents) { | ||
logger.warn('Window, webContents of window or topic for sendIpcMessage cannot be empty.') | ||
return | ||
} | ||
webContents.send(topic, message) | ||
} |
@@ -12,1 +12,16 @@ /** | ||
} | ||
/** | ||
* Switch current namespace between different asar resources. | ||
* @param {String} namespace identifier of the namespace about to switch to. | ||
*/ | ||
export const switchBaseUrl = namespace => { | ||
if (global.__dev) { | ||
global.__baseUrl = namespace === 'app' | ||
? `http://localhost:${global.__port}` | ||
: `http://localhost:${global.__port}/${namespace}/dist/index.html` | ||
} else { | ||
global.__baseUrl = global.__baseUrl.replace(`${global.__namespace}.asar`, `${namespace}.asar`) | ||
} | ||
global.__namespace = namespace | ||
} |
@@ -0,6 +1,8 @@ | ||
import log4js from 'log4js' | ||
import Windows from './windows' | ||
import { resolveUrl } from '../util/url' | ||
import { resolveUrl, switchBaseUrl } from '../util/url' | ||
/** @type {Windows} */ | ||
export const windows = Windows.getInstance() | ||
const logger = log4js.getLogger('window') | ||
@@ -27,2 +29,48 @@ /** | ||
/** | ||
* Send IPC message to renderer process. | ||
* @param {String} topic message topic. | ||
* @param {String | Object} message message content. | ||
* @param {String} identifier name or url of the window which will send ipc message. Default to 'main' | ||
*/ | ||
export const sendRendererMessage = (topic, message, identifier = 'main') => { | ||
logger.debug('Sending message to window with identifier', identifier, 'and topic', topic) | ||
const window = windows.collection[identifier] || windows.findWindowByUrl(identifier) | ||
if (!window || !topic || !window.webContents) { | ||
logger.warn('Window, webContents of window or topic for sendRendererMessage cannot be empty.') | ||
return | ||
} | ||
window.webContents.send(topic, message) | ||
} | ||
/** | ||
* Switch asar resources with the given namespace string, and close all child windows. | ||
* @param {String} namespace the namespace about to switch to. | ||
*/ | ||
export const switchNamespace = namespace => { | ||
if (!global.__resources.includes(namespace)) { | ||
logger.error(`Namespace ${namespace} is not available.`) | ||
return | ||
} | ||
for (const name in windows.collection) { | ||
const instance = windows.collection[name] | ||
if (instance && instance !== windows.main && !instance.isDestroyed()) { | ||
instance.close() | ||
} | ||
} | ||
switchBaseUrl(namespace) | ||
logger.info(`Reload main window with ${global.__baseUrl}`) | ||
windows.main.loadURL(global.__baseUrl) | ||
} | ||
/** | ||
* Reload a specified window with the given identifer | ||
* @param {*} identifier name or url of the window which will send ipc message. Default to 'main' | ||
*/ | ||
export const reloadWindow = (identifier = 'main') => { | ||
const window = windows.collection[identifier] || windows.findWindowByUrl(identifier) | ||
logger.info(`Reload window ${window._name} with url ${window._url}`) | ||
window.reload() | ||
} | ||
/** | ||
* Restore all window instances | ||
@@ -29,0 +77,0 @@ */ |
@@ -49,4 +49,4 @@ import { BrowserWindow } from 'electron' | ||
/** | ||
* Find the window instance with the given | ||
* @param {*} url the url that window loads | ||
* Find the window instance with the given url | ||
* @param {String} url the url that window loads | ||
* @returns {BrowserWindow} window instance | ||
@@ -72,3 +72,3 @@ */ | ||
logger.debug('Creating new BrowserWindow with options:', options) | ||
const { name, url, sizeType, width, height, events, x, y } = options | ||
const { name, url, category, width, height, events, x, y } = options | ||
/** @type {BrowserWindow} */ | ||
@@ -90,4 +90,4 @@ const existWindow = this.collection[name] | ||
window._url = url | ||
window._category = category | ||
this.urlCache[url] = name | ||
sizeType && (window._sizeType = sizeType) | ||
window.loadURL(url) | ||
@@ -143,3 +143,2 @@ this.registerEventHandlers(window, events) | ||
const instance = this.collection[name] | ||
console.log(name) | ||
if (instance && !instance.isDestroyed()) { | ||
@@ -146,0 +145,0 @@ instance.close() |
@@ -0,1 +1,3 @@ | ||
const { dependencies } = require('./package.json') | ||
module.exports = { | ||
@@ -12,2 +14,5 @@ mode: process.env.NODE_ENV, | ||
}, | ||
externals: [ | ||
...Object.keys(dependencies) | ||
], | ||
target: 'electron-main', | ||
@@ -14,0 +19,0 @@ module: { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 17 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
3
2
325857
14
816
+ Addedasar@^2.0.3
+ Added@types/glob@7.2.0(transitive)
+ Added@types/minimatch@5.1.2(transitive)
+ Added@types/node@22.13.8(transitive)
+ Addedasar@2.1.0(transitive)
+ Addedbluebird@3.7.2(transitive)
+ Addedchromium-pickle-js@0.2.0(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedcuint@0.2.2(transitive)
+ Addedtmp@0.1.0(transitive)
+ Addedtmp-promise@1.1.0(transitive)
+ Addedundici-types@6.20.0(transitive)