forked from wulkano/Kap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.js
40 lines (30 loc) · 1007 Bytes
/
plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
const electron = require('electron');
const path = require('path');
const fs = require('fs');
const PluginConfig = require('./utils/plugin-config');
const {app, shell} = electron;
class Plugin {
constructor(pluginName) {
this.pluginName = pluginName;
const cwd = path.join(app.getPath('userData'), 'plugins');
const pluginPath = path.join(cwd, 'node_modules', pluginName);
this.plugin = require(pluginPath);
const {homepage, links} = JSON.parse(fs.readFileSync(path.join(pluginPath, 'package.json'), 'utf8'));
this.link = homepage || (links && links.homepage);
this.config = new PluginConfig(pluginName, this.plugin);
}
isConfigValid() {
return this.config.isConfigValid();
}
getSerivce(serviceTitle) {
return this.plugin.shareServices.find(shareService => shareService.title === serviceTitle);
}
openConfig() {
this.config.openInEditor();
}
viewOnGithub() {
shell.openExternal(this.link);
}
}
module.exports = Plugin;