-
Notifications
You must be signed in to change notification settings - Fork 33.4k
Render avatar for Accounts #200390
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
base: main
Are you sure you want to change the base?
Render avatar for Accounts #200390
Conversation
@@ -233,7 +233,7 @@ export class GitHubServer implements IGitHubServer { | |||
try { | |||
const json = await result.json(); | |||
this._logger.info('Got account info!'); | |||
return { id: json.id, accountName: json.login }; | |||
return { id: json.id, accountName: json.login, avatar: json.avatar_url }; |
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.
Does this come back when we ask for user:email
scope or do we need it to have read:user
?
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.
Based on the GitHub docs: "If the authenticated user is authenticated through OAuth without the user scope, then the response lists only public profile information."
Since a users profile picture is publicly available information. I expect that we can get it just with user:email
.
To be sure. I just changed from source that we do not request read:user
, and indeed I got back the avatar nicely.
If you want to call this out of scope for this PR, I am ok with that... that said, it's probably not a crazy amount of work on top of this item. |
I would love it if this image is cached locally somehow so that if I get on a plane, the icon doesn't change. |
Good points. I will try to tackle MS as part of this PR. |
If you don't cache the image, at the very least verify that while offline it shows something reasonable |
Tried to wire up the image for the MS account. However Copilot says that this can only be obtained through MS Graph (and browsing the internet confirms this). I remember you told me that we can not access the MS graph due to us creating our account with a type that does not have MS Graph support. Let me know if I am missing something here? For context, here's Copilot: Please note that you need to have the User.Read permission in your Azure AD app registration to access the user's profile photo, and the user needs to have granted this permission during the sign-in process. Here's a basic example of how you can do this in TypeScript:" import fetch from 'node-fetch';
async function getProfilePhoto(accessToken: string) {
const response = await fetch('https://graph.microsoft.com/v1.0/me/photo/$value', {
headers: {
'Authorization': `Bearer ${accessToken}`
}
});
if (!response.ok) {
throw new Error('Failed to get profile photo');
}
const blob = await response.blob();
const url = URL.createObjectURL(blob);
return url;
} |
Yeah this gets a little tricky... it's doable, but maybe skip Microsoft auth for now. |
I think I got this into a decent state -> ready for review. But I plan to merge this in January. Here's a demo. Tomorrow I will show in Zurich and share in Slack for feedback: Screen.Recording.2023-12-19.at.16.19.31.movTo-do list:
|
💯 , should it be "Show Avatar" in the menu? |
@bpasero thanks, I like your suggested wording better - updating. |
fyi @bpasero on potential advice
Some follow ups for Jan:
|
[like] Peter Rasborg reacted to your message:
…________________________________
From: Tyler James Leonhardt ***@***.***>
Sent: Wednesday, December 20, 2023 6:11:34 PM
To: microsoft/vscode ***@***.***>
Cc: Subscribed ***@***.***>
Subject: Re: [microsoft/vscode] Render avatar for Accounts (PR #200390)
Some follow ups for Jan:
* make sure vscode.dev is happy with where you put the icon
* follow up after this PR goes in, does Codespaces' embedder already have the icon and can it be fetched already while loading the Codespace?
—
Reply to this email directly, view it on GitHub<#200390 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/A6OHGTICACA6RIT5WK4AENDYKMS5NAVCNFSM6AAAAABAM7XNVKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNRUHEYTOOJSHA>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
I love this so much. Is the "Show Avatar" the default? |
|
||
const avatarId = this.storageService.get(AccountsActivityActionViewItem.AVATAR_STORAGE_KEY, StorageScope.PROFILE); | ||
// account.id is sometimes a number and sometimes a string so we need to convert to string | ||
if (account.id.toString() === avatarId || (avatarId === undefined && providerId === 'github')) { |
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 would not hardcode github
in code. Read it from product.json
protected override updateLabel(): void { | ||
super.updateLabel(); | ||
this.label.classList.toggle('show-avatar', !!this.accountForAvatar); | ||
this.label.style.setProperty('background-image', this.accountForAvatar?.iconPath ? `url("${URI.from(this.accountForAvatar.iconPath).fsPath}")` : ''); |
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.
Why is this fsPath
? Is the file stored on disk? How does this work in web version then?
@@ -523,6 +555,16 @@ export class AccountsActivityActionViewItem extends AbstractGlobalActivityAction | |||
} | |||
} | |||
|
|||
private updateActionItem(): void { |
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 not this method has to be called when
- created
- profile changed
- avatar state changed
Is this still relevant? |
Fixes #136889
To do list:
:before
element, and I want to apply custom css with image.@TylerLeonhardt if time allows feedback is welcome. I have verified that the avatar URL nicely flows from extension to renderer. Though if you are busy I am perfectly happy if you review once I figure out the
AccountsActivityActionViewItem
part.Is it ok to add an optional parameter directly in
vscode.d.ts
, or should I create a proposed file?Here's how it looks (I edited CSS directly in out of source). Here's the css I plan to use:
And when activity bar is at top.