From 204cef09aa94a6f8de482f811615b7a5a79d9f8c Mon Sep 17 00:00:00 2001 From: kawaiizenbo <48113593+kawaiizenbo@users.noreply.github.com> Date: Sat, 4 Feb 2023 23:45:16 -0700 Subject: [PATCH] login to the app --- LICENSE | 21 ++++++ README.md | 10 +++ WMstodon/App.xaml.cs | 2 +- WMstodon/HTTPUtils.cs | 54 ++++++++++++++ WMstodon/JSONClasses.cs | 111 ++++++++++++++++++++++++++++ WMstodon/LoginPage.xaml | 21 ++++++ WMstodon/LoginPage.xaml.cs | 74 +++++++++++++++++++ WMstodon/MainPage.xaml | 3 + WMstodon/MainPage.xaml.cs | 28 +++++-- WMstodon/SelectInstancePage.xaml | 18 +++++ WMstodon/SelectInstancePage.xaml.cs | 48 ++++++++++++ WMstodon/WMstodon.csproj | 21 +++++- 12 files changed, 404 insertions(+), 7 deletions(-) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 WMstodon/HTTPUtils.cs create mode 100644 WMstodon/JSONClasses.cs create mode 100644 WMstodon/LoginPage.xaml create mode 100644 WMstodon/LoginPage.xaml.cs create mode 100644 WMstodon/SelectInstancePage.xaml create mode 100644 WMstodon/SelectInstancePage.xaml.cs diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..abecc82 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 KawaiiZenbo + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e7a816a --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# WMstodon +Mastodon client for Windows 10 Mobile made without API Libraries + +## Requirements + - Windows 10 Creators Update (version 1703) or later (or Windows 11) + The app is intended to be used on Windows Mobile but will work on desktop as well + +### For Building + - Visual Studio 2017 (last version for building Windows Mobile apps) + - Windows 10 SDK 10.0.15063 diff --git a/WMstodon/App.xaml.cs b/WMstodon/App.xaml.cs index 4bed0bc..9d6ae8b 100644 --- a/WMstodon/App.xaml.cs +++ b/WMstodon/App.xaml.cs @@ -66,7 +66,7 @@ namespace WMstodon // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter - rootFrame.Navigate(typeof(MainPage), e.Arguments); + rootFrame.Navigate(typeof(SelectInstancePage), e.Arguments); } // Ensure the current window is active Window.Current.Activate(); diff --git a/WMstodon/HTTPUtils.cs b/WMstodon/HTTPUtils.cs new file mode 100644 index 0000000..75912b9 --- /dev/null +++ b/WMstodon/HTTPUtils.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading.Tasks; + +using Windows.Storage; + +namespace WMstodon +{ + class HTTPUtils + { + static ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; + // still usin em + public static async Task> GETAsync(string URL) + { + HttpClient httpClient = new HttpClient(); + httpClient.BaseAddress = new Uri((string)localSettings.Values["instanceURL"]); + httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", (string)localSettings.Values["accessToken"]); + HttpResponseMessage response = await httpClient.GetAsync(URL); + httpClient.Dispose(); + return new KeyValuePair(response.StatusCode, await response.Content.ReadAsStringAsync()); + } + + public static async Task> GETGenericAsync(string URL) + { + HttpClient generic = new HttpClient(); + generic.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", (string)localSettings.Values["accessToken"]); + HttpResponseMessage response = await generic.GetAsync(URL); + generic.Dispose(); + return new KeyValuePair(response.StatusCode, await response.Content.ReadAsStringAsync()); + } + + public static async Task> POSTAsync(string URL, HttpContent data) + { + HttpClient httpClient = new HttpClient(); + httpClient.BaseAddress = new Uri((string)localSettings.Values["instanceURL"]); + httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", (string)localSettings.Values["accessToken"]); + HttpResponseMessage response = await httpClient.PostAsync(URL, data); + httpClient.Dispose(); + return new KeyValuePair(response.StatusCode, await response.Content.ReadAsStringAsync()); + } + + public static async Task> POSTGenericAsync(string URL, HttpContent data) + { + HttpClient generic = new HttpClient(); + generic.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", (string)localSettings.Values["accessToken"]); + HttpResponseMessage response = await generic.PostAsync(URL, data); + generic.Dispose(); + return new KeyValuePair(response.StatusCode, await response.Content.ReadAsStringAsync()); + } + } +} diff --git a/WMstodon/JSONClasses.cs b/WMstodon/JSONClasses.cs new file mode 100644 index 0000000..ce7b4b5 --- /dev/null +++ b/WMstodon/JSONClasses.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WMstodon +{ + public class Account + { + public string id { get; set; } + public string username { get; set; } + public string acct { get; set; } + public string display_name { get; set; } + public bool locked { get; set; } + public bool bot { get; set; } + public bool discoverable { get; set; } + public bool group { get; set; } + public DateTime created_at { get; set; } + public string note { get; set; } + public string url { get; set; } + public string avatar { get; set; } + public string avatar_static { get; set; } + public string header { get; set; } + public string header_static { get; set; } + public int followers_count { get; set; } + public int following_count { get; set; } + public int statuses_count { get; set; } + public object last_status_at { get; set; } + public object source { get; set; } + public object[] emojis { get; set; } + public object[] fields { get; set; } + } + + + public class Attachment + { + public string id { get; set; } + public string type { get; set; } + public string url { get; set; } + public string preview_url { get; set; } + public string remote_url { get; set; } + public string text_url { get; set; } + public AttachmentMeta meta { get; set; } + public string description { get; set; } + public string blurhash { get; set; } + } + + public class AttachmentMeta + { + public AttachmentFocus focus { get; set; } + public AttachmentSizing original { get; set; } + public AttachmentSizing small { get; set; } + } + + public class AttachmentFocus + { + public float x { get; set; } + public float y { get; set; } + } + + public class AttachmentSizing + { + public int width { get; set; } + public int height { get; set; } + public string size { get; set; } + public float aspect { get; set; } + } + + public class Status + { + public string id { get; set; } + public DateTime created_at { get; set; } + public object in_reply_to_id { get; set; } + public object in_reply_to_account_id { get; set; } + public bool sensitive { get; set; } + public string spoiler_text { get; set; } + public string visibility { get; set; } + public string language { get; set; } + public string uri { get; set; } + public string url { get; set; } + public int replies_count { get; set; } + public int reblogs_count { get; set; } + public int favourites_count { get; set; } + public bool favourited { get; set; } + public bool reblogged { get; set; } + public bool muted { get; set; } + public bool bookmarked { get; set; } + public string content { get; set; } + public object reblog { get; set; } + public MApplication application { get; set; } + public Account account { get; set; } + public Attachment[] media_attachments { get; set; } + public object[] mentions { get; set; } + public object[] tags { get; set; } + public object[] emojis { get; set; } + public object card { get; set; } + public object poll { get; set; } + } + + public class Feed + { + public Status[] statuses { get; set; } + } + + public class MApplication + { + public string name { get; set; } + public string website { get; set; } + } +} diff --git a/WMstodon/LoginPage.xaml b/WMstodon/LoginPage.xaml new file mode 100644 index 0000000..ec57bf2 --- /dev/null +++ b/WMstodon/LoginPage.xaml @@ -0,0 +1,21 @@ + + + + +