Skip to content

Commit 7111318

Browse files
authored
Refactoring + JumpList fixes (#2087)
1 parent d2b4d25 commit 7111318

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

Files/App.xaml.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
using Windows.ApplicationModel;
2424
using Windows.ApplicationModel.Activation;
2525
using Windows.ApplicationModel.AppService;
26+
using Windows.ApplicationModel.Core;
27+
using Windows.Foundation.Metadata;
2628
using Windows.Storage;
2729
using Windows.UI.Core;
2830
using Windows.UI.Notifications;
@@ -71,8 +73,8 @@ public App()
7173
Suspending += OnSuspending;
7274
LeavingBackground += OnLeavingBackground;
7375
// Initialize NLog
74-
Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
75-
NLog.LogManager.Configuration.Variables["LogPath"] = storageFolder.Path;
76+
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
77+
LogManager.Configuration.Variables["LogPath"] = storageFolder.Path;
7678

7779
StartAppCenter();
7880
}
@@ -86,7 +88,7 @@ private async void StartAppCenter()
8688
var lines = await FileIO.ReadTextAsync(file);
8789
obj = JObject.Parse(lines);
8890
}
89-
catch (Exception e)
91+
catch
9092
{
9193
return;
9294
}
@@ -142,7 +144,7 @@ private async void Connection_RequestReceived(AppServiceConnection sender, AppSe
142144
var changeType = (string)args.Request.Message["Type"];
143145
var newItem = JsonConvert.DeserializeObject<ShellFileItem>(args.Request.Message.Get("Item", ""));
144146
Debug.WriteLine("{0}: {1}", folderPath, changeType);
145-
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
147+
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
146148
{
147149
// If we are currently displaying the reycle bin lets refresh the items
148150
if (CurrentInstance.FilesystemViewModel?.CurrentFolder?.ItemPath == folderPath)
@@ -186,7 +188,7 @@ private void CoreWindow_PointerPressed(CoreWindow sender, PointerEventArgs args)
186188

187189
public static void UnpinItem_Click(object sender, RoutedEventArgs e)
188190
{
189-
if (rightClickedItem.Path.Equals(App.AppSettings.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
191+
if (rightClickedItem.Path.Equals(AppSettings.RecycleBinPath, StringComparison.OrdinalIgnoreCase))
190192
{
191193
AppSettings.PinRecycleBinToSideBar = false;
192194
}
@@ -212,7 +214,7 @@ protected override async void OnLaunched(LaunchActivatedEventArgs e)
212214

213215
Logger.Info("App launched");
214216

215-
bool canEnablePrelaunch = Windows.Foundation.Metadata.ApiInformation.IsMethodPresent("Windows.ApplicationModel.Core.CoreApplication", "EnablePrelaunch");
217+
bool canEnablePrelaunch = ApiInformation.IsMethodPresent("Windows.ApplicationModel.Core.CoreApplication", "EnablePrelaunch");
216218

217219
// Do not repeat app initialization when the Window already has content,
218220
// just ensure that the window is active
@@ -272,7 +274,7 @@ private void CoreWindow_Activated(CoreWindow sender, WindowActivatedEventArgs ar
272274

273275
private void Window_BackRequested(object sender, BackRequestedEventArgs e)
274276
{
275-
if (App.CurrentInstance.ContentFrame.CanGoBack)
277+
if (CurrentInstance.ContentFrame.CanGoBack)
276278
{
277279
e.Handled = true;
278280
NavigationActions.Back_Click(null, null);
@@ -404,7 +406,7 @@ protected override async void OnActivated(IActivatedEventArgs args)
404406

405407
private void TryEnablePrelaunch()
406408
{
407-
Windows.ApplicationModel.Core.CoreApplication.EnablePrelaunch(true);
409+
CoreApplication.EnablePrelaunch(true);
408410
}
409411

410412
/// <summary>

Files/Helpers/JumpListManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public async void AddFolderToJumpList(string path)
4545

4646
private Task AddFolder(string path)
4747
{
48-
if (!JumpListItemPaths.Contains(path) && _instance != null)
48+
if (_instance != null && !JumpListItemPaths.Contains(path))
4949
{
5050
string displayName;
5151
if (path.Equals(App.AppSettings.DesktopPath, StringComparison.OrdinalIgnoreCase))

Files/View Models/ItemViewModel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ public async Task SetWorkingDirectory(string value)
7272
return;
7373
}
7474

75-
App.JumpList.AddFolderToJumpList(value);
76-
7775
INavigationControlItem item = null;
7876
List<INavigationControlItem> sidebarItems = MainPage.sideBarItems.Where(x => !string.IsNullOrWhiteSpace(x.Path)).ToList();
7977

@@ -120,6 +118,10 @@ public async Task SetWorkingDirectory(string value)
120118
{
121119
_currentStorageFolder = null;
122120
}
121+
else
122+
{
123+
App.JumpList.AddFolderToJumpList(value);
124+
}
123125

124126
NotifyPropertyChanged(nameof(WorkingDirectory));
125127
}

0 commit comments

Comments
 (0)