mirror of https://github.com/keeweb/keeweb.git
moved PluginManager
This commit is contained in:
parent
5a10dc1f2f
commit
2688e761ba
|
@ -80,7 +80,7 @@ ready(() => {
|
||||||
KdbxwebInit.init();
|
KdbxwebInit.init();
|
||||||
FocusDetector.init();
|
FocusDetector.init();
|
||||||
window.kw = ExportApi;
|
window.kw = ExportApi;
|
||||||
return PluginManager.init();
|
return PluginManager.instance.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
function showSettingsLoadError() {
|
function showSettingsLoadError() {
|
||||||
|
@ -146,7 +146,7 @@ ready(() => {
|
||||||
Updater.init();
|
Updater.init();
|
||||||
SingleInstanceChecker.init();
|
SingleInstanceChecker.init();
|
||||||
AppRightsChecker.init();
|
AppRightsChecker.init();
|
||||||
setTimeout(() => PluginManager.runAutoUpdate(), Timeouts.AutoUpdatePluginsAfterStart);
|
setTimeout(() => PluginManager.instance.runAutoUpdate(), Timeouts.AutoUpdatePluginsAfterStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showView() {
|
function showView() {
|
||||||
|
|
|
@ -142,7 +142,7 @@ const AppModel = Backbone.Model.extend({
|
||||||
}
|
}
|
||||||
if (config.plugins) {
|
if (config.plugins) {
|
||||||
const pluginsPromises = config.plugins.map(plugin =>
|
const pluginsPromises = config.plugins.map(plugin =>
|
||||||
PluginManager.installIfNew(plugin.url, plugin.manifest, true)
|
PluginManager.instance.installIfNew(plugin.url, plugin.manifest, true)
|
||||||
);
|
);
|
||||||
return Promise.all(pluginsPromises).then(() => {
|
return Promise.all(pluginsPromises).then(() => {
|
||||||
this.settings.set(config.settings);
|
this.settings.set(config.settings);
|
||||||
|
|
|
@ -233,4 +233,6 @@ const PluginManager = Backbone.Model.extend({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = new PluginManager();
|
PluginManager.instance = new PluginManager();
|
||||||
|
|
||||||
|
module.exports = PluginManager;
|
||||||
|
|
|
@ -47,7 +47,7 @@ const SettingsPluginsView = Backbone.View.extend({
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
this.renderTemplate({
|
this.renderTemplate({
|
||||||
plugins: PluginManager.get('plugins')
|
plugins: PluginManager.instance.get('plugins')
|
||||||
.map(plugin => ({
|
.map(plugin => ({
|
||||||
id: plugin.id,
|
id: plugin.id,
|
||||||
manifest: plugin.get('manifest'),
|
manifest: plugin.get('manifest'),
|
||||||
|
@ -87,7 +87,7 @@ const SettingsPluginsView = Backbone.View.extend({
|
||||||
if (!PluginGallery.gallery) {
|
if (!PluginGallery.gallery) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const plugins = PluginManager.get('plugins');
|
const plugins = PluginManager.instance.get('plugins');
|
||||||
return PluginGallery.gallery.plugins
|
return PluginGallery.gallery.plugins
|
||||||
.map(pl => ({
|
.map(pl => ({
|
||||||
url: pl.url,
|
url: pl.url,
|
||||||
|
@ -142,7 +142,7 @@ const SettingsPluginsView = Backbone.View.extend({
|
||||||
urlTextBox.prop('disabled', true);
|
urlTextBox.prop('disabled', true);
|
||||||
installBtn.text(Locale.setPlInstallBtnProgress + '...').prop('disabled', true);
|
installBtn.text(Locale.setPlInstallBtnProgress + '...').prop('disabled', true);
|
||||||
this.installFromUrl = { url };
|
this.installFromUrl = { url };
|
||||||
PluginManager.install(url, undefined, true)
|
PluginManager.instance.install(url, undefined, true)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.installFinished();
|
this.installFinished();
|
||||||
this.installFromUrl = null;
|
this.installFromUrl = null;
|
||||||
|
@ -166,22 +166,22 @@ const SettingsPluginsView = Backbone.View.extend({
|
||||||
|
|
||||||
uninstallClick(e) {
|
uninstallClick(e) {
|
||||||
const pluginId = $(e.target).data('plugin');
|
const pluginId = $(e.target).data('plugin');
|
||||||
PluginManager.uninstall(pluginId);
|
PluginManager.instance.uninstall(pluginId);
|
||||||
},
|
},
|
||||||
|
|
||||||
disableClick(e) {
|
disableClick(e) {
|
||||||
const pluginId = $(e.target).data('plugin');
|
const pluginId = $(e.target).data('plugin');
|
||||||
PluginManager.disable(pluginId);
|
PluginManager.instance.disable(pluginId);
|
||||||
},
|
},
|
||||||
|
|
||||||
enableClick(e) {
|
enableClick(e) {
|
||||||
const pluginId = $(e.target).data('plugin');
|
const pluginId = $(e.target).data('plugin');
|
||||||
PluginManager.activate(pluginId);
|
PluginManager.instance.activate(pluginId);
|
||||||
},
|
},
|
||||||
|
|
||||||
updateClick(e) {
|
updateClick(e) {
|
||||||
const pluginId = $(e.target).data('plugin');
|
const pluginId = $(e.target).data('plugin');
|
||||||
PluginManager.update(pluginId);
|
PluginManager.instance.update(pluginId);
|
||||||
},
|
},
|
||||||
|
|
||||||
useLocaleClick(e) {
|
useLocaleClick(e) {
|
||||||
|
@ -201,7 +201,7 @@ const SettingsPluginsView = Backbone.View.extend({
|
||||||
installBtn.text(Locale.setPlInstallBtnProgress + '...').prop('disabled', true);
|
installBtn.text(Locale.setPlInstallBtnProgress + '...').prop('disabled', true);
|
||||||
this.installing[plugin.url] = true;
|
this.installing[plugin.url] = true;
|
||||||
delete this.installErrors[plugin.url];
|
delete this.installErrors[plugin.url];
|
||||||
PluginManager.install(plugin.url, plugin.manifest)
|
PluginManager.instance.install(plugin.url, plugin.manifest)
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
this.installErrors[plugin.url] = e;
|
this.installErrors[plugin.url] = e;
|
||||||
delete this.installing[plugin.url];
|
delete this.installing[plugin.url];
|
||||||
|
@ -249,14 +249,14 @@ const SettingsPluginsView = Backbone.View.extend({
|
||||||
const setting = settingEl.data('setting');
|
const setting = settingEl.data('setting');
|
||||||
const pluginId = settingEl.data('plugin');
|
const pluginId = settingEl.data('plugin');
|
||||||
const val = el.type === 'checkbox' ? el.checked : el.value;
|
const val = el.type === 'checkbox' ? el.checked : el.value;
|
||||||
const plugin = PluginManager.getPlugin(pluginId);
|
const plugin = PluginManager.instance.getPlugin(pluginId);
|
||||||
plugin.setSettings({ [setting]: val });
|
plugin.setSettings({ [setting]: val });
|
||||||
},
|
},
|
||||||
|
|
||||||
autoUpdateChange(e) {
|
autoUpdateChange(e) {
|
||||||
const pluginId = $(e.target).data('plugin');
|
const pluginId = $(e.target).data('plugin');
|
||||||
const enabled = e.target.checked;
|
const enabled = e.target.checked;
|
||||||
PluginManager.setAutoUpdate(pluginId, enabled);
|
PluginManager.instance.setAutoUpdate(pluginId, enabled);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const readdirSync = (p, a = []) => {
|
||||||
|
if (fs.statSync(p).isDirectory()) {
|
||||||
|
fs.readdirSync(p).map(f => readdirSync(a[a.push(path.join(p, f)) - 1], a));
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('Building file list...');
|
||||||
|
|
||||||
|
const files = readdirSync('app/scripts').filter(f => f.endsWith('.js'));
|
||||||
|
|
||||||
|
console.log(`Found ${files.length} files, working...`);
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
const lines = fs.readFileSync(file, 'utf8').split('\n');
|
||||||
|
const imports = [];
|
||||||
|
for (let ix = 0; ix < lines.length; ix++) {
|
||||||
|
const match = lines[ix].match(/^const\s+(\w+)\s*=\s*require\('(.*)'\);$/);
|
||||||
|
if (!match) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let [, variable, modPath] = match;
|
||||||
|
if (modPath.includes('/')) {
|
||||||
|
modPath = path.join(path.dirname(file), modPath).replace('app/scripts/', '');
|
||||||
|
}
|
||||||
|
imports.push({
|
||||||
|
variable,
|
||||||
|
modPath
|
||||||
|
});
|
||||||
|
}
|
||||||
|
imports.sort((a, b) => {
|
||||||
|
const aModPath = a.modPath.includes('/') ? a.modPath : `_${a.modPath}`;
|
||||||
|
const bModPath = b.modPath.includes('/') ? b.modPath : `_${b.modPath}`;
|
||||||
|
return aModPath.localeCompare(bModPath);
|
||||||
|
});
|
||||||
|
for (let ix = 0; ix < imports.length; ix++) {
|
||||||
|
const imp = imports[ix];
|
||||||
|
lines[ix] = `import { ${imp.variable} } from '${imp.modPath}';`;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let ix = 0; ix < lines.length; ix++) {
|
||||||
|
const match = lines[ix].match(/^module\.exports/);
|
||||||
|
if (!match) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const simpleExportMatch = lines[ix].match(/^module.exports\s*=\s*(\w+);/);
|
||||||
|
if (simpleExportMatch) {
|
||||||
|
const varName = simpleExportMatch[1];
|
||||||
|
lines[ix] = `export { ${varName} };`;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
console.log(lines[ix]);
|
||||||
|
}
|
||||||
|
// fs.writeFileSync(file, lines.join('\n'));
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Done');
|
Loading…
Reference in New Issue