-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Graph authentication improvements #2035
Graph authentication improvements #2035
Conversation
* Makes v2 MSAL default authentication provider * Updates Microsoft.Graph to package 1.8.1 * Updates Microsoft.Identity.Client to 1.1.2-preview0008
…matted file size.
We no longer ask the user for an MSA/O365 account provider.
adds section for testing in Sample app.
/// <summary> | ||
/// Gets the smallest available thumbnail for the object | ||
/// </summary> | ||
public string Thumbnail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a Uri vs. a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the XAML binding to Image.Source works as a string, I suggest letting it fly as is, and if folks need it as a URI, let them convert it as needed. Not gonna fall on my sword over it though.
{ | ||
get | ||
{ | ||
return _path; | ||
var size = _fileSize.HasValue ? _fileSize.Value : 0; | ||
if (size < 1024) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR #2055 was doing something similar, could we make this an extension for long?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They started pulling it out here: https://github.com/Microsoft/WindowsCommunityToolkit/pull/2055/files#diff-e62611f48a9fc0cbaed40c2e841f0b25R30, but we should coordinate on needs/formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this implementation is fine the way it is here, let's pull it out in a different PR if needed
{ | ||
_thumbnail = string.Empty; | ||
} | ||
}).Wait(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't like doing this, but I can't think of anything that will have the same behavior (lazy loaded async property). @nmetulev ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. wouldn't this block the UI? Should we just have an asynchronous method to retrieve Thumbnails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is the best approach. But what if the developer wants to bind an image's Source property to it? I hate every since solution that I can think for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect the developer to add it to their view model that extends INotifyProperty - seems like the cleanest approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is lazy load, which is nice, since we don't want every thumbnail to load all the time, but when you'll get it when you ask for it without overhead on the client side. It will prevent the get from completing while the request is in process but other UI thread actions will continue while the request is in process... so you can bind to it without issue. If you run it, the result is a generally pleasant experience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GraniteStateHacker If you bind directly to it, it will block the UI Thread for as long as that GetThumbnailSetAsync method takes to do the request. Just remove that and add a Task.Delay(10000), to test it.
It is lazy loading it, but it is still blocking the UI Thread until it does it (that's what the .Wait() is doing).
This class is a Model, not a ViewModel, so it should not be bind directly to. Properties should return immediately (<50ms). This property should be replaced by a method that returns a Task, this way, the developer can wait for it's completion and create their own VM that handles that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, sorry, I was forgetting that Task.Run doesn't keep you on the UI thread, so it doesn't matter that the await is used within it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Once you remove this property @GraniteStateHacker , I think we should be good to go.
@@ -23,98 +26,89 @@ namespace Microsoft.Toolkit.Services.OneDrive | |||
/// <summary> | |||
/// GraphOneDriveStorageItem class. | |||
/// </summary> | |||
public class OneDriveStorageItem | |||
public class OneDriveStorageItem : INotifyPropertyChanged |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels weird extending INotifyPropertyChanged
for just one property. This is a model level class so I don't think we should be extending the interface at all. How do you feel about removing the Thumbnail property and adding a return value to the GetThumbnailAsync
method so the developer can create their own ViewModel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrestled with this, myself, but decided that we're already binding to the class in the UI, now... I felt my choices were to either make the class support the interface, or build out a new viewmodel. The latter felt like overkill, too, but I really wanted to allow the user to continue to bind to the property, as we're already exemplifying, and achieve the expected result. Again, not gonna fall on my sword over it, but that was my rationale... if you still feel it needs to go, lemme know and I'll get it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this, but I still think is the best solution. Only thing I would change is that now you don't need the Method... Lazy loading (fire and forget, so no .Wait()) would be perfect as it would update the UI when needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me check in that tweak just to see what it looks like, and to make sure I understand you. (will pull it back out if I misunderstood).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You just need to handle multiple requests (don't do them), and make sure you are on the UI thread when you set the variable back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok... had to tweak a condition logic bug, but that makes it behave relatively nicely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The project is not building. Remember that the Services project is using multi-targeting. This means that you can't use the namespace 'Windows' on it. Don't dispatch the call to the UI Thread if you are not on Windows 10. Wrap everything that uses that namespace on a #if WINRT. Also, never use async void. Change that method to "async Task" (still don't await or .Wait() on it, so it still is a fire and forget method) and return the newValue variable. This makes it possible to await that operation if you are not binding to pre property, but you want it's value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotta admit, the thought that any part of this might be targeting anything other than Windows 10 never crossed my mind. Feeling a bit outta touch... sorry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is a good reason to go the route of the separate viewmodel. I'll refactor.
…and found a reasonable place to lazy load it from the calling side.
@@ -83,5 +93,30 @@ public OneDriveStorageFile(IBaseClient graphProvider, IBaseRequestBuilder reques | |||
var renameItem = await base.RenameAsync(desiredName, cancellationToken); | |||
return InitializeOneDriveStorageFile(renameItem.OneDriveItem); | |||
} | |||
|
|||
/// <summary> | |||
/// gets the smallest available thumbnail url as string for the OneDrive file item, asyncrounously, and applies it to the Thumbnail property. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upper case. I would rename this method. It's a "Get" method that does not return anything(aside from the Task). Either make it return a Task < string > (and then do both, update the property and return the value) or change it to be a Task UpdateThumbnailPropertyAsync();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the last comment. I promise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL Gotta say, thumbnails seem wildly disproportionately difficult for the value it feels like they provide.
Issue: #
Related to requests by Adam Braden & team at Microsoft (by individual request)
PR Type
What kind of change does this PR introduce?
Enhancement