mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-15 13:18:40 -09:00
Show plugin (name and version) loaded (#1826)
* Print plugin name and version in devtools * Add plugins informations in About dialog
This commit is contained in:
parent
5ec705000f
commit
db35faa431
6 changed files with 61 additions and 18 deletions
|
|
@ -405,8 +405,9 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
|
||||||
const menu = plugins.decorateMenu(
|
const menu = plugins.decorateMenu(
|
||||||
AppMenu(createWindow, () => {
|
AppMenu(createWindow, () => {
|
||||||
plugins.updatePlugins({force: true});
|
plugins.updatePlugins({force: true});
|
||||||
})
|
},
|
||||||
);
|
plugins.getLoadedPluginVersions
|
||||||
|
));
|
||||||
|
|
||||||
// If we're on Mac make a Dock Menu
|
// If we're on Mac make a Dock Menu
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
|
const {app, dialog} = require('electron');
|
||||||
|
|
||||||
const {getKeymaps} = require('../config');
|
const {getKeymaps} = require('../config');
|
||||||
|
const {icon} = require('../config/paths');
|
||||||
|
|
||||||
// menus
|
// menus
|
||||||
const viewMenu = require('./menus/view');
|
const viewMenu = require('./menus/view');
|
||||||
|
|
@ -9,16 +12,32 @@ const windowMenu = require('./menus/window');
|
||||||
const helpMenu = require('./menus/help');
|
const helpMenu = require('./menus/help');
|
||||||
const darwinMenu = require('./menus/darwin');
|
const darwinMenu = require('./menus/darwin');
|
||||||
|
|
||||||
module.exports = (createWindow, updatePlugins) => {
|
const appName = app.getName();
|
||||||
|
const appVersion = app.getVersion();
|
||||||
|
|
||||||
|
module.exports = (createWindow, updatePlugins, getLoadedPluginVersions) => {
|
||||||
const commands = getKeymaps().commands;
|
const commands = getKeymaps().commands;
|
||||||
|
const showAbout = () => {
|
||||||
|
const loadedPlugins = getLoadedPluginVersions();
|
||||||
|
const pluginList = loadedPlugins.length === 0 ?
|
||||||
|
'none' :
|
||||||
|
loadedPlugins.map(plugin => `\n ${plugin.name} (${plugin.version})`);
|
||||||
|
dialog.showMessageBox({
|
||||||
|
title: `About ${appName}`,
|
||||||
|
message: `${appName} ${appVersion}`,
|
||||||
|
detail: `Plugins: ${pluginList}\n\nCreated by Guillermo Rauch\nCopyright © 2017 Zeit, Inc.`,
|
||||||
|
buttons: [],
|
||||||
|
icon
|
||||||
|
});
|
||||||
|
};
|
||||||
const menu = [
|
const menu = [
|
||||||
...(process.platform === 'darwin' ? [darwinMenu(commands)] : []),
|
...(process.platform === 'darwin' ? [darwinMenu(commands, showAbout)] : []),
|
||||||
shellMenu(commands, createWindow),
|
shellMenu(commands, createWindow),
|
||||||
editMenu(commands),
|
editMenu(commands),
|
||||||
viewMenu(commands),
|
viewMenu(commands),
|
||||||
pluginsMenu(commands, updatePlugins),
|
pluginsMenu(commands, updatePlugins),
|
||||||
windowMenu(commands),
|
windowMenu(commands),
|
||||||
helpMenu(commands)
|
helpMenu(commands, showAbout)
|
||||||
];
|
];
|
||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,15 @@
|
||||||
const {app} = require('electron');
|
const {app} = require('electron');
|
||||||
const {openConfig} = require('../../config');
|
const {openConfig} = require('../../config');
|
||||||
|
|
||||||
module.exports = function (commands) {
|
module.exports = function (commands, showAbout) {
|
||||||
return {
|
return {
|
||||||
label: `${app.getName()}`,
|
label: `${app.getName()}`,
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
role: 'about'
|
label: 'About Hyper',
|
||||||
|
click() {
|
||||||
|
showAbout();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'separator'
|
type: 'separator'
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const {app, shell, dialog} = require('electron');
|
const {app, shell} = require('electron');
|
||||||
const {icon} = require('../../config/paths');
|
|
||||||
|
|
||||||
module.exports = function () {
|
module.exports = function (commands, showAbout) {
|
||||||
const submenu = [
|
const submenu = [
|
||||||
{
|
{
|
||||||
label: `${app.getName()} Website`,
|
label: `${app.getName()} Website`,
|
||||||
|
|
@ -31,13 +30,7 @@ module.exports = function () {
|
||||||
{
|
{
|
||||||
role: 'about',
|
role: 'about',
|
||||||
click() {
|
click() {
|
||||||
dialog.showMessageBox({
|
showAbout();
|
||||||
title: `About ${app.getName()}`,
|
|
||||||
message: `${app.getName()} ${app.getVersion()}`,
|
|
||||||
detail: 'Created by Guillermo Rauch',
|
|
||||||
icon,
|
|
||||||
buttons: []
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -161,6 +161,10 @@ function clearCache() {
|
||||||
|
|
||||||
exports.updatePlugins = updatePlugins;
|
exports.updatePlugins = updatePlugins;
|
||||||
|
|
||||||
|
exports.getLoadedPluginVersions = function () {
|
||||||
|
return modules.map(mod => ({name: mod._name, version: mod._version}));
|
||||||
|
};
|
||||||
|
|
||||||
// we schedule the initial plugins update
|
// we schedule the initial plugins update
|
||||||
// a bit after the user launches the terminal
|
// a bit after the user launches the terminal
|
||||||
// to prevent slowness
|
// to prevent slowness
|
||||||
|
|
@ -309,6 +313,13 @@ function requirePlugins() {
|
||||||
|
|
||||||
// populate the name for internal errors here
|
// populate the name for internal errors here
|
||||||
mod._name = basename(path);
|
mod._name = basename(path);
|
||||||
|
try {
|
||||||
|
// eslint-disable-next-line import/no-dynamic-require
|
||||||
|
mod._version = require(resolve(path, 'package.json')).version;
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(`No package.json found in ${path}`);
|
||||||
|
}
|
||||||
|
console.log(`Plugin ${mod._name} (${mod._version}) loaded.`);
|
||||||
|
|
||||||
return mod;
|
return mod;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,19 @@ const clearModulesCache = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getPluginName = path => window.require('path').basename(path);
|
const pathModule = window.require('path');
|
||||||
|
|
||||||
|
const getPluginName = path => pathModule.basename(path);
|
||||||
|
|
||||||
|
const getPluginVersion = path => {
|
||||||
|
let version = null;
|
||||||
|
try {
|
||||||
|
version = window.require(pathModule.resolve(path, 'package.json')).version;
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(`No package.json found in ${path}`);
|
||||||
|
}
|
||||||
|
return version;
|
||||||
|
};
|
||||||
|
|
||||||
const loadModules = () => {
|
const loadModules = () => {
|
||||||
console.log('(re)loading renderer plugins');
|
console.log('(re)loading renderer plugins');
|
||||||
|
|
@ -112,6 +124,7 @@ const loadModules = () => {
|
||||||
.map(path => {
|
.map(path => {
|
||||||
let mod;
|
let mod;
|
||||||
const pluginName = getPluginName(path);
|
const pluginName = getPluginName(path);
|
||||||
|
const pluginVersion = getPluginVersion(path);
|
||||||
|
|
||||||
// window.require allows us to ensure this doesn't get
|
// window.require allows us to ensure this doesn't get
|
||||||
// in the way of our build
|
// in the way of our build
|
||||||
|
|
@ -126,6 +139,7 @@ const loadModules = () => {
|
||||||
for (const i in mod) {
|
for (const i in mod) {
|
||||||
if ({}.hasOwnProperty.call(mod, i)) {
|
if ({}.hasOwnProperty.call(mod, i)) {
|
||||||
mod[i]._pluginName = pluginName;
|
mod[i]._pluginName = pluginName;
|
||||||
|
mod[i]._pluginVersion = pluginVersion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -209,6 +223,8 @@ const loadModules = () => {
|
||||||
mod.onRendererWindow(window);
|
mod.onRendererWindow(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`Plugin ${pluginName} (${pluginVersion}) loaded.`);
|
||||||
|
|
||||||
return mod;
|
return mod;
|
||||||
})
|
})
|
||||||
.filter(mod => Boolean(mod));
|
.filter(mod => Boolean(mod));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue