Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@
"settingsAddServerButton": {
"message": "Add Server"
},
"settingsAddActiveSubscriptionProxyServerButton": {
"message": "Add to My Servers"
},
"settingsRemoveMultipleServerButton": {
"message": "Delete Multiple"
},
Expand Down
64 changes: 60 additions & 4 deletions src/ui/code/settingsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ export class settingsPage {

jq("#btnAddProxyServer").click(settingsPage.uiEvents.onClickAddProxyServer);

jq("#btnAddActiveSubscriptionProxyServerToMyServers").click(settingsPage.uiEvents.onClickAddActiveSubscriptionProxyServerToMyServers);

jq("#btnRemoveMultipleProxyServer").click(settingsPage.uiEvents.onClickRemoveMultipleProxyServer);

jq("#cmdServerProtocol").on("change", settingsPage.uiEvents.onChangeServerProtocol);
Expand Down Expand Up @@ -1201,6 +1203,7 @@ export class settingsPage {

// populate
this.populateProxyServersToComboBox(cmbActiveProxyServer, defaultProxyServerId, proxyServers, serverSubscriptions);
this.updateActiveSubscriptionProxyServerAction();
}

private static readServers(): ProxyServer[] {
Expand Down Expand Up @@ -1318,6 +1321,35 @@ export class settingsPage {
return null;
}

private static findProxyServerSubscriptionByProxyServerId(proxyServerId: string): ProxyServerSubscription | null {
if (!proxyServerId)
return null;

let serverSubscriptions = settingsPage.readServerSubscriptions();
for (let subscription of serverSubscriptions) {
if (!subscription.enabled || !subscription.proxies)
continue;

let proxy = subscription.proxies.find(item => item.id === proxyServerId);
if (proxy !== undefined)
return subscription;
}
return null;
}

private static updateActiveSubscriptionProxyServerAction() {
let proxyServerId = jq("#cmbActiveProxyServer").val() as string;
let subscription = settingsPage.findProxyServerSubscriptionByProxyServerId(proxyServerId);
let button = jq("#btnAddActiveSubscriptionProxyServerToMyServers");

if (subscription) {
button.removeClass("d-none");
}
else {
button.addClass("d-none");
}
}

private static exportServersListFormatted(): string {
let proxyList = settingsPage.readServers();
let result = `[SmartProxy Servers]\r\n`;
Expand Down Expand Up @@ -2640,6 +2672,7 @@ export class settingsPage {
else {
Debug.warn("Settings> Selected ActiveProxyServer ID not found!");
}
settingsPage.updateActiveSubscriptionProxyServerAction();
},
onClickAddProxyServer() {

Expand All @@ -2651,6 +2684,29 @@ export class settingsPage {
modal.modal("show");
modal.find("#txtServerAddress").focus();
},
onClickAddActiveSubscriptionProxyServerToMyServers() {
let proxyServerId = jq("#cmbActiveProxyServer").val() as string;
let subscription = settingsPage.findProxyServerSubscriptionByProxyServerId(proxyServerId);
if (!subscription || !subscription.proxies)
return;

let server = subscription.proxies.find(item => item.id === proxyServerId);
if (!server)
return;

let modal = jq("#modalModifyProxyServer");
modal.data("editing", null);

let serverToAdd = new ProxyServer();
jQuery.extend(serverToAdd, server);
serverToAdd.order = settingsPage.readServers().reduce((order, item) => Math.max(order, item.order || 0), 0) + 1;
serverToAdd.name = settingsPage.generateNewServerName(subscription.name);

settingsPage.populateServerModal(modal, serverToAdd);

modal.modal("show");
modal.find("#txtServerAddress").focus();
},
onClickRemoveMultipleProxyServer() {
var rows = settingsPage.grdServers.rows({ selected: true });
if (!rows)
Expand Down Expand Up @@ -4367,25 +4423,25 @@ export class settingsPage {
//#endregion

//#region Common functions ---------------
private static generateNewServerName(): string {
private static generateNewServerName(prefix: string = "Server"): string {
// generates a unique name for proxy server
let servers = this.readServers();
let serverNo = 1;
let result = `Server ${serverNo}`;
let result = `${prefix} ${serverNo}`;

if (servers && servers.length > 0) {
let exist;

serverNo = servers.length + 1;
result = `Server ${serverNo}`;
result = `${prefix} ${serverNo}`;

do {
exist = false;
for (let i = servers.length - 1; i >= 0; i--) {
if (servers[i].name === result) {
exist = true;
serverNo++;
result = `Server ${serverNo}`;
result = `${prefix} ${serverNo}`;
break;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/ui/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,10 @@ <h5 data-localize="settingsActiveProxyServer">
<option value="0">(Select)</option>
</select>
</div>
<div class="col-auto">
<button id="btnAddActiveSubscriptionProxyServerToMyServers" class="btn btn-info d-none"
data-localize="settingsAddActiveSubscriptionProxyServerButton">Add to My Servers</button>
</div>
</div>
<h5 data-localize="settingsTabProxyServersTitle">
Manage your proxy servers:
Expand Down