mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-15 13:18:40 -09:00
improve plugin notifications
This commit is contained in:
parent
8c0d94aa1d
commit
edc201ea03
2 changed files with 28 additions and 5 deletions
4
index.js
4
index.js
|
|
@ -184,7 +184,9 @@ app.on('ready', () => {
|
||||||
const setupMenu = () => {
|
const setupMenu = () => {
|
||||||
const tpl = plugins.decorateMenu(createMenu({
|
const tpl = plugins.decorateMenu(createMenu({
|
||||||
createWindow,
|
createWindow,
|
||||||
updatePlugins: plugins.updatePlugins
|
updatePlugins: () => {
|
||||||
|
plugins.updatePlugins({ force: true });
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
Menu.setApplicationMenu(Menu.buildFromTemplate(tpl));
|
Menu.setApplicationMenu(Menu.buildFromTemplate(tpl));
|
||||||
};
|
};
|
||||||
|
|
|
||||||
29
plugins.js
29
plugins.js
|
|
@ -7,6 +7,7 @@ const { sync: mkdirpSync } = require('mkdirp');
|
||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
const Config = require('electron-config');
|
const Config = require('electron-config');
|
||||||
const ms = require('ms');
|
const ms = require('ms');
|
||||||
|
const which = require('which');
|
||||||
const notify = require('./notify');
|
const notify = require('./notify');
|
||||||
|
|
||||||
// local storage
|
// local storage
|
||||||
|
|
@ -48,7 +49,7 @@ config.subscribe(() => {
|
||||||
|
|
||||||
let updating = false;
|
let updating = false;
|
||||||
|
|
||||||
function updatePlugins () {
|
function updatePlugins ({ force = false } = {}) {
|
||||||
if (updating) return notify('Plugin update in progress');
|
if (updating) return notify('Plugin update in progress');
|
||||||
updating = true;
|
updating = true;
|
||||||
syncPackageJSON();
|
syncPackageJSON();
|
||||||
|
|
@ -78,14 +79,31 @@ function updatePlugins () {
|
||||||
// notify watchers
|
// notify watchers
|
||||||
watchers.forEach((fn) => fn(err));
|
watchers.forEach((fn) => fn(err));
|
||||||
|
|
||||||
// we consider it a success if we loaded *all* modules
|
const loaded = modules.length;
|
||||||
if ((paths.plugins.length + paths.localPlugins.length) === modules.length) {
|
const total = paths.plugins.length + paths.localPlugins.length;
|
||||||
|
const pluginVersions = JSON.stringify(getPluginVersions());
|
||||||
|
if (force || (cache.get('plugin-versions') !== pluginVersions && loaded === total)) {
|
||||||
notify('HyperTerm plugins updated!');
|
notify('HyperTerm plugins updated!');
|
||||||
}
|
}
|
||||||
|
cache.set('plugin-versions', pluginVersions);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPluginVersions () {
|
||||||
|
const paths_ = paths.plugins.concat(paths.localPlugins);
|
||||||
|
return paths_.map((path) => {
|
||||||
|
let version = null;
|
||||||
|
try {
|
||||||
|
version = require(resolve(path, 'package.json')).version;
|
||||||
|
} catch (err) { }
|
||||||
|
return [
|
||||||
|
basename(path),
|
||||||
|
version
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function clearCache (mod) {
|
function clearCache (mod) {
|
||||||
for (const entry in require.cache) {
|
for (const entry in require.cache) {
|
||||||
if (0 === entry.indexOf(mod + '/')) {
|
if (0 === entry.indexOf(mod + '/')) {
|
||||||
|
|
@ -99,7 +117,7 @@ exports.updatePlugins = updatePlugins;
|
||||||
// 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
|
||||||
if (cache.get('plugins') !== id) {
|
if (cache.get('plugins') !== id || process.env.HYPERTERM_FORCE_UPDATE) {
|
||||||
// install immediately if the user changed plugins
|
// install immediately if the user changed plugins
|
||||||
console.log('plugins have changed / not init, scheduling plugins installation');
|
console.log('plugins have changed / not init, scheduling plugins installation');
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
@ -114,8 +132,11 @@ function syncPackageJSON () {
|
||||||
const dependencies = toDependencies(plugins);
|
const dependencies = toDependencies(plugins);
|
||||||
const pkg = {
|
const pkg = {
|
||||||
name: 'hyperterm-plugins',
|
name: 'hyperterm-plugins',
|
||||||
|
description: 'Auto-generated from `~/.hyperterm.js`!',
|
||||||
private: true,
|
private: true,
|
||||||
version: '0.0.1',
|
version: '0.0.1',
|
||||||
|
repository: 'zeit/hyperterm',
|
||||||
|
license: 'MIT',
|
||||||
homepage: 'https://hyperterm.org',
|
homepage: 'https://hyperterm.org',
|
||||||
dependencies
|
dependencies
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue