Skip to content

Commit

Permalink
Hide TTYD Console Tab
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriiNazarenkoTine committed Nov 20, 2024
1 parent 7c0962a commit a4c1b19
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 50 deletions.
4 changes: 3 additions & 1 deletion src/app/config
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 14 additions & 26 deletions src/src/appWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'),
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/src/panels/settings/rrManagerConfigTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
]
Expand Down
34 changes: 22 additions & 12 deletions src/src/tabs/main.js
Original file line number Diff line number Diff line change
@@ -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", {
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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));
Expand Down
33 changes: 24 additions & 9 deletions src/src/tabs/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
Expand All @@ -76,28 +82,31 @@ 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();
try {
(async () => {
await this.setConf();
await this.updateAllForm();
await this.appWin.runScheduledTask('ApplyRRConfig');
// await this.appWin.runScheduledTask('ApplyRRConfig');
this.clearStatusBusy();
this.setStatusOK();
})();
} catch (e) {
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 = {
Expand All @@ -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())
Expand Down

0 comments on commit a4c1b19

Please sign in to comment.