Skip to content

Commit 03483ec

Browse files
committed
Fixed big bug
1 parent 2e864b0 commit 03483ec

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

TumblrThemeSelect/MainWindow.xaml.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.ComponentModel;
5+
using System.Threading.Tasks;
56
using System.Windows;
67
using System.Windows.Controls;
78
using System.Windows.Data;
89
using System.Windows.Media;
910
using System.Windows.Media.Animation;
11+
using RestSharp;
1012
using TumblrThemeSelect.Api;
1113
using TumblrThemeSelect.Val;
1214

@@ -77,16 +79,28 @@ private async void ButtonSave_Click(object sender, RoutedEventArgs e)
7779
GridLoading.Visibility = Visibility.Visible;
7880
t.Cav.CustomParams.Clear();
7981
foreach (dynamic param in StackPanelDefaultParam.Children) { t.Cav.CustomParams[param.ID] = param.Value; }
80-
await ((Val.Theme)ListBoxTheme.SelectedItem)?.ApplyTheme(CurrentTheme);
82+
var item = ((Val.Theme)ListBoxTheme.SelectedItem);
83+
await Task.Factory.StartNew(() =>
84+
{
85+
if (!CurrentTheme)
86+
{
87+
t.Cav.CustomTheme = Newtonsoft.Json.JsonConvert.DeserializeObject<Val.Theme>(t.restClient.Post(new RestRequest($"customize_api/theme/{t.Cav.Name}/{item.Id}").AddHeader("referer", "https://www.tumblr.com/customize/")).Content).ThemeCode;
88+
t.Cav.ThemeId = "0";
89+
}
90+
t.restClient.Post(new RestRequest($"customize_api/blog/{t.Cav.Name}").AddHeader("referer", $"https://www.tumblr.com/customize/{t.Cav.Name}").AddParameter("application/json", Newtonsoft.Json.JsonConvert.SerializeObject(t.Cav), ParameterType.RequestBody));
91+
});
92+
8193
BeginAnimation(WidthProperty, new DoubleAnimation(Width, 306, TimeSpan.FromSeconds(1)));
8294
GridLoading.Visibility = Visibility.Collapsed;
8395
}
8496
private void ButtonSelect_Click(object sender, RoutedEventArgs e)
8597
{
98+
CurrentTheme = false;
8699
LoadEditing(((Val.Theme)ListBoxTheme.SelectedItem)?.DefaultParams);
87100
}
88101
private void ButtonCurrentThemeSettings_Click(object sender, RoutedEventArgs e)
89102
{
103+
CurrentTheme = true;
90104
LoadEditing(t.Cav.CustomParams);
91105
}
92106
private void LoadEditing(IDictionary<string, object> data)
@@ -99,7 +113,6 @@ private void LoadEditing(IDictionary<string, object> data)
99113
else if (param.Key.StartsWith("select:")) { }
100114
else { StackPanelDefaultParam.Children.Add(new ParametrePanel(param.Key, param.Value, t, GridLoading)); }
101115
}
102-
CurrentTheme = true;
103116
GridThemes.Visibility = Visibility.Collapsed;
104117
GridCustomize.Visibility = Visibility.Visible;
105118
GridLoading.Visibility = Visibility.Collapsed;

TumblrThemeSelect/Val/Theme.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,5 @@ public class Theme
3939
private ImageSource _ImageSource;
4040
[IgnoreDataMember]
4141
public ImageSource ImageSource => _ImageSource ?? (_ImageSource = new BitmapImage(new Uri($"https://33.media.tumblr.com/themes/wide/{WideThumbnailKey}.png")) { CacheOption = BitmapCacheOption.OnLoad, DecodePixelHeight = 173, DecodePixelWidth = 260 });
42-
43-
public Task<CustomizeApiValue> ApplyTheme(bool CurrentTheme)
44-
{
45-
return Task<CustomizeApiValue>.Factory.StartNew(() =>
46-
{
47-
if (!CurrentTheme)
48-
{
49-
tumblr.Cav.CustomTheme =
50-
Newtonsoft.Json.JsonConvert.DeserializeObject<Theme>(
51-
tumblr.restClient.Post(
52-
new RestRequest($"customize_api/theme/{tumblr.Cav.Name}/{Id}").AddHeader("referer",
53-
"https://www.tumblr.com/customize/")).Content).ThemeCode;
54-
55-
}
56-
tumblr.restClient.Post(new RestRequest($"customize_api/blog/{tumblr.Cav.Name}").AddHeader("referer", $"https://www.tumblr.com/customize/{tumblr.Cav.Name}").AddParameter("application/json", Newtonsoft.Json.JsonConvert.SerializeObject(tumblr.Cav), ParameterType.RequestBody));
57-
return tumblr.Cav;
58-
});
59-
}
6042
}
6143
}

0 commit comments

Comments
 (0)