Skip to content

Commit

Permalink
>Export Base64-encoded Share Links to Clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Aug 17, 2024
1 parent 7faabdc commit 770e8b8
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 36 deletions.
28 changes: 23 additions & 5 deletions v2rayN/v2rayN/Resx/ResUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions v2rayN/v2rayN/Resx/ResUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="BatchExportURLSuccessfully" xml:space="preserve">
<value>Batch export share URL to clipboard successfully</value>
<value>Export Share Link to Clipboard Successfully</value>
</data>
<data name="CheckServerSettings" xml:space="preserve">
<value>Please check the server settings first</value>
Expand Down Expand Up @@ -299,7 +299,7 @@
<value>{0} servers have been imported from clipboard</value>
</data>
<data name="SuccessfullyImportedServerViaScan" xml:space="preserve">
<value>Scan import URL successfully</value>
<value>Scan import the shared link successfully</value>
</data>
<data name="TestMeOutput" xml:space="preserve">
<value>The ping of current service: {0} ms</value>
Expand Down Expand Up @@ -491,7 +491,7 @@
<value>Language (Restart)</value>
</data>
<data name="menuAddServerViaClipboard" xml:space="preserve">
<value>Import bulk URL from clipboard (Ctrl+V)</value>
<value>Importing Share Links from clipboard (Ctrl+V)</value>
</data>
<data name="menuAddServerViaScan" xml:space="preserve">
<value>Scan QR code on the screen (Ctrl+S)</value>
Expand Down Expand Up @@ -524,10 +524,10 @@
<value>Test servers with tcping (Ctrl+O)</value>
</data>
<data name="menuExport2ClientConfig" xml:space="preserve">
<value>Export selected server for client configuration</value>
<value>Export selected server for complete configuration</value>
</data>
<data name="menuExport2ShareUrl" xml:space="preserve">
<value>Export share URLs to clipboard (Ctrl+C)</value>
<value>Export Share Link to Clipboard (Ctrl+C)</value>
</data>
<data name="menuAddCustomServer" xml:space="preserve">
<value>Add a custom configuration server</value>
Expand Down Expand Up @@ -1264,4 +1264,10 @@
<data name="menuProfileAutofitColumnWidth" xml:space="preserve">
<value>Auto column width adjustment</value>
</data>
<data name="menuExport2ShareUrlBase64" xml:space="preserve">
<value>Export Base64-encoded Share Links to Clipboard</value>
</data>
<data name="menuExport2ClientConfigClipboard" xml:space="preserve">
<value>Export selected server for complete configuration to clipboard</value>
</data>
</root>
16 changes: 11 additions & 5 deletions v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="BatchExportURLSuccessfully" xml:space="preserve">
<value>批量导出分享URL至剪贴板成功</value>
<value>导出分享链接至剪贴板成功</value>
</data>
<data name="CheckServerSettings" xml:space="preserve">
<value>请先检查服务器设置</value>
Expand Down Expand Up @@ -299,7 +299,7 @@
<value>成功从剪贴板导入 {0} 个服务器</value>
</data>
<data name="SuccessfullyImportedServerViaScan" xml:space="preserve">
<value>扫描导入URL成功</value>
<value>扫描导入分享链接成功</value>
</data>
<data name="TestMeOutput" xml:space="preserve">
<value>当前服务的真连接延迟: {0} ms</value>
Expand Down Expand Up @@ -491,7 +491,7 @@
<value>语言(重启)</value>
</data>
<data name="menuAddServerViaClipboard" xml:space="preserve">
<value>从剪贴板导入批量URL (Ctrl+V)</value>
<value>从剪贴板导入分享链接 (Ctrl+V)</value>
</data>
<data name="menuAddServerViaScan" xml:space="preserve">
<value>扫描屏幕上的二维码 (Ctrl+S)</value>
Expand Down Expand Up @@ -524,10 +524,10 @@
<value>测试服务器延迟Tcping(多选) (Ctrl+O)</value>
</data>
<data name="menuExport2ClientConfig" xml:space="preserve">
<value>导出所选服务器为客户端配置</value>
<value>导出所选服务器完整配置</value>
</data>
<data name="menuExport2ShareUrl" xml:space="preserve">
<value>批量导出分享URL至剪贴板(多选) (Ctrl+C)</value>
<value>导出分享链接至剪贴板(多选) (Ctrl+C)</value>
</data>
<data name="menuAddCustomServer" xml:space="preserve">
<value>添加自定义配置服务器</value>
Expand Down Expand Up @@ -1261,4 +1261,10 @@
<data name="menuProfileAutofitColumnWidth" xml:space="preserve">
<value>自动调整列宽</value>
</data>
<data name="menuExport2ShareUrlBase64" xml:space="preserve">
<value>导出分享链接至剪贴板(多选) Base64编码</value>
</data>
<data name="menuExport2ClientConfigClipboard" xml:space="preserve">
<value>导出所选服务器完整配置至剪贴板</value>
</data>
</root>
16 changes: 11 additions & 5 deletions v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="BatchExportURLSuccessfully" xml:space="preserve">
<value>批次匯出分享URL至剪貼簿成功</value>
<value>匯出分享链接至剪貼簿成功</value>
</data>
<data name="CheckServerSettings" xml:space="preserve">
<value>請先檢查伺服器設定</value>
Expand Down Expand Up @@ -298,7 +298,7 @@
<value>成功從剪貼簿匯入 {0} 個伺服器</value>
</data>
<data name="SuccessfullyImportedServerViaScan" xml:space="preserve">
<value>掃描匯入URL成功</value>
<value>掃描匯入分享链接成功</value>
</data>
<data name="TestMeOutput" xml:space="preserve">
<value>目前服務的真連接延遲: {0} ms</value>
Expand Down Expand Up @@ -490,7 +490,7 @@
<value>語言(重啟)</value>
</data>
<data name="menuAddServerViaClipboard" xml:space="preserve">
<value>從剪貼簿匯入批次URL (Ctrl+V)</value>
<value>從剪貼簿導入分享鏈接 (Ctrl+V)</value>
</data>
<data name="menuAddServerViaScan" xml:space="preserve">
<value>掃描螢幕上的二維碼 (Ctrl+S)</value>
Expand Down Expand Up @@ -523,10 +523,10 @@
<value>測試伺服器延遲Tcping(多選) (Ctrl+O)</value>
</data>
<data name="menuExport2ClientConfig" xml:space="preserve">
<value>匯出所選伺服器為用戶端配置</value>
<value>匯出所選伺服器完整配置</value>
</data>
<data name="menuExport2ShareUrl" xml:space="preserve">
<value>批次匯出分享URL至剪貼簿(多選) (Ctrl+C)</value>
<value>匯出分享链接至剪貼簿(多選) (Ctrl+C)</value>
</data>
<data name="menuAddCustomServer" xml:space="preserve">
<value>新增自訂配置伺服器</value>
Expand Down Expand Up @@ -1141,4 +1141,10 @@
<data name="menuProfileAutofitColumnWidth" xml:space="preserve">
<value>自動調整列寬</value>
</data>
<data name="menuExport2ShareUrlBase64" xml:space="preserve">
<value>匯出分享链接至剪貼簿(多選) Base64编码</value>
</data>
<data name="menuExport2ClientConfigClipboard" xml:space="preserve">
<value>匯出所選伺服器完整配置至剪貼簿</value>
</data>
</root>
45 changes: 38 additions & 7 deletions v2rayN/v2rayN/ViewModels/ProfilesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ public class ProfilesViewModel : MyReactiveObject
//servers export
public ReactiveCommand<Unit, Unit> Export2ClientConfigCmd { get; }

public ReactiveCommand<Unit, Unit> Export2ClientConfigClipboardCmd { get; }
public ReactiveCommand<Unit, Unit> Export2ShareUrlCmd { get; }
public ReactiveCommand<Unit, Unit> Export2ShareUrlBase64Cmd { get; }

public ReactiveCommand<Unit, Unit> AddSubCmd { get; }
public ReactiveCommand<Unit, Unit> EditSubCmd { get; }
Expand Down Expand Up @@ -216,11 +218,19 @@ public ProfilesViewModel(Func<EViewAction, object?, bool>? updateView)
//servers export
Export2ClientConfigCmd = ReactiveCommand.Create(() =>
{
Export2ClientConfig();
Export2ClientConfig(false);
}, canEditRemove);
Export2ClientConfigClipboardCmd = ReactiveCommand.Create(() =>
{
Export2ClientConfig(true);
}, canEditRemove);
Export2ShareUrlCmd = ReactiveCommand.Create(() =>
{
Export2ShareUrl();
Export2ShareUrl(false);
}, canEditRemove);
Export2ShareUrlBase64Cmd = ReactiveCommand.Create(() =>
{
Export2ShareUrl(true);
}, canEditRemove);

//Subscription
Expand Down Expand Up @@ -670,16 +680,30 @@ public void ServerSpeedtest(ESpeedActionType actionType)
}
}

private void Export2ClientConfig()
private void Export2ClientConfig(bool blClipboard)
{
var item = LazyConfig.Instance.GetProfileItem(SelectedProfile.indexId);
if (item is null)
{
_noticeHandler?.Enqueue(ResUI.PleaseSelectServer);
return;
}

_updateView?.Invoke(EViewAction.SaveFileDialog, item);
if (blClipboard)
{
if (CoreConfigHandler.GenerateClientConfig(item, null, out string msg, out string content) != 0)
{
Locator.Current.GetService<NoticeHandler>()?.Enqueue(msg);
}
else
{
WindowsUtils.SetClipboardData(content);
_noticeHandler?.SendMessage(ResUI.OperationSuccess);
}
}
else
{
_updateView?.Invoke(EViewAction.SaveFileDialog, item);
}
}

public void Export2ClientConfigResult(string fileName, ProfileItem item)
Expand All @@ -699,7 +723,7 @@ public void Export2ClientConfigResult(string fileName, ProfileItem item)
}
}

public void Export2ShareUrl()
public void Export2ShareUrl(bool blEncode)
{
if (GetProfileItems(out List<ProfileItem> lstSelecteds, true) < 0)
{
Expand All @@ -719,7 +743,14 @@ public void Export2ShareUrl()
}
if (sb.Length > 0)
{
WindowsUtils.SetClipboardData(sb.ToString());
if (blEncode)
{
WindowsUtils.SetClipboardData(Utils.Base64Encode(sb.ToString()));
}
else
{
WindowsUtils.SetClipboardData(sb.ToString());
}
_noticeHandler?.SendMessage(ResUI.BatchExportURLSuccessfully);
}
}
Expand Down
28 changes: 20 additions & 8 deletions v2rayN/v2rayN/Views/ProfilesView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,26 @@
Click="menuSelectAll_Click"
Header="{x:Static resx:ResUI.menuSelectAll}" />
<Separator />
<MenuItem
x:Name="menuExport2ClientConfig"
Height="{StaticResource MenuItemHeight}"
Header="{x:Static resx:ResUI.menuExport2ClientConfig}" />
<MenuItem
x:Name="menuExport2ShareUrl"
Height="{StaticResource MenuItemHeight}"
Header="{x:Static resx:ResUI.menuExport2ShareUrl}" />
<MenuItem Header="{x:Static resx:ResUI.menuExport2ClientConfig}">
<MenuItem
x:Name="menuExport2ClientConfig"
Height="{StaticResource MenuItemHeight}"
Header="{x:Static resx:ResUI.menuExport2ClientConfig}" />
<MenuItem
x:Name="menuExport2ClientConfigClipboard"
Height="{StaticResource MenuItemHeight}"
Header="{x:Static resx:ResUI.menuExport2ClientConfigClipboard}" />
</MenuItem>
<MenuItem Header="{x:Static resx:ResUI.menuExport2ShareUrl}">
<MenuItem
x:Name="menuExport2ShareUrl"
Height="{StaticResource MenuItemHeight}"
Header="{x:Static resx:ResUI.menuExport2ShareUrl}" />
<MenuItem
x:Name="menuExport2ShareUrlBase64"
Height="{StaticResource MenuItemHeight}"
Header="{x:Static resx:ResUI.menuExport2ShareUrlBase64}" />
</MenuItem>
</ContextMenu>
</DataGrid.ContextMenu>
<DataGrid.Resources>
Expand Down
4 changes: 3 additions & 1 deletion v2rayN/v2rayN/Views/ProfilesView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ public ProfilesView()
//servers export
this.BindCommand(ViewModel, vm => vm.Export2ClientConfigCmd, v => v.menuExport2ClientConfig).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.Export2ClientConfigClipboardCmd, v => v.menuExport2ClientConfigClipboard).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.Export2ShareUrlCmd, v => v.menuExport2ShareUrl).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.Export2ShareUrlBase64Cmd, v => v.menuExport2ShareUrlBase64).DisposeWith(disposables);
});

RestoreUI();
Expand Down Expand Up @@ -236,7 +238,7 @@ private void LstProfiles_PreviewKeyDown(object sender, KeyEventArgs e)
break;

case Key.C:
ViewModel?.Export2ShareUrl();
ViewModel?.Export2ShareUrl(false);
break;

case Key.D:
Expand Down

0 comments on commit 770e8b8

Please sign in to comment.