diff --git a/src/app/config b/src/app/config index f723995..2b9af5f 100644 --- a/src/app/config +++ b/src/app/config @@ -9,7 +9,9 @@ "allowMultiInstance": false, "allUsers": false, "appWindow": "SYNOCOMMUNITY.RRManager.AppWindow", - "depend": ["SYNOCOMMUNITY.RRManager.AppWindow"] + "depend": ["SYNOCOMMUNITY.RRManager.AppWindow"], + "enableTTYDTab": false, + "checkRRForUpdates": false }, "SYNOCOMMUNITY.RRManager.AppWindow": { "type": "lib", diff --git a/src/src/appWindow.js b/src/src/appWindow.js index 638f351..7314884 100644 --- a/src/src/appWindow.js +++ b/src/src/appWindow.js @@ -18,10 +18,14 @@ export default constructor: function (config) { const t = this; this.apiProvider.init(this.sendWebAPI.bind(this)); - t.callParent([t.fillConfig(config)]); + t.callParent([t.fillConfig(config)]); }, fillConfig: function (e) { - let tabs = this.getListItems(); + //get app setting from src\app\config + const jsConfig =e.appInstance.initialConfig?.taskButton?.jsConfig; + //check if the console tab is enabled + const showConsoleTab = jsConfig?.enableTTYDTab; + let tabs = this.getListTabs(showConsoleTab); const i = { cls: "syno-app-iscsi", width: this.defaultWinSize.width, @@ -32,9 +36,8 @@ export default listItems: tabs, }; return Ext.apply(i, e), i; - }, - getListItems: function () { + getListTabs: function (showConsoleTab) { let items = [ { text: this.helper.V('ui', 'tab_general'), @@ -51,34 +54,19 @@ export default iconCls: "icon-debug", fn: "SYNOCOMMUNITY.RRManager.Debug.Main", }, - { - text: 'Console', - iconCls: "icon-terminal-and-SNMP", - fn: "SYNOCOMMUNITY.RRManager.Ssh.Main", - }, { text: this.helper.V('ui', 'tab_configuration'), iconCls: "icon-rr-setting", fn: "SYNOCOMMUNITY.RRManager.Setting.Main", } ]; - // // Fetch conditionally add a tab if `ttydPackage` is available - // this.apiProvider.getPackagesList().then((response) => { - // let ttydPackage = response.packages.find((pkg) => pkg.id === 'TTYD'); - // if (ttydPackage) { - // let newTab = { - // text: "Console", - // iconCls: "icon-terminal-and-SNMP", - // fn: "SYNOCOMMUNITY.RRManager.Ssh.Main", - // }; - - // // Check if the tab already exists to prevent duplicates - // if (!items.find(tab => tab.fn === newTab.fn)) { - // items.push(newTab); - // } - // } - // return items; - // }); + if (showConsoleTab) { + items.push({ + text: 'Console', + iconCls: "icon-terminal-and-SNMP", + fn: "SYNOCOMMUNITY.RRManager.Ssh.Main", + }); + } return items; }, onOpen: function (a) { diff --git a/src/src/panels/settings/rrManagerConfigTab.js b/src/src/panels/settings/rrManagerConfigTab.js index d7a9736..b22c7e1 100644 --- a/src/src/panels/settings/rrManagerConfigTab.js +++ b/src/src/panels/settings/rrManagerConfigTab.js @@ -18,12 +18,12 @@ export default items: [ { boxLabel: 'Check for updates on App Startup', - name: 'checkForUpdates', + name: 'checkRRForUpdates', xtype: 'syno_checkbox', }, { boxLabel: 'Enable TTYD package integration', - name: 'checkForUpdates', + name: 'enableTTYDTab', xtype: 'syno_checkbox', } ] diff --git a/src/src/tabs/main.js b/src/src/tabs/main.js index 6dc4e23..864f58b 100644 --- a/src/src/tabs/main.js +++ b/src/src/tabs/main.js @@ -1,7 +1,6 @@ import UpdateAvailable from '../components/dialogs/updateAvailableDialog'; import PasswordConfirmDialog from '../components/dialogs/passwordConfirmDialog'; import UploadFileDialog from '../components/dialogs/uploadFileDialog'; -import UpdateHelper from '../utils/updateHelper'; import updateHelper from '../utils/updateHelper'; export default Ext.define("SYNOCOMMUNITY.RRManager.Overview.Main", { @@ -15,12 +14,22 @@ export default }); }, - handleFileUpload: function (jsonData) { - this.apiProvider._handleFileUpload(jsonData).then(x => { - this.apiProvider.runScheduledTask('ApplyRRConfig'); - this.showMsg(this.helper.V('ui', 'rr_config_applied')); - this.appWin.clearStatusBusy(); - }); + handleFileUpload: function (jsonData, rrManagerConfig) { + if (jsonData) { + this.apiProvider._handleFileUpload(jsonData).then(x => { + this.apiProvider.runScheduledTask('ApplyRRConfig'); + this.showMsg(this.helper.V('ui', 'rr_config_applied')); + this.appWin.clearStatusBusy(); + }); + } + //TODO: implement modify rrManagerConfig + if (rrManagerConfig) { + this.apiProvider._handleFileUpload(rrManagerConfig).then(x => { + this.apiProvider.runScheduledTask('ApplyRRConfig'); + this.showMsg(this.helper.V('ui', 'rr_config_applied')); + this.appWin.clearStatusBusy(); + }); + } }, constructor: function (e) { this.installed = false; @@ -165,20 +174,20 @@ export default if (tasksToCreate.length > 0 || ifSetRRprivTask) { async function craeteTasks() { const task = requiredTasks[0]; - if (ifSetRRprivTask){ + if (ifSetRRprivTask) { //Update existing task if (task.updateTaskCallback) { var data = await self.showPasswordConfirmDialog(task.name); task.updateTaskCallback(data, ifSetRRprivTask != null); } } - else{ + else { //Create new task if (task.createTaskCallback) { var data = await self.showPasswordConfirmDialog(task.name); task.createTaskCallback(data, ifSetRRprivTask != null); } - } + } // After all tasks have been created, you might want to notify the user. self.showMsg(self.helper.V('ui', 'tasks_created_msg')); self.owner.clearStatusBusy(); @@ -269,7 +278,8 @@ export default const [systemInfo, packages, rrCheckVersion] = await Promise.all([ self.apiProvider.getSytemInfo(), self.apiProvider.getPackagesList(), - self.apiProvider.checkRRVersion() + self.initialConfig.appWin.initialConfig.appInstance.taskButton.jsConfig.checkRRForUpdates + ? self.apiProvider.checkRRVersion() : null ]); self.systemInfo = systemInfo; var isModernDSM = systemInfo.version_string.includes("7.2.2"); @@ -314,7 +324,7 @@ export default self.loaded = true; } - if (self.isUpdateAvailable(rrCheckVersion)) { + if (rrCheckVersion && self.isUpdateAvailable(rrCheckVersion)) { self.showPrompt(self.helper.V('ui', 'prompt_update_available_title'), self.helper.formatString(self.helper.V('ui', 'prompt_update_available_message'), rrCheckVersion.tag), rrCheckVersion.notes, self.donwloadUpdate.bind(self)); diff --git a/src/src/tabs/setting.js b/src/src/tabs/setting.js index 9d2c495..ec5ef96 100644 --- a/src/src/tabs/setting.js +++ b/src/src/tabs/setting.js @@ -52,13 +52,19 @@ export default return Ext.apply(settingsConfig, e); }, - loadAllForms: function (e) { + loadAllForms: function (config) { + const user_config = config.user_config; + const rrm_config = config.rrm_config; this.items.each((t) => { if (t && typeof t.loadForm !== undefined && Ext.isFunction(t.loadForm)) { if (t.itemId == "SynoInfoTab") { - t.loadForm(e.synoinfo); - } else { - t.loadForm(e); + t.loadForm(user_config.synoinfo); + }if(t.itemId == "RrManagerConfigTab") { + debugger; + t.loadForm(rrm_config); + } + else { + t.loadForm(user_config); } } }); @@ -76,7 +82,9 @@ export default this.clearStatusBusy(); }, applyHandler: function () { - this.confirmApply() && this.doApply().catch(() => { }); + this.confirmApply() && this.doApply().catch((error) => + alert("Error", error) + ); }, doApply: async function () { this.setStatusBusy(); @@ -84,7 +92,7 @@ export default (async () => { await this.setConf(); await this.updateAllForm(); - await this.appWin.runScheduledTask('ApplyRRConfig'); + // await this.appWin.runScheduledTask('ApplyRRConfig'); this.clearStatusBusy(); this.setStatusOK(); })(); @@ -92,12 +100,13 @@ export default SYNO.Debug(e); this.clearStatusBusy(); this.appWin.getMsgBox().alert(this.title, this.API.getErrorString(e)); - throw e; } }, getParams: function () { const generalTab = this.generalTab.getForm().getValues(); const rrConfigTab = this.rrConfigTab.getForm().getValues(); + const rrManagerConfigTab = this.rrManagerConfigTab.getForm().getValues(); + localStorage.setItem("rrManagerConfig", JSON.stringify(rrManagerConfigTab)); const synoInfoTab = this.synoInfoTab.getForm().getValues(); const synoInfoTabFixed = { @@ -111,17 +120,23 @@ export default getConf: function () { var rrConfigJson = localStorage.getItem("rrConfig"); var rrConfig = JSON.parse(rrConfigJson); + var rrManagerConfig = this.appWin.appInstance.initialConfig.taskButton.jsConfig - return rrConfig?.user_config; + return { + user_config: rrConfig?.user_config, + rrm_config: rrManagerConfig, + }; }, setConf: function () { var user_config = this.getParams(); var rrConfigJson = localStorage.getItem("rrConfig"); var rrConfigOrig = JSON.parse(rrConfigJson); + var rrManagerConfigJson = localStorage.getItem("rrConfig"); + var rrManagerConfigOrig = JSON.parse(rrManagerConfigJson);\ rrConfigOrig.user_config = user_config; localStorage.setItem("rrConfig", JSON.stringify(rrConfigOrig)); - return this.appWin.handleFileUpload(user_config); + return this.appWin.handleFileUpload(user_config, rrManagerConfigOrig); }, confirmApply: function () { if (!this.isAnyFormDirty())