Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions desktop/internal/i18n/shared.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions desktop/internal/settingswindow/github_account_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ type GitHubAccount struct {
SignOut func()
}

// GitHubState is what the card shows: whether sign-in is configured, whether an account is
// GitHubState is what the card shows: whether this build can reach GitHub, whether an account is
// connected and as whom, and the device authorization in progress with its user code.
type GitHubState struct {
// Available is whether the kernel plans GitHub requests; without it the card offers no sign-in.
Available bool
Connected bool
Login string
Expand Down Expand Up @@ -59,7 +60,7 @@ func (w *window) gitHubCard(c ui.C, language i18n.Language, account *GitHubAccou
ui.Text(c, i18n.Shared(language, "desktop.github.working"))
default:
if !state.Available {
ui.Text(c, i18n.Shared(language, "desktop.github.notConfigured")).Color(w.pal.muted)
ui.Text(c, i18n.Shared(language, "desktop.github.unavailable")).Color(w.pal.muted)
} else if ui.Button(c, i18n.Shared(language, "desktop.github.signIn")).Outline().Clicked() && account.SignIn != nil {
account.SignIn()
}
Expand Down
12 changes: 7 additions & 5 deletions desktop/internal/settingswindow/version_control_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import (
"github.com/vivaui/viva/ui"
)

// versionControlPage is the Version Control page: the Git switches of the editor, the Commit
// window and the Git console. Opening the page writes nothing; a switch hands its change to
// versionControlPage is the Version Control page: the GitHub account, then the Git switches of
// the editor, the Commit window and the Git console. Opening the page writes nothing; a switch hands its change to
// the settings owner at once.
func (w *window) versionControlPage(c ui.C) {
language := w.marketLanguage()
if w.ctrl.opts.GitHub != nil {
w.gitHubCard(c, language, w.ctrl.opts.GitHub)
}
gutterTitle := i18n.Shared(language, "desktop.git.settings.gutter")
blameTitle := i18n.Shared(language, "desktop.git.settings.blame")
gutter := !w.sess.values.HideGitGutter
Expand All @@ -22,6 +19,11 @@ func (w *window) versionControlPage(c ui.C) {
changeListsTitle := i18n.Shared(language, "desktop.git.settings.changeLists")
parentsTitle := i18n.Shared(language, "desktop.git.settings.parentReferences")
w.pageScroll(c, pageVersionControl, func() {
// The account card is the page's first card, inside the scroll so it lines up and scrolls
// with the others.
if w.ctrl.opts.GitHub != nil {
w.gitHubCard(c, language, w.ctrl.opts.GitHub)
}
w.card(c, gutterTitle, i18n.Shared(language, "desktop.git.settings.gutterHelp"), func() {
if ui.Switch(c.Part("gutter"), &gutter, gutterTitle).Changed() {
w.setHideGitGutter(!gutter, false)
Expand Down
2 changes: 2 additions & 0 deletions desktop/internal/settingswindow/visual_capture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func TestVisualSettings(t *testing.T) {
Marketplace: func(context.Context) (marketplace.Snapshot, error) { return marketplace.Snapshot{}, nil },
UpdateStatus: func() UpdateStatus { return UpdateStatus{Configured: true} },
Toolchains: &scopedToolchainLoader{fakeToolchainLoader{snapshot: globalVisualToolchains()}},
// Every build can sign in to GitHub; no account is connected yet.
GitHub: &GitHubAccount{Snapshot: func() GitHubState { return GitHubState{Available: true} }},
}
w := newWindow(NewController(opts), Values{Theme: theme, Language: language.Code(), TerminalScrollback: 2000})
w.sess.page = scenario.page
Expand Down
27 changes: 17 additions & 10 deletions desktop/internal/workbench/github_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ import (
// github-device-authorization): it shows the user code, opens GitHub's verification page, polls
// until the user answers, stores the token in the platform's credential store and validates it
// with currentUser. The token never leaves this file's state and the store; the settings page
// shows the login and the phase only. The client ID is the product's public OAuth client, read
// from LITHE_GITHUB_CLIENT_ID; without one sign-in is unavailable.
// shows the login and the phase only. The client ID is the product's public OAuth client,
// built in; LITHE_GITHUB_CLIENT_ID replaces it for a fork's or a development OAuth app.

const (
// githubCredentialPlugin and githubCredentialKey name the stored token in the credential store.
githubCredentialPlugin = "github"
githubCredentialKey = "access-token"
// githubAccountTimeout bounds one validation or one start request.
githubAccountTimeout = 30 * time.Second
// githubProductClientID is Lithe's OAuth app on GitHub, the one the macOS client shipped in its
// Info.plist. The device flow is a public-client flow with no client secret, so the ID is not
// a credential and every build carries it.
githubProductClientID = "Ov23li60nlOOHwDY3MO6"
)

// githubPhase is where the sign-in stands.
Expand Down Expand Up @@ -62,9 +66,13 @@ type githubAccount struct {
// errGitHubUnavailable reports that the kernel cannot plan GitHub requests.
var errGitHubUnavailable = errors.New("GitHub is unavailable")

// githubClientID is the OAuth client of the product, or empty when none is configured.
// githubClientID is the OAuth client sign-in uses: LITHE_GITHUB_CLIENT_ID when it is set, else the
// product's.
func githubClientID() string {
return strings.TrimSpace(os.Getenv("LITHE_GITHUB_CLIENT_ID"))
if id := strings.TrimSpace(os.Getenv("LITHE_GITHUB_CLIENT_ID")); id != "" {
return id
}
return githubProductClientID
}

// githubAPI is the client that plans and sends GitHub requests, made once with the kernel.
Expand Down Expand Up @@ -124,10 +132,7 @@ func (a *App) startGitHubSignIn() {
clientID := githubClientID()
g := &a.github
g.mu.Lock()
if client == nil || clientID == "" || g.phase != githubIdle {
if clientID == "" {
g.err = i18n.Shared(a.language(), "desktop.github.notConfigured")
}
if client == nil || g.phase != githubIdle {
g.mu.Unlock()
return
}
Expand Down Expand Up @@ -252,13 +257,15 @@ type githubSnapshot struct {
err string
}

// githubAccountSnapshot copies the account for a paint.
// githubAccountSnapshot copies the account for a paint. Sign-in is available when the kernel plans
// GitHub requests; githubAPI takes the account's lock itself, so it is asked first.
func (a *App) githubAccountSnapshot() githubSnapshot {
available := a.githubAPI() != nil
g := &a.github
g.mu.Lock()
defer g.mu.Unlock()
return githubSnapshot{
available: githubClientID() != "",
available: available,
connected: g.connected,
login: g.login,
phase: g.phase,
Expand Down
29 changes: 29 additions & 0 deletions desktop/internal/workbench/github_account_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package workbench

import (
"testing"

"github.com/1lck/Lithe-IDEA/desktop/internal/core"
)

// A packaged build is launched without LITHE_GITHUB_CLIENT_ID, so sign-in must not depend on it:
// the Viva client used to read the OAuth client only from that variable and showed every user
// "GitHub sign-in is not configured for this build" on the Version Control page.
func TestGitHubSignInIsAvailableWithoutClientIDVariable(t *testing.T) {
t.Setenv("LITHE_GITHUB_CLIENT_ID", "")
if got := githubClientID(); got == "" {
t.Fatal("githubClientID() is empty without LITHE_GITHUB_CLIENT_ID; the product's OAuth client must be built in")
}
h := newHarness(t, &testKernel{Client: core.NewClient()})
if snapshot := h.app.githubAccountSnapshot(); !snapshot.available {
t.Fatalf("the Version Control page reports GitHub sign-in unavailable with a kernel that plans GitHub requests: %+v", snapshot)
}
}

// LITHE_GITHUB_CLIENT_ID still replaces the built-in client, for a fork's or a development OAuth app.
func TestGitHubClientIDVariableReplacesBuiltInClient(t *testing.T) {
t.Setenv("LITHE_GITHUB_CLIENT_ID", " dev-client ")
if got := githubClientID(); got != "dev-client" {
t.Fatalf("githubClientID() = %q, want the trimmed variable %q", got, "dev-client")
}
}
1 change: 0 additions & 1 deletion shared/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -10636,7 +10636,6 @@
"desktop.github.enterCode": "Enter this code on GitHub:",
"desktop.github.cancelSignIn": "Cancel",
"desktop.github.working": "Connecting to GitHub…",
"desktop.github.notConfigured": "GitHub sign-in is not configured for this build.",
"desktop.github.expired": "The code expired before it was entered on GitHub. Try again.",
"desktop.github.denied": "The authorization was denied on GitHub.",
"desktop.github.failed": "GitHub sign-in failed: {reason}",
Expand Down
1 change: 0 additions & 1 deletion shared/i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -10636,7 +10636,6 @@
"desktop.github.enterCode": "在 GitHub 上输入此代码:",
"desktop.github.cancelSignIn": "取消",
"desktop.github.working": "正在连接 GitHub…",
"desktop.github.notConfigured": "此构建未配置 GitHub 登录。",
"desktop.github.expired": "代码在 GitHub 上输入前已过期,请重试。",
"desktop.github.denied": "GitHub 上的授权被拒绝。",
"desktop.github.failed": "GitHub 登录失败:{reason}",
Expand Down
7 changes: 0 additions & 7 deletions shared/i18n/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -11007,13 +11007,6 @@
"desktop"
]
},
{
"id": "desktop.github.notConfigured",
"description": "Shown when this build has no GitHub OAuth client",
"platforms": [
"desktop"
]
},
{
"id": "desktop.github.openFailed",
"description": "Notice when the pull request page could not be opened in the browser",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"evidence": [
"docs/viva-migration.md",
"desktop/internal/workbench/github_account.go",
"desktop/internal/workbench/github_account_test.go",
"desktop/internal/githubapi/device.go",
"desktop/internal/core/github.go",
"desktop/internal/settingswindow/github_account_view.go"
Expand All @@ -20,14 +21,15 @@
"evidence": [
"docs/viva-migration.md",
"desktop/internal/workbench/github_account.go",
"desktop/internal/workbench/github_account_test.go",
"desktop/internal/githubapi/device.go",
"desktop/internal/core/github.go",
"desktop/internal/settingswindow/github_account_view.go"
]
},
"owner": "GitHub",
"verification": "使用可控时钟验证待授权、退避、过期和成功授权;实际 GitHub OAuth 与钥匙串流程仍需在 macOS 上验收。",
"notes": "Viva:GitHub 设备码登录:显示用户码并打开验证页,按服务器给的间隔轮询,处理 slow_down 退避与过期(githubapi/device.go),令牌存平台凭据库并用 currentUser 校验,设置页只显示登录名和阶段。OAuth client ID 从 LITHE_GITHUB_CLIENT_ID 读取,未配置时登录不可用。没有专门的自动化测试。",
"notes": "Viva:GitHub 设备码登录:显示用户码并打开验证页,按服务器给的间隔轮询,处理 slow_down 退避与过期(githubapi/device.go),令牌存平台凭据库并用 currentUser 校验,设置页只显示登录名和阶段。OAuth client ID 内置为产品的 OAuth App(与旧 macOS 客户端 Info.plist 相同),LITHE_GITHUB_CLIENT_ID 只用于换成 fork 或开发用的 OAuth App;设置页是否可登录只取决于内核能否规划 GitHub 请求,github_account_test.go 覆盖未设该变量时仍可登录。设备码流程本身没有专门的自动化测试。",
"legacy": {
"revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36",
"macos": {
Expand Down
Loading