Skip to content

Commit

Permalink
fix: init plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
whes1015 committed Dec 3, 2024
1 parent a82057c commit 0ff569d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 21 deletions.
34 changes: 34 additions & 0 deletions src/js/index/plugin_init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const fs = require('fs-extra');
const path = require('path');
const { app } = require('@electron/remote');

async function copyMissingTremFiles() {
try {
const defaultPluginsPath = path.join(__dirname, '../../resource/plugins');
const userPluginsPath = path.join(app.getPath('userData'), 'plugins');

await fs.ensureDir(userPluginsPath);

const defaultTremFiles = (await fs.readdir(defaultPluginsPath))
.filter((file) => file.endsWith('.trem'));
const userTremFiles = (await fs.readdir(userPluginsPath))
.filter((file) => file.endsWith('.trem'));

const missingFiles = defaultTremFiles.filter((file) => !userTremFiles.includes(file));

for (const file of missingFiles) {
const srcFile = path.join(defaultPluginsPath, file);
const destFile = path.join(userPluginsPath, file);
await fs.copy(srcFile, destFile);
console.log(`Copied ${file} to user plugins directory`);
}

return missingFiles;
}
catch (error) {
console.error('Error copying trem files:', error);
throw error;
}
}

module.exports = copyMissingTremFiles;
48 changes: 27 additions & 21 deletions src/js/index/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,30 @@ const logger = require('../js/core/utils/logger');

logger.info('App start');

// require('../js/core/config');
require('../js/core/plugin')('index');

require('../js/index/nav');
require('../js/index/lang');
require('../js/index/event');
require('../js/index/map');
require('../js/index/data/data');

require('../js/index/core/resource');
require('../js/index/core/tts');
require('../js/index/core/rts');
require('../js/index/core/eew');
require('../js/index/core/loop');
require('../js/index/core/estimate');
require('../js/index/core/audio');
require('../js/index/core/focus');
require('../js/index/core/report');
require('../js/index/core/intensity');
require('../js/index/core/lpgm');
require('../js/index/core/window');
const copyMissingTremFiles = require('../js/index/plugin_init');

(async () => {
await copyMissingTremFiles();

// require('../js/core/config');
require('../js/core/plugin')('index');

require('../js/index/nav');
require('../js/index/lang');
require('../js/index/event');
require('../js/index/map');
require('../js/index/data/data');

require('../js/index/core/resource');
require('../js/index/core/tts');
require('../js/index/core/rts');
require('../js/index/core/eew');
require('../js/index/core/loop');
require('../js/index/core/estimate');
require('../js/index/core/audio');
require('../js/index/core/focus');
require('../js/index/core/report');
require('../js/index/core/intensity');
require('../js/index/core/lpgm');
require('../js/index/core/window');
})();
Binary file added src/resource/plugins/setting.trem
Binary file not shown.

0 comments on commit 0ff569d

Please sign in to comment.