-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainPage.xaml.cs
105 lines (84 loc) · 2.63 KB
/
MainPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using CommunityToolkit.Maui.Storage;
namespace DirectSFTP;
public partial class MainPage : ContentPage
{
public List<Tuple<string, Entry>> Settings;
public MainPage()
{
InitializeComponent();
Settings = new()
{
new("Host",host),
new("Password",password),
new("Port",port),
new("Username",username)
};
foreach (var item in Settings)
{
var pref = Preferences.Default.Get(item.Item1, "");
if (pref != "")
{
item.Item2.Text = pref;
}
}
Loaded += (a, b) =>
{
Application.Current.UserAppTheme = AppTheme.Dark;
};
downloadFolderLabel.Text = SFTP.GetDownloadFolder();
}
public async void OnConnect(object sender, EventArgs ars)
{
var isConnected = Task.Run(() =>
{
try
{
bool connected = SFTP.GetInstance().Connect(host.Text, int.Parse(port.Text), username.Text, password.Text);
return connected;
}catch (Exception)
{
return false;
}
});
await DisplayAlert("Alert", "Connecting...", "OK");
var res = await isConnected;
if (Preferences.Default.Get("DownloadFolder","") == "")
{
await DisplayAlert("Alert", "You haven't selected a download folder", "OK");
}
else if (res)
{
Dispatcher.Dispatch(() => Navigation.PushAsync(new ConnectPage()));
}
else
{
await DisplayAlert("Alert", "Couldn't connect", "OK");
}
}
public async void OnSave(object sender, EventArgs ars)
{
foreach (var item in Settings)
{
Preferences.Default.Set(item.Item1, item.Item2.Text);
}
await DisplayAlert("Result", "Saved", "OK");
}
public void OnChooseDownloadLocation(object sender, EventArgs ars)
{
#if ANDROID
var intent = new Android.Content.Intent(Android.Content.Intent.ActionOpenDocumentTree);
Microsoft.Maui.ApplicationModel.Platform.CurrentActivity.StartActivityForResult(intent,70);
#else
Task.Run(async () =>
{
CancellationToken token = new();
var res = await FolderPicker.PickAsync(token);
if (res.IsSuccessful)
{
Preferences.Default.Set("DownloadFolder", res.Folder.Path);
}
Dispatcher.Dispatch(()=> downloadFolderLabel.Text = SFTP.GetDownloadFolder());
});
#endif
}
}