Skip to content

Commit 035fe26

Browse files
author
Kristifor Milchev
committed
Resolving the browser regression issue caused by the electron merge, now links should open properly on all 3 operating systems.
1 parent cab2736 commit 035fe26

File tree

3 files changed

+163
-128
lines changed

3 files changed

+163
-128
lines changed

Pages/Landing.razor

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,6 @@
770770

771771
private async void OpenLink(TokenLink link)
772772
{
773-
Uri uri = new Uri(link.Url);
774-
@* await Browser.Default.OpenAsync(uri, BrowserLaunchMode.SystemPreferred); *@
773+
Utilities.OpenBrowser(link.Url);
775774
}
776775
}

Services/Definitions/IUtilities.cs

Lines changed: 133 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,133 @@
1-
using SYNCWallet.Models;
2-
3-
namespace SYNCWallet.Services.Definitions
4-
{
5-
public interface IUtilities
6-
{
7-
/// <summary>
8-
/// Returns a list of NetworkSettings, executes a query against the main github repository
9-
/// retruves the officially supported networks and then checks if there are any local networks returns the combined result
10-
/// </summary>
11-
public Task<List<NetworkSettings>> SetupNetworks();
12-
13-
/// <summary>
14-
/// Returns the result of a Generic GET request as a model of T
15-
/// Parameters:
16-
/// <paramref name="url"/>
17-
/// <param name="url">The weboage url to get, must be a JSON that matches the T properties.</param>
18-
/// </summary>
19-
public Task<T> GetRequest<T>(string url);
20-
21-
/// <summary>
22-
/// Splits a string to equal chunks
23-
/// Parameters:
24-
/// <paramref name="str"/>
25-
/// <param name="str">The original string that has to be split to equal chunks</param>
26-
/// <paramref name="chunkSize"/>
27-
/// <param name="chunkSize">The number of piaces that the string has to be broken to</param>
28-
/// </summary>
29-
public IEnumerable<string> Split(string str, int chunkSize);
30-
31-
/// <summary>
32-
/// Converts a binary to string
33-
/// Example: 101-> 1
34-
/// Parameters:
35-
/// <paramref name="data"/>
36-
/// <param name="data">Any text UTF 8 encoded</param>
37-
/// </summary>
38-
public string BinaryToString(string data);
39-
40-
/// <summary>
41-
/// Converts a string to binary
42-
/// Example: 1-> 101
43-
/// Parameters:
44-
/// <param name="data">Any text UTF 8 encoded</param>
45-
/// </summary>
46-
public string StringToBinary(string data);
47-
48-
49-
/// <summary>
50-
/// Multiplies the value to the 10 of the power of the delimiter,
51-
/// used for interaction with solidity smart contracts.
52-
/// Parameters:
53-
/// <paramref name="value"/>
54-
/// <param name="value">The value that has to be multiplied</param>
55-
/// <paramref name="delimeter"/>
56-
/// <param name="delimeter">the number to rise 10 to the power over</param>
57-
/// </summary>
58-
public decimal SetDecimalPoint(decimal value, int delimeter);
59-
60-
/// <summary>
61-
/// Divides the value to the 10 of the power of the delimiter,
62-
/// used for interaction with solidity smart contracts.
63-
/// Parameters:
64-
/// <paramref name="value"/>
65-
/// <param name="value">The value that has to be multiplied</param>
66-
/// <paramref name="delimeter"/>
67-
/// <param name="delimeter">the number to rise 10 to the power over</param>
68-
/// </summary>
69-
public decimal ConvertToDex(decimal value, int delimeter);
70-
71-
72-
/// <summary>
73-
/// Multiplies the value to the 10 of the power of the delimiter,
74-
/// used for interaction with solidity smart contracts.
75-
/// Parameters:
76-
/// <paramref name="value"/>
77-
/// <param name="value">The value that has to be multiplied BigInteger</param>
78-
/// <paramref name="delimeter"/>
79-
/// <param name="delimeter">the number to rise 10 to the power over</param>
80-
/// </summary>
81-
public decimal ConvertToBigIntDex(System.Numerics.BigInteger value, int delimeter);
82-
83-
84-
/// <summary>
85-
/// Divides the value to the 10 of the power of the delimiter,
86-
/// used for interaction with solidity smart contracts.
87-
/// Parameters:
88-
/// <paramref name="value"/>
89-
/// <param name="value">The value that has to be multiplied</param>
90-
/// <paramref name="delimeter"/>
91-
/// <param name="delimeter">the number to rise 10 to the power over</param>
92-
/// </summary>
93-
public decimal ConvertToDexDecimal(decimal number, int decimals);
94-
95-
/// <summary>
96-
/// Returns the active device operating system
97-
/// </summary>
98-
public int GetSystemOs();
99-
100-
101-
/// <summary>
102-
/// Returns the device files safe path, not onwed by system OS for downloads and local settings such as imported tokens, imported networks.
103-
/// </summary>
104-
public string GetOsSavePath();
105-
106-
/// <summary>
107-
/// Opens a popup window that shows an alert
108-
/// Parameters:
109-
/// <paramref name="msg"/>
110-
/// <param name="msg">The message that has to be displayed on the screen</param>
111-
/// <paramref name="attempts"/>
112-
/// <param name="attempts">Obsolete not being utilized, part of an old API, to be removed next V</param>
113-
/// </summary>
114-
public void OpenErrorView(string title, string msg, int attempts);
115-
116-
/// <summary>
117-
/// Truncates a price to the 14th decimal to make it more user friendly
118-
/// Example 0.00000000275465465654 -> 0.0000000027
119-
/// Parameters:
120-
/// <paramref name="price"/>
121-
/// <param name="price">The input amount to be truncated, returns the same value if it's less then 14 characters.</param>
122-
/// </summary>
123-
public string TruncateDecimals(decimal price);
124-
}
125-
}
1+
using SYNCWallet.Models;
2+
3+
namespace SYNCWallet.Services.Definitions
4+
{
5+
public interface IUtilities
6+
{
7+
/// <summary>
8+
/// Returns a list of NetworkSettings, executes a query against the main github repository
9+
/// retruves the officially supported networks and then checks if there are any local networks returns the combined result
10+
/// </summary>
11+
public Task<List<NetworkSettings>> SetupNetworks();
12+
13+
/// <summary>
14+
/// Returns the result of a Generic GET request as a model of T
15+
/// Parameters:
16+
/// <paramref name="url"/>
17+
/// <param name="url">The weboage url to get, must be a JSON that matches the T properties.</param>
18+
/// </summary>
19+
public Task<T> GetRequest<T>(string url);
20+
21+
/// <summary>
22+
/// Splits a string to equal chunks
23+
/// Parameters:
24+
/// <paramref name="str"/>
25+
/// <param name="str">The original string that has to be split to equal chunks</param>
26+
/// <paramref name="chunkSize"/>
27+
/// <param name="chunkSize">The number of piaces that the string has to be broken to</param>
28+
/// </summary>
29+
public IEnumerable<string> Split(string str, int chunkSize);
30+
31+
/// <summary>
32+
/// Converts a binary to string
33+
/// Example: 101-> 1
34+
/// Parameters:
35+
/// <paramref name="data"/>
36+
/// <param name="data">Any text UTF 8 encoded</param>
37+
/// </summary>
38+
public string BinaryToString(string data);
39+
40+
/// <summary>
41+
/// Converts a string to binary
42+
/// Example: 1-> 101
43+
/// Parameters:
44+
/// <param name="data">Any text UTF 8 encoded</param>
45+
/// </summary>
46+
public string StringToBinary(string data);
47+
48+
49+
/// <summary>
50+
/// Multiplies the value to the 10 of the power of the delimiter,
51+
/// used for interaction with solidity smart contracts.
52+
/// Parameters:
53+
/// <paramref name="value"/>
54+
/// <param name="value">The value that has to be multiplied</param>
55+
/// <paramref name="delimeter"/>
56+
/// <param name="delimeter">the number to rise 10 to the power over</param>
57+
/// </summary>
58+
public decimal SetDecimalPoint(decimal value, int delimeter);
59+
60+
/// <summary>
61+
/// Divides the value to the 10 of the power of the delimiter,
62+
/// used for interaction with solidity smart contracts.
63+
/// Parameters:
64+
/// <paramref name="value"/>
65+
/// <param name="value">The value that has to be multiplied</param>
66+
/// <paramref name="delimeter"/>
67+
/// <param name="delimeter">the number to rise 10 to the power over</param>
68+
/// </summary>
69+
public decimal ConvertToDex(decimal value, int delimeter);
70+
71+
72+
/// <summary>
73+
/// Multiplies the value to the 10 of the power of the delimiter,
74+
/// used for interaction with solidity smart contracts.
75+
/// Parameters:
76+
/// <paramref name="value"/>
77+
/// <param name="value">The value that has to be multiplied BigInteger</param>
78+
/// <paramref name="delimeter"/>
79+
/// <param name="delimeter">the number to rise 10 to the power over</param>
80+
/// </summary>
81+
public decimal ConvertToBigIntDex(System.Numerics.BigInteger value, int delimeter);
82+
83+
84+
/// <summary>
85+
/// Divides the value to the 10 of the power of the delimiter,
86+
/// used for interaction with solidity smart contracts.
87+
/// Parameters:
88+
/// <paramref name="value"/>
89+
/// <param name="value">The value that has to be multiplied</param>
90+
/// <paramref name="delimeter"/>
91+
/// <param name="delimeter">the number to rise 10 to the power over</param>
92+
/// </summary>
93+
public decimal ConvertToDexDecimal(decimal number, int decimals);
94+
95+
/// <summary>
96+
/// Returns the active device operating system
97+
/// </summary>
98+
public int GetSystemOs();
99+
100+
101+
/// <summary>
102+
/// Returns the device files safe path, not onwed by system OS for downloads and local settings such as imported tokens, imported networks.
103+
/// </summary>
104+
public string GetOsSavePath();
105+
106+
/// <summary>
107+
/// Opens a popup window that shows an alert
108+
/// Parameters:
109+
/// <paramref name="msg"/>
110+
/// <param name="msg">The message that has to be displayed on the screen</param>
111+
/// <paramref name="attempts"/>
112+
/// <param name="attempts">Obsolete not being utilized, part of an old API, to be removed next V</param>
113+
/// </summary>
114+
public void OpenErrorView(string title, string msg, int attempts);
115+
116+
/// <summary>
117+
/// Truncates a price to the 14th decimal to make it more user friendly
118+
/// Example 0.00000000275465465654 -> 0.0000000027
119+
/// Parameters:
120+
/// <paramref name="price"/>
121+
/// <param name="price">The input amount to be truncated, returns the same value if it's less then 14 characters.</param>
122+
/// </summary>
123+
public string TruncateDecimals(decimal price);
124+
125+
/// <summary>
126+
/// Starts a system process to launch the default user browser
127+
/// Parameters:
128+
/// <paramref name="url"/>
129+
/// <param name="url">The webpage address that has to be opened..</param>
130+
/// </summary>
131+
public void OpenBrowser(string url);
132+
}
133+
}

Services/Implementation/Utilities.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using SYNCWallet.Services.Definitions;
44
using System.Diagnostics;
55
using System.Numerics;
6+
using System.Runtime.InteropServices;
67
using System.Text;
78

89
namespace SYNCWallet.Services.Implementation
@@ -176,7 +177,34 @@ public string TruncateDecimals(decimal price)
176177
return data.Substring(0, 14); //Truncate to the 14th character
177178
}
178179

179-
180+
public void OpenBrowser(string url)
181+
{
182+
try
183+
{
184+
Process.Start(url);
185+
}
186+
catch
187+
{
188+
// hack because of this: https://github.com/dotnet/corefx/issues/10361
189+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
190+
{
191+
url = url.Replace("&", "^&");
192+
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
193+
}
194+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
195+
{
196+
Process.Start("xdg-open", url);
197+
}
198+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
199+
{
200+
Process.Start("open", url);
201+
}
202+
else
203+
{
204+
throw;
205+
}
206+
}
207+
}
180208

181209
}
182210
}

0 commit comments

Comments
 (0)