Skip to content

Commit

Permalink
feat(tiles): Update tiles every 15 minutes.
Browse files Browse the repository at this point in the history
  • Loading branch information
filiphsps committed Dec 13, 2021
1 parent 3a7b949 commit dc70ce9
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 14 deletions.
5 changes: 3 additions & 2 deletions Shell.Controls/AppListLayoutControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@

<Grid.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem x:Name="PinToStartBtn" Text="Pin to Start" Icon="Pin"/>
<MenuFlyoutItem x:Name="UninstallBtn" Text="Uninstall" Icon="Delete"/>
<!-- TODO: replace with "Unpin from Start" if it's pinned already -->
<MenuFlyoutItem x:Name="PinToStartBtn" Text="Pin to Start" Icon="Pin" Click="PinToStartBtn_Click"/>
<MenuFlyoutItem x:Name="UninstallBtn" Text="Uninstall" Icon="Delete" IsEnabled="False"/>
</MenuFlyout>
</Grid.ContextFlyout>
</Grid>
Expand Down
10 changes: 8 additions & 2 deletions Shell.Controls/AppListLayoutControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public AppListLayoutControl() {
public void Control_OnReady() {
Debug.WriteLine("[AppListLayout] OnReady!");

/* this.ItemsSource.CollectionChanged += (Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) => {
this.ItemsSource.CollectionChanged += (Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) => {
this.AppsSource.Source = from c in this.ItemsSource group c by c.DisplayName[0].ToString().ToUpper();
}; */
};

this.AppsSource.Source = from c in this.ItemsSource group c by c.DisplayName[0].ToString().ToUpper();
this.Control_SizeChanged(null, null);
Expand Down Expand Up @@ -90,5 +90,11 @@ private void AppsListItem_Tapped(Object sender, TappedRoutedEventArgs e) {
if (this.ToggleVisibility != null)
this.ToggleVisibility();
}

private void PinToStartBtn_Click(Object sender, RoutedEventArgs e) {
var localItem = (TileModel)((MenuFlyoutItem)sender).DataContext;
var item = this.ItemsSource.First(i => i.AppId == localItem.AppId);
item.IsPinned = true;
}
}
}
2 changes: 2 additions & 0 deletions Shell.Controls/LiveTilesLayoutControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:media="using:Windows.UI.Xaml.Media"
xmlns:common="using:Shell.Controls.Common"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
Expand Down Expand Up @@ -89,6 +90,7 @@
<MenuFlyoutItem x:Name="WideOpt" Text="Wide" Click="LiveTileContext_Click"/>
<MenuFlyoutItem x:Name="LargeOpt" Text="Large" Click="LiveTileContext_Click"/>
<MenuFlyoutSeparator/>
<MenuFlyoutItem x:Name="UnPin" Icon="UnPin" Text="Unpin from Start" Click="UnPin_Click"/>
</MenuFlyout>
</Grid.ContextFlyout>
</Grid>
Expand Down
37 changes: 32 additions & 5 deletions Shell.Controls/LiveTilesLayoutControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,18 @@ public LiveTilesLayoutControl() {

public void Control_OnReady() {
Debug.WriteLine("[LiveTilesLayout] OnReady!");
this.LiveTiles.ItemsSource = this.ItemsSource;
this.UpdateItemsSource();
this.ItemsSource.CollectionChanged += (Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) => {
this.UpdateItemsSource();
};

this.Control_SizeChanged(null, null);
}

public void UpdateItemsSource() {
this.LiveTiles.ItemsSource = this.ItemsSource.Where(x => x.IsPinned).ToList();
}

private void Control_SizeChanged(Object sender, SizeChangedEventArgs e) {
if (this.ScreenWidth == 0) return;
if ((VariableSizedWrapGrid)this.LiveTiles.ItemsPanelRoot == null) return;
Expand Down Expand Up @@ -92,12 +100,21 @@ private void Control_SizeChanged(Object sender, SizeChangedEventArgs e) {

private async void LiveTile_Loaded(Object sender, RoutedEventArgs e) {
var item = (TileModel)((PreviewTile)sender).DataContext;
var container = (GridViewItem)this.LiveTiles.ContainerFromItem(item);
var gridItem = (Grid)container.ContentTemplateRoot;

Debug.WriteLine($"[LiveTilesLayout] LiveTile_Loaded {item.AppId} - {item.DisplayName}");

if (!item.IsPinned) {
container.SetValue(VariableSizedWrapGrid.RowSpanProperty, 0);
container.SetValue(VariableSizedWrapGrid.ColumnSpanProperty, 0);

gridItem.Width = 0;
gridItem.Height = 0;
return;
}

// Set span.
var container = (GridViewItem)this.LiveTiles.ContainerFromItem(item);
var gridItem = (Grid)container.ContentTemplateRoot;
container.SetValue(VariableSizedWrapGrid.RowSpanProperty, item.RowSpan);
container.SetValue(VariableSizedWrapGrid.ColumnSpanProperty, item.ColumnSpan);

Expand All @@ -111,7 +128,9 @@ private async void LiveTile_Loaded(Object sender, RoutedEventArgs e) {

foreach (TileDataModel data in item.TileData) {
// FIXME: Queue
tileUpdater.Update(new TileNotification(data.Payload));
try {
tileUpdater.Update(new TileNotification(data.Payload));
} catch { }
}

// TODO: handle background based on tile data,
Expand All @@ -136,7 +155,8 @@ private async void LiveTile_Tapped(Object sender, TappedRoutedEventArgs e) {
}

private async void LiveTileContext_Click(Object sender, RoutedEventArgs e) {
var item = (TileModel)((MenuFlyoutItem)sender).DataContext;
var localItem = (TileModel)((MenuFlyoutItem)sender).DataContext;
var item = this.ItemsSource.First(i => i.AppId == localItem.AppId);
PreviewTile tile = item.LiveTile;

switch (((MenuFlyoutItem)sender).Name) {
Expand Down Expand Up @@ -187,5 +207,12 @@ private async void LiveTile_Drop(Object sender, DragEventArgs e) {
tile.UpdateLayout();
await tile.UpdateAsync();
}

private void UnPin_Click(Object sender, RoutedEventArgs e) {
var localItem = (TileModel)((MenuFlyoutItem)sender).DataContext;
var item = this.ItemsSource.First(i => i.AppId == localItem.AppId);
item.IsPinned = false;
this.UpdateItemsSource();
}
}
}
3 changes: 2 additions & 1 deletion Shell.Host/StartScreen.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
Loaded="Window_Loaded"
SizeChanged="Window_SizeChanged"
Visibility="Collapsed"
LostFocus="Window_LostFocus">
LostFocus="Window_LostFocus"
Closed="Window_Closed">

<Grid>
<xamlhost:WindowsXamlHost
Expand Down
12 changes: 12 additions & 0 deletions Shell.Host/StartScreen.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Shell.Host {
public partial class StartScreen : Window {
public Action OnExit { get; set; }
public Action OnSettings { get; set; }
private System.Windows.Threading.DispatcherTimer DispatcherTimer = new System.Windows.Threading.DispatcherTimer();

public StartScreen() {
this.InitializeComponent();
Expand Down Expand Up @@ -63,6 +64,13 @@ private async void StartScreenControl_ChildChanged(Object sender, EventArgs e) {
await applicationManager.Initilize();
control.ApplicationManager = applicationManager;

this.DispatcherTimer = new System.Windows.Threading.DispatcherTimer();
this.DispatcherTimer.Tick += (Object? tickSender, EventArgs tickE) => {
_ = applicationManager.UpdateLiveTiles();
};
this.DispatcherTimer.Interval = new TimeSpan(0, 15, 0);
this.DispatcherTimer.Start();

String? userWallpaper = (String)Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", false).GetValue("WallPaper");
if (userWallpaper != null) {
StorageFile background = await StorageFile.GetFileFromPathAsync(userWallpaper);
Expand Down Expand Up @@ -118,5 +126,9 @@ private void Window_SizeChanged(Object sender, SizeChangedEventArgs e) {
private void Window_LostFocus(Object sender, RoutedEventArgs e) {
this.Visibility = Visibility.Collapsed;
}

private void Window_Closed(Object sender, EventArgs e) {
this.DispatcherTimer.Stop();
}
}
}
16 changes: 12 additions & 4 deletions Shell.LiveTilesAccessLibrary/ApplicationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,15 @@ public async Task<ObservableCollection<TileModel>> UpdateLiveTiles() {
// Get the new live tile data.
var tilesData = await this.GetLiveTilesData();

// Remove all live tiles.
this.LiveTiles.Clear();
// Update tiles if they're already loaded
if (this.LiveTiles != null && this.LiveTiles.Count > 0) {
foreach (var tile in this.LiveTiles) {
// Only update tiledata
tile.TileData = tilesData.FindAll(i => i.AppId == tile.AppId);
}

return this.LiveTiles;
}

var liveTiles = new List<TileModel>();

Expand All @@ -66,7 +73,7 @@ public async Task<ObservableCollection<TileModel>> UpdateLiveTiles() {
if (entry.DisplayInfo.DisplayName == "NoUIEntryPoints-DesignMode")
continue;
// Temporary hide ourselves
if (entry.DisplayInfo.DisplayName == "Adaptive Shell")
if (entry.DisplayInfo.DisplayName == "Adaptive Shell" || entry.DisplayInfo.DisplayName == "Adaptive Shell Preview")
continue;

ImageBrush logo = null;
Expand All @@ -87,6 +94,7 @@ public async Task<ObservableCollection<TileModel>> UpdateLiveTiles() {
} catch { }

var tile = new TileModel {
IsPinned = true,
TileData = tilesData.FindAll(i => i.AppId == entry.AppUserModelId),
Publisher = package.PublisherDisplayName,
LiveTile = new PreviewTile() {
Expand All @@ -110,7 +118,7 @@ public async Task<ObservableCollection<TileModel>> UpdateLiveTiles() {
}
}


// TODO: restore saved layout
this.LiveTiles = new ObservableCollection<TileModel>(liveTiles.OrderBy(o => o.DisplayName).ToList());
return this.LiveTiles;
}
Expand Down
1 change: 1 addition & 0 deletions Shell.LiveTilesAccessLibrary/TileModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class TileDataModel {
public class TileModel {
public String AppId { get => this.Entry.AppUserModelId; }
public String DisplayName { get => this.LiveTile.DisplayName; set => this.LiveTile.DisplayName = value; }
public Boolean IsPinned { get; set; }
public String Publisher { get; set; }
public TileSize Size { get => this.LiveTile.TileSize; set => this.LiveTile.TileSize = value; }
public PreviewTile LiveTile { get; set; }
Expand Down

0 comments on commit dc70ce9

Please sign in to comment.