Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show plugin (name and version) loaded #1826

Merged
merged 7 commits into from
Jun 19, 2017
Merged

Conversation

chabou
Copy link
Collaborator

@chabou chabou commented May 14, 2017

Currently, there is no way to know which plugin is loaded and its version.
I begun to add a console.log to my plugins but I realized it can be a useful information and should be a Hyper feature.

This PR add these informations:

  • in shell in dev mode (from electron):
    capture d ecran 2017-05-14 a 22 12 29
  • in devtools (from renderer)
    capture d ecran 2017-05-14 a 22 12 49
  • in About dialog
    capture d ecran 2017-05-14 a 22 07 17
    capture d ecran 2017-05-14 a 22 07 43

To show these information in about dialog, I needed to use a custom Dialog on MacOS like on Windows/Linux. The only downside is that I can't show build number like currently:
capture d ecran 2017-05-14 a 22 15 37

But now, MacOS About dialog is consistant with other OS.

@rauchg: I don't know if you want to add Zeit Copyright (but it is not currently shown on Windows/Linux).

@chabou chabou added the 🎨 Type: Enhancement Issue or PR is an enhancement request/proposal for Hyper label May 14, 2017
@chabou chabou requested a review from rauchg May 14, 2017 20:25
app/index.js Outdated
@@ -395,7 +395,8 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
createWindow,
updatePlugins: () => {
plugins.updatePlugins({force: true});
}
},
getPlugins: plugins.getModules
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you rename it from getModules to getPlugins 🤔 I think it's better to have the same name so it's easier to read the code :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because everywhere in plugin file, modules are mentioned. And plugins.getPlugins seems weird to me.
But you're right, it's really better to not mention module in exports.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getLoadedPlugins will be a better name and it will export only plugin name and version. Not the entire module.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome @chabou 🌮

app/menu.js Outdated
module.exports = ({createWindow, updatePlugins}) => {
module.exports = ({createWindow, updatePlugins, getPlugins}) => {
const showAbout = () => {
const pluginList = getPlugins().length === 0 ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

save the plugins in a variable
const plugins = getPlugins()
at the top of this function, that way you avoid calling it multiple times 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oups... Totally agreed

@@ -69,6 +69,7 @@ const clearModulesCache = () => {
};

const getPluginName = path => window.require('path').basename(path);
const getPluginVersion = path => window.require(window.require('path').resolve(path, 'package.json')).version;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be in a try/catch, just to be safe 😄 maybe if a plugin is not installed yet etc?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I'd import path to a variable

const path = window.require('path')

not really necessary since require caches it but looks cleaner

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, a local plugin withoutpackage.json file can be used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chabou
Copy link
Collaborator Author

chabou commented May 18, 2017

I was certainly tired to make a PR of such poor quality. 😰
Thank you so much @albinekb for your insights.

@@ -307,6 +311,13 @@ function requirePlugins() {

// populate the name for internal errors here
mod._name = basename(path);
try {
// eslint-disable-next-line import/no-dynamic-require
mod._version = require(resolve(path, 'package.json')).version;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be sync and block other stuff, better to do something like:

const getVersion = (path) => new Promise((resolve, reject) => {
  fs.readFile(resolve(path, 'package.json'), (error, result) => {
    if (error) return reject(error)
    try {
      const { version } = JSON.parse(result.toString())
      return resolve(version)
    } catch (error) {
      return reject(error)
    }
  })
})

or just use https://github.com/sindresorhus/load-json-file 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe not an issue since it's (maybe?) cached, and looking at your screenshot it doesn't even take 10ms

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I think it is not an issue, I measure it in renderer with 3 plugins without requiring package.json: 8ms.
With requiring: 12ms.

I don't want to add asynchronous complexity here and in the renderer for such a little gain.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed

const getPluginVersion = path => {
let version = null;
try {
version = window.require(pathModule.resolve(path, 'package.json')).version;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@albinekb
Copy link
Contributor

Great work @chabou ❤️

@chabou
Copy link
Collaborator Author

chabou commented Jun 7, 2017

rebased and Copyright added
capture d ecran 2017-06-08 a 00 17 32

Ready to merge

@albinekb
Copy link
Contributor

albinekb commented Jun 8, 2017

Is it OK'd by the @zeit team?

@Stanzilla Stanzilla mentioned this pull request Jun 16, 2017
5 tasks
Copy link
Member

@matheuss matheuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@chabou
Copy link
Collaborator Author

chabou commented Jun 19, 2017

It seems impossible to easily add link to this Electron MessageBox.

@chabou chabou merged commit db35faa into vercel:master Jun 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎨 Type: Enhancement Issue or PR is an enhancement request/proposal for Hyper
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants