-
Notifications
You must be signed in to change notification settings - Fork 18
Add PR companion web view #88
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
Open
vaayne
wants to merge
1
commit into
main
Choose a base branch
from
feature/pr-webview
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import AppKit | ||
| import MoriTerminal | ||
|
|
||
| @MainActor | ||
| final class CompanionContainerController: NSViewController { | ||
| let terminalPane: CompanionToolPaneController | ||
| let pullRequestPane: PullRequestWebViewController | ||
|
|
||
| private var activeChild: NSViewController? | ||
|
|
||
| init(terminalPane: CompanionToolPaneController, pullRequestPane: PullRequestWebViewController) { | ||
| self.terminalPane = terminalPane | ||
| self.pullRequestPane = pullRequestPane | ||
| super.init(nibName: nil, bundle: nil) | ||
| } | ||
|
|
||
| @available(*, unavailable) | ||
| required init?(coder: NSCoder) { fatalError() } | ||
|
|
||
| override func loadView() { | ||
| let root = NSView() | ||
| root.wantsLayer = true | ||
| root.translatesAutoresizingMaskIntoConstraints = false | ||
| self.view = root | ||
| show(terminalPane) | ||
| } | ||
|
|
||
| func show(tool: CompanionTool) { | ||
| if tool == .pullRequest { | ||
| guard activeChild !== pullRequestPane else { return } | ||
| swap(to: pullRequestPane) | ||
| } else { | ||
| guard activeChild !== terminalPane else { return } | ||
| swap(to: terminalPane) | ||
| } | ||
| } | ||
|
|
||
| func updateAppearance(themeInfo: GhosttyThemeInfo, isKeyWindow: Bool) { | ||
| terminalPane.updateAppearance(themeInfo: themeInfo, isKeyWindow: isKeyWindow) | ||
| pullRequestPane.updateAppearance(themeInfo: themeInfo) | ||
| } | ||
|
|
||
| private func show(_ child: NSViewController) { | ||
| addChild(child) | ||
| child.view.translatesAutoresizingMaskIntoConstraints = false | ||
| view.addSubview(child.view) | ||
| NSLayoutConstraint.activate([ | ||
| child.view.topAnchor.constraint(equalTo: view.topAnchor), | ||
| child.view.leadingAnchor.constraint(equalTo: view.leadingAnchor), | ||
| child.view.trailingAnchor.constraint(equalTo: view.trailingAnchor), | ||
| child.view.bottomAnchor.constraint(equalTo: view.bottomAnchor), | ||
| ]) | ||
| activeChild = child | ||
| } | ||
|
|
||
| private func swap(to child: NSViewController) { | ||
| activeChild?.view.removeFromSuperview() | ||
| activeChild?.removeFromParent() | ||
| show(child) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import AppKit | ||
| import WebKit | ||
| import MoriTerminal | ||
|
|
||
| @MainActor | ||
| final class PullRequestWebViewController: NSViewController { | ||
| private var webView: WKWebView! | ||
| private let headerView = NSView() | ||
| private let titleLabel = NSTextField(labelWithString: "") | ||
| private let dividerView = NSView() | ||
|
|
||
| override func loadView() { | ||
| let root = NSView() | ||
| root.wantsLayer = true | ||
| root.translatesAutoresizingMaskIntoConstraints = false | ||
|
|
||
| headerView.translatesAutoresizingMaskIntoConstraints = false | ||
| headerView.wantsLayer = true | ||
|
|
||
| titleLabel.translatesAutoresizingMaskIntoConstraints = false | ||
| titleLabel.stringValue = .localized("Pull Request") | ||
| titleLabel.font = .systemFont(ofSize: 12, weight: .medium) | ||
| titleLabel.lineBreakMode = .byTruncatingTail | ||
|
|
||
| dividerView.translatesAutoresizingMaskIntoConstraints = false | ||
| dividerView.wantsLayer = true | ||
|
|
||
| let config = WKWebViewConfiguration() | ||
| let wv = WKWebView(frame: .zero, configuration: config) | ||
| wv.translatesAutoresizingMaskIntoConstraints = false | ||
| wv.underPageBackgroundColor = .clear | ||
| self.webView = wv | ||
|
|
||
| root.addSubview(headerView) | ||
| root.addSubview(dividerView) | ||
| root.addSubview(wv) | ||
| headerView.addSubview(titleLabel) | ||
|
|
||
| NSLayoutConstraint.activate([ | ||
| headerView.topAnchor.constraint(equalTo: root.topAnchor), | ||
| headerView.leadingAnchor.constraint(equalTo: root.leadingAnchor), | ||
| headerView.trailingAnchor.constraint(equalTo: root.trailingAnchor), | ||
| headerView.heightAnchor.constraint(equalToConstant: 28), | ||
|
|
||
| titleLabel.leadingAnchor.constraint(equalTo: headerView.leadingAnchor, constant: 10), | ||
| titleLabel.trailingAnchor.constraint(equalTo: headerView.trailingAnchor, constant: -10), | ||
| titleLabel.centerYAnchor.constraint(equalTo: headerView.centerYAnchor), | ||
|
|
||
| dividerView.topAnchor.constraint(equalTo: headerView.bottomAnchor), | ||
| dividerView.leadingAnchor.constraint(equalTo: root.leadingAnchor), | ||
| dividerView.trailingAnchor.constraint(equalTo: root.trailingAnchor), | ||
| dividerView.heightAnchor.constraint(equalToConstant: 1), | ||
|
|
||
| wv.topAnchor.constraint(equalTo: dividerView.bottomAnchor), | ||
| wv.leadingAnchor.constraint(equalTo: root.leadingAnchor), | ||
| wv.trailingAnchor.constraint(equalTo: root.trailingAnchor), | ||
| wv.bottomAnchor.constraint(equalTo: root.bottomAnchor), | ||
| ]) | ||
|
|
||
| self.view = root | ||
| } | ||
|
|
||
| func loadPullRequest(_ url: URL) { | ||
| titleLabel.stringValue = url.absoluteString | ||
| webView.load(URLRequest(url: url)) | ||
| } | ||
|
|
||
| func updateAppearance(themeInfo: GhosttyThemeInfo) { | ||
| view.appearance = NSAppearance(named: themeInfo.isDark ? .darkAqua : .aqua) | ||
| view.layer?.backgroundColor = themeInfo.effectiveBackground.cgColor | ||
| let blend: CGFloat = themeInfo.isDark ? 0.12 : 0.06 | ||
| let tint = themeInfo.isDark ? NSColor.white : NSColor.black | ||
| let headerBg = (themeInfo.effectiveBackground.usingColorSpace(.deviceRGB) ?? themeInfo.effectiveBackground) | ||
| .blended(withFraction: blend, of: tint) ?? themeInfo.effectiveBackground | ||
| headerView.layer?.backgroundColor = headerBg.cgColor | ||
| dividerView.layer?.backgroundColor = NSColor.separatorColor.withAlphaComponent(0.45).cgColor | ||
| titleLabel.textColor = .secondaryLabelColor | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
After
await manager.fetchCurrentPullRequestURL()returns, this block unconditionally switches the companion pane to PR and overwritescompanionToolState. If the user changes selection or opens another companion tool whilegh pr viewis still running, the stale task result can reopen/replace the current pane with an out-of-date PR. Gate these assignments on current intent (e.g., still targeting PR for the same selected worktree) before mutating UI state.Useful? React with 👍 / 👎.