Merge remote-tracking branch 'origin/main' into replies
This commit is contained in:
@@ -8,7 +8,7 @@ use collections::{HashMap, HashSet};
|
||||
use editor::{
|
||||
display_map::{BlockDisposition, BlockId, BlockProperties, BlockStyle, ToDisplayPoint},
|
||||
scroll::autoscroll::{Autoscroll, AutoscrollStrategy},
|
||||
Anchor, Editor,
|
||||
Anchor, Editor, ToOffset,
|
||||
};
|
||||
use fs::Fs;
|
||||
use futures::{io::BufReader, AsyncBufReadExt, AsyncReadExt, Stream, StreamExt};
|
||||
@@ -1303,8 +1303,14 @@ impl AssistantEditor {
|
||||
|
||||
fn split(&mut self, _: &Split, cx: &mut ViewContext<Self>) {
|
||||
self.assistant.update(cx, |assistant, cx| {
|
||||
let range = self.editor.read(cx).selections.newest::<usize>(cx).range();
|
||||
assistant.split_message(range, cx);
|
||||
let selections = self.editor.read(cx).selections.disjoint_anchors();
|
||||
for selection in selections.into_iter() {
|
||||
let buffer = self.editor.read(cx).buffer().read(cx).snapshot(cx);
|
||||
let range = selection
|
||||
.map(|endpoint| endpoint.to_offset(&buffer))
|
||||
.range();
|
||||
assistant.split_message(range, cx);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,12 @@ use std::{
|
||||
},
|
||||
};
|
||||
use unindent::Unindent as _;
|
||||
use workspace::{item::ItemHandle as _, shared_screen::SharedScreen, SplitDirection, Workspace};
|
||||
use workspace::{
|
||||
dock::{test::TestPanel, DockPosition},
|
||||
item::{test::TestItem, ItemHandle as _},
|
||||
shared_screen::SharedScreen,
|
||||
SplitDirection, Workspace,
|
||||
};
|
||||
|
||||
#[ctor::ctor]
|
||||
fn init_logger() {
|
||||
@@ -6847,12 +6852,43 @@ async fn test_basic_following(
|
||||
)
|
||||
});
|
||||
|
||||
// Client B activates an external window again, and the previously-opened screen-sharing item
|
||||
// gets activated.
|
||||
active_call_b
|
||||
.update(cx_b, |call, cx| call.set_location(None, cx))
|
||||
.await
|
||||
.unwrap();
|
||||
// Client B activates a panel, and the previously-opened screen-sharing item gets activated.
|
||||
let panel = cx_b.add_view(workspace_b.window_id(), |_| {
|
||||
TestPanel::new(DockPosition::Left)
|
||||
});
|
||||
workspace_b.update(cx_b, |workspace, cx| {
|
||||
workspace.add_panel(panel, cx);
|
||||
workspace.toggle_panel_focus::<TestPanel>(cx);
|
||||
});
|
||||
deterministic.run_until_parked();
|
||||
assert_eq!(
|
||||
workspace_a.read_with(cx_a, |workspace, cx| workspace
|
||||
.active_item(cx)
|
||||
.unwrap()
|
||||
.id()),
|
||||
shared_screen.id()
|
||||
);
|
||||
|
||||
// Toggling the focus back to the pane causes client A to return to the multibuffer.
|
||||
workspace_b.update(cx_b, |workspace, cx| {
|
||||
workspace.toggle_panel_focus::<TestPanel>(cx);
|
||||
});
|
||||
deterministic.run_until_parked();
|
||||
workspace_a.read_with(cx_a, |workspace, cx| {
|
||||
assert_eq!(
|
||||
workspace.active_item(cx).unwrap().id(),
|
||||
multibuffer_editor_a.id()
|
||||
)
|
||||
});
|
||||
|
||||
// Client B activates an item that doesn't implement following,
|
||||
// so the previously-opened screen-sharing item gets activated.
|
||||
let unfollowable_item = cx_b.add_view(workspace_b.window_id(), |_| TestItem::new());
|
||||
workspace_b.update(cx_b, |workspace, cx| {
|
||||
workspace.active_pane().update(cx, |pane, cx| {
|
||||
pane.add_item(Box::new(unfollowable_item), true, true, None, cx)
|
||||
})
|
||||
});
|
||||
deterministic.run_until_parked();
|
||||
assert_eq!(
|
||||
workspace_a.read_with(cx_a, |workspace, cx| workspace
|
||||
|
||||
@@ -6,17 +6,23 @@ import ScreenCaptureKit
|
||||
class LKRoomDelegate: RoomDelegate {
|
||||
var data: UnsafeRawPointer
|
||||
var onDidDisconnect: @convention(c) (UnsafeRawPointer) -> Void
|
||||
var onDidSubscribeToRemoteAudioTrack: @convention(c) (UnsafeRawPointer, CFString, CFString, UnsafeRawPointer) -> Void
|
||||
var onDidUnsubscribeFromRemoteAudioTrack: @convention(c) (UnsafeRawPointer, CFString, CFString) -> Void
|
||||
var onDidSubscribeToRemoteVideoTrack: @convention(c) (UnsafeRawPointer, CFString, CFString, UnsafeRawPointer) -> Void
|
||||
var onDidUnsubscribeFromRemoteVideoTrack: @convention(c) (UnsafeRawPointer, CFString, CFString) -> Void
|
||||
|
||||
init(
|
||||
data: UnsafeRawPointer,
|
||||
onDidDisconnect: @escaping @convention(c) (UnsafeRawPointer) -> Void,
|
||||
onDidSubscribeToRemoteAudioTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString, UnsafeRawPointer) -> Void,
|
||||
onDidUnsubscribeFromRemoteAudioTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString) -> Void,
|
||||
onDidSubscribeToRemoteVideoTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString, UnsafeRawPointer) -> Void,
|
||||
onDidUnsubscribeFromRemoteVideoTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString) -> Void)
|
||||
{
|
||||
self.data = data
|
||||
self.onDidDisconnect = onDidDisconnect
|
||||
self.onDidSubscribeToRemoteAudioTrack = onDidSubscribeToRemoteAudioTrack
|
||||
self.onDidUnsubscribeFromRemoteAudioTrack = onDidUnsubscribeFromRemoteAudioTrack
|
||||
self.onDidSubscribeToRemoteVideoTrack = onDidSubscribeToRemoteVideoTrack
|
||||
self.onDidUnsubscribeFromRemoteVideoTrack = onDidUnsubscribeFromRemoteVideoTrack
|
||||
}
|
||||
@@ -30,12 +36,16 @@ class LKRoomDelegate: RoomDelegate {
|
||||
func room(_ room: Room, participant: RemoteParticipant, didSubscribe publication: RemoteTrackPublication, track: Track) {
|
||||
if track.kind == .video {
|
||||
self.onDidSubscribeToRemoteVideoTrack(self.data, participant.identity as CFString, track.sid! as CFString, Unmanaged.passUnretained(track).toOpaque())
|
||||
} else if track.kind == .audio {
|
||||
self.onDidSubscribeToRemoteAudioTrack(self.data, participant.identity as CFString, track.sid! as CFString, Unmanaged.passUnretained(track).toOpaque())
|
||||
}
|
||||
}
|
||||
|
||||
func room(_ room: Room, participant: RemoteParticipant, didUnsubscribe publication: RemoteTrackPublication, track: Track) {
|
||||
if track.kind == .video {
|
||||
self.onDidUnsubscribeFromRemoteVideoTrack(self.data, participant.identity as CFString, track.sid! as CFString)
|
||||
} else if track.kind == .audio {
|
||||
self.onDidUnsubscribeFromRemoteAudioTrack(self.data, participant.identity as CFString, track.sid! as CFString)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,12 +87,16 @@ class LKVideoRenderer: NSObject, VideoRenderer {
|
||||
public func LKRoomDelegateCreate(
|
||||
data: UnsafeRawPointer,
|
||||
onDidDisconnect: @escaping @convention(c) (UnsafeRawPointer) -> Void,
|
||||
onDidSubscribeToRemoteAudioTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString, UnsafeRawPointer) -> Void,
|
||||
onDidUnsubscribeFromRemoteAudioTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString) -> Void,
|
||||
onDidSubscribeToRemoteVideoTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString, UnsafeRawPointer) -> Void,
|
||||
onDidUnsubscribeFromRemoteVideoTrack: @escaping @convention(c) (UnsafeRawPointer, CFString, CFString) -> Void
|
||||
) -> UnsafeMutableRawPointer {
|
||||
let delegate = LKRoomDelegate(
|
||||
data: data,
|
||||
onDidDisconnect: onDidDisconnect,
|
||||
onDidSubscribeToRemoteAudioTrack: onDidSubscribeToRemoteAudioTrack,
|
||||
onDidUnsubscribeFromRemoteAudioTrack: onDidUnsubscribeFromRemoteAudioTrack,
|
||||
onDidSubscribeToRemoteVideoTrack: onDidSubscribeToRemoteVideoTrack,
|
||||
onDidUnsubscribeFromRemoteVideoTrack: onDidUnsubscribeFromRemoteVideoTrack
|
||||
)
|
||||
@@ -123,6 +137,18 @@ public func LKRoomPublishVideoTrack(room: UnsafeRawPointer, track: UnsafeRawPoin
|
||||
}
|
||||
}
|
||||
|
||||
@_cdecl("LKRoomPublishAudioTrack")
|
||||
public func LKRoomPublishAudioTrack(room: UnsafeRawPointer, track: UnsafeRawPointer, callback: @escaping @convention(c) (UnsafeRawPointer, UnsafeMutableRawPointer?, CFString?) -> Void, callback_data: UnsafeRawPointer) {
|
||||
let room = Unmanaged<Room>.fromOpaque(room).takeUnretainedValue()
|
||||
let track = Unmanaged<LocalAudioTrack>.fromOpaque(track).takeUnretainedValue()
|
||||
room.localParticipant?.publishAudioTrack(track: track).then { publication in
|
||||
callback(callback_data, Unmanaged.passRetained(publication).toOpaque(), nil)
|
||||
}.catch { error in
|
||||
callback(callback_data, nil, error.localizedDescription as CFString)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@_cdecl("LKRoomUnpublishTrack")
|
||||
public func LKRoomUnpublishTrack(room: UnsafeRawPointer, publication: UnsafeRawPointer) {
|
||||
let room = Unmanaged<Room>.fromOpaque(room).takeUnretainedValue()
|
||||
@@ -130,6 +156,20 @@ public func LKRoomUnpublishTrack(room: UnsafeRawPointer, publication: UnsafeRawP
|
||||
let _ = room.localParticipant?.unpublish(publication: publication)
|
||||
}
|
||||
|
||||
@_cdecl("LKRoomAudioTracksForRemoteParticipant")
|
||||
public func LKRoomAudioTracksForRemoteParticipant(room: UnsafeRawPointer, participantId: CFString) -> CFArray? {
|
||||
let room = Unmanaged<Room>.fromOpaque(room).takeUnretainedValue()
|
||||
|
||||
for (_, participant) in room.remoteParticipants {
|
||||
if participant.identity == participantId as String {
|
||||
return participant.audioTracks.compactMap { $0.track as? RemoteAudioTrack } as CFArray?
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
@_cdecl("LKRoomVideoTracksForRemoteParticipant")
|
||||
public func LKRoomVideoTracksForRemoteParticipant(room: UnsafeRawPointer, participantId: CFString) -> CFArray? {
|
||||
let room = Unmanaged<Room>.fromOpaque(room).takeUnretainedValue()
|
||||
@@ -143,6 +183,17 @@ public func LKRoomVideoTracksForRemoteParticipant(room: UnsafeRawPointer, partic
|
||||
return nil;
|
||||
}
|
||||
|
||||
@_cdecl("LKLocalAudioTrackCreateTrack")
|
||||
public func LKLocalAudioTrackCreateTrack() -> UnsafeMutableRawPointer {
|
||||
let track = LocalAudioTrack.createTrack(options: AudioCaptureOptions(
|
||||
echoCancellation: true,
|
||||
noiseSuppression: true
|
||||
))
|
||||
|
||||
return Unmanaged.passRetained(track).toOpaque()
|
||||
}
|
||||
|
||||
|
||||
@_cdecl("LKCreateScreenShareTrackForDisplay")
|
||||
public func LKCreateScreenShareTrackForDisplay(display: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer {
|
||||
let display = Unmanaged<MacOSDisplay>.fromOpaque(display).takeUnretainedValue()
|
||||
@@ -150,6 +201,19 @@ public func LKCreateScreenShareTrackForDisplay(display: UnsafeMutableRawPointer)
|
||||
return Unmanaged.passRetained(track).toOpaque()
|
||||
}
|
||||
|
||||
@_cdecl("LKRemoteAudioTrackStart")
|
||||
public func LKRemoteAudioTrackStart(track: UnsafeRawPointer, onStart: @escaping @convention(c) (UnsafeRawPointer, Bool) -> Void, callbackData: UnsafeRawPointer) {
|
||||
let track = Unmanaged<Track>.fromOpaque(track).takeUnretainedValue() as! RemoteAudioTrack
|
||||
|
||||
track.start().then { success in
|
||||
onStart(callbackData, success)
|
||||
}
|
||||
.catch { _ in
|
||||
onStart(callbackData, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@_cdecl("LKVideoRendererCreate")
|
||||
public func LKVideoRendererCreate(data: UnsafeRawPointer, onFrame: @escaping @convention(c) (UnsafeRawPointer, CVPixelBuffer) -> Bool, onDrop: @escaping @convention(c) (UnsafeRawPointer) -> Void) -> UnsafeMutableRawPointer {
|
||||
Unmanaged.passRetained(LKVideoRenderer(data: data, onFrame: onFrame, onDrop: onDrop)).toOpaque()
|
||||
@@ -169,6 +233,12 @@ public func LKRemoteVideoTrackGetSid(track: UnsafeRawPointer) -> CFString {
|
||||
return track.sid! as CFString
|
||||
}
|
||||
|
||||
@_cdecl("LKRemoteAudioTrackGetSid")
|
||||
public func LKRemoteAudioTrackGetSid(track: UnsafeRawPointer) -> CFString {
|
||||
let track = Unmanaged<RemoteAudioTrack>.fromOpaque(track).takeUnretainedValue()
|
||||
return track.sid! as CFString
|
||||
}
|
||||
|
||||
@_cdecl("LKDisplaySources")
|
||||
public func LKDisplaySources(data: UnsafeRawPointer, callback: @escaping @convention(c) (UnsafeRawPointer, CFArray?, CFString?) -> Void) {
|
||||
MacOSScreenCapturer.sources(for: .display, includeCurrentApplication: false, preferredMethod: .legacy).then { displaySources in
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use futures::StreamExt;
|
||||
use gpui::{actions, keymap_matcher::Binding, Menu, MenuItem};
|
||||
use live_kit_client::{LocalVideoTrack, RemoteVideoTrackUpdate, Room};
|
||||
use live_kit_client::{
|
||||
LocalAudioTrack, LocalVideoTrack, RemoteAudioTrackUpdate, RemoteVideoTrackUpdate, Room,
|
||||
};
|
||||
use live_kit_server::token::{self, VideoGrant};
|
||||
use log::LevelFilter;
|
||||
use simplelog::SimpleLogger;
|
||||
@@ -11,6 +15,12 @@ fn main() {
|
||||
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
|
||||
|
||||
gpui::App::new(()).unwrap().run(|cx| {
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
println!("USING TEST LIVEKIT");
|
||||
|
||||
#[cfg(not(any(test, feature = "test-support")))]
|
||||
println!("USING REAL LIVEKIT");
|
||||
|
||||
cx.platform().activate(true);
|
||||
cx.add_global_action(quit);
|
||||
|
||||
@@ -49,16 +59,14 @@ fn main() {
|
||||
let room_b = Room::new();
|
||||
room_b.connect(&live_kit_url, &user2_token).await.unwrap();
|
||||
|
||||
let mut track_changes = room_b.remote_video_track_updates();
|
||||
let mut audio_track_updates = room_b.remote_audio_track_updates();
|
||||
let audio_track = LocalAudioTrack::create();
|
||||
let audio_track_publication = room_a.publish_audio_track(&audio_track).await.unwrap();
|
||||
|
||||
let displays = room_a.display_sources().await.unwrap();
|
||||
let display = displays.into_iter().next().unwrap();
|
||||
|
||||
let track_a = LocalVideoTrack::screen_share_for_display(&display);
|
||||
let track_a_publication = room_a.publish_video_track(&track_a).await.unwrap();
|
||||
|
||||
if let RemoteVideoTrackUpdate::Subscribed(track) = track_changes.next().await.unwrap() {
|
||||
let remote_tracks = room_b.remote_video_tracks("test-participant-1");
|
||||
if let RemoteAudioTrackUpdate::Subscribed(track) =
|
||||
audio_track_updates.next().await.unwrap()
|
||||
{
|
||||
let remote_tracks = room_b.remote_audio_tracks("test-participant-1");
|
||||
assert_eq!(remote_tracks.len(), 1);
|
||||
assert_eq!(remote_tracks[0].publisher_id(), "test-participant-1");
|
||||
assert_eq!(track.publisher_id(), "test-participant-1");
|
||||
@@ -66,18 +74,60 @@ fn main() {
|
||||
panic!("unexpected message");
|
||||
}
|
||||
|
||||
let remote_track = room_b
|
||||
println!("Pausing for 5 seconds to test audio, make some noise!");
|
||||
let timer = cx.background().timer(Duration::from_secs(5));
|
||||
timer.await;
|
||||
|
||||
let remote_audio_track = room_b
|
||||
.remote_audio_tracks("test-participant-1")
|
||||
.pop()
|
||||
.unwrap();
|
||||
room_a.unpublish_track(audio_track_publication);
|
||||
if let RemoteAudioTrackUpdate::Unsubscribed {
|
||||
publisher_id,
|
||||
track_id,
|
||||
} = audio_track_updates.next().await.unwrap()
|
||||
{
|
||||
assert_eq!(publisher_id, "test-participant-1");
|
||||
assert_eq!(remote_audio_track.sid(), track_id);
|
||||
assert_eq!(room_b.remote_audio_tracks("test-participant-1").len(), 0);
|
||||
} else {
|
||||
panic!("unexpected message");
|
||||
}
|
||||
|
||||
let mut video_track_updates = room_b.remote_video_track_updates();
|
||||
let displays = room_a.display_sources().await.unwrap();
|
||||
let display = displays.into_iter().next().unwrap();
|
||||
|
||||
let local_video_track = LocalVideoTrack::screen_share_for_display(&display);
|
||||
let local_video_track_publication = room_a
|
||||
.publish_video_track(&local_video_track)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
if let RemoteVideoTrackUpdate::Subscribed(track) =
|
||||
video_track_updates.next().await.unwrap()
|
||||
{
|
||||
let remote_video_tracks = room_b.remote_video_tracks("test-participant-1");
|
||||
assert_eq!(remote_video_tracks.len(), 1);
|
||||
assert_eq!(remote_video_tracks[0].publisher_id(), "test-participant-1");
|
||||
assert_eq!(track.publisher_id(), "test-participant-1");
|
||||
} else {
|
||||
panic!("unexpected message");
|
||||
}
|
||||
|
||||
let remote_video_track = room_b
|
||||
.remote_video_tracks("test-participant-1")
|
||||
.pop()
|
||||
.unwrap();
|
||||
room_a.unpublish_track(track_a_publication);
|
||||
room_a.unpublish_track(local_video_track_publication);
|
||||
if let RemoteVideoTrackUpdate::Unsubscribed {
|
||||
publisher_id,
|
||||
track_id,
|
||||
} = track_changes.next().await.unwrap()
|
||||
} = video_track_updates.next().await.unwrap()
|
||||
{
|
||||
assert_eq!(publisher_id, "test-participant-1");
|
||||
assert_eq!(remote_track.sid(), track_id);
|
||||
assert_eq!(remote_video_track.sid(), track_id);
|
||||
assert_eq!(room_b.remote_video_tracks("test-participant-1").len(), 0);
|
||||
} else {
|
||||
panic!("unexpected message");
|
||||
|
||||
@@ -4,7 +4,7 @@ pub mod prod;
|
||||
pub use prod::*;
|
||||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
mod test;
|
||||
pub mod test;
|
||||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub use test::*;
|
||||
|
||||
@@ -21,6 +21,17 @@ extern "C" {
|
||||
fn LKRoomDelegateCreate(
|
||||
callback_data: *mut c_void,
|
||||
on_did_disconnect: extern "C" fn(callback_data: *mut c_void),
|
||||
on_did_subscribe_to_remote_audio_track: extern "C" fn(
|
||||
callback_data: *mut c_void,
|
||||
publisher_id: CFStringRef,
|
||||
track_id: CFStringRef,
|
||||
remote_track: *const c_void,
|
||||
),
|
||||
on_did_unsubscribe_from_remote_audio_track: extern "C" fn(
|
||||
callback_data: *mut c_void,
|
||||
publisher_id: CFStringRef,
|
||||
track_id: CFStringRef,
|
||||
),
|
||||
on_did_subscribe_to_remote_video_track: extern "C" fn(
|
||||
callback_data: *mut c_void,
|
||||
publisher_id: CFStringRef,
|
||||
@@ -49,7 +60,18 @@ extern "C" {
|
||||
callback: extern "C" fn(*mut c_void, *mut c_void, CFStringRef),
|
||||
callback_data: *mut c_void,
|
||||
);
|
||||
fn LKRoomPublishAudioTrack(
|
||||
room: *const c_void,
|
||||
track: *const c_void,
|
||||
callback: extern "C" fn(*mut c_void, *mut c_void, CFStringRef),
|
||||
callback_data: *mut c_void,
|
||||
);
|
||||
fn LKRoomUnpublishTrack(room: *const c_void, publication: *const c_void);
|
||||
fn LKRoomAudioTracksForRemoteParticipant(
|
||||
room: *const c_void,
|
||||
participant_id: CFStringRef,
|
||||
) -> CFArrayRef;
|
||||
|
||||
fn LKRoomVideoTracksForRemoteParticipant(
|
||||
room: *const c_void,
|
||||
participant_id: CFStringRef,
|
||||
@@ -61,6 +83,13 @@ extern "C" {
|
||||
on_drop: extern "C" fn(callback_data: *mut c_void),
|
||||
) -> *const c_void;
|
||||
|
||||
fn LKRemoteAudioTrackGetSid(track: *const c_void) -> CFStringRef;
|
||||
// fn LKRemoteAudioTrackStart(
|
||||
// track: *const c_void,
|
||||
// callback: extern "C" fn(*mut c_void, bool),
|
||||
// callback_data: *mut c_void
|
||||
// );
|
||||
|
||||
fn LKVideoTrackAddRenderer(track: *const c_void, renderer: *const c_void);
|
||||
fn LKRemoteVideoTrackGetSid(track: *const c_void) -> CFStringRef;
|
||||
|
||||
@@ -73,6 +102,7 @@ extern "C" {
|
||||
),
|
||||
);
|
||||
fn LKCreateScreenShareTrackForDisplay(display: *const c_void) -> *const c_void;
|
||||
fn LKLocalAudioTrackCreateTrack() -> *const c_void;
|
||||
}
|
||||
|
||||
pub type Sid = String;
|
||||
@@ -89,6 +119,7 @@ pub struct Room {
|
||||
watch::Sender<ConnectionState>,
|
||||
watch::Receiver<ConnectionState>,
|
||||
)>,
|
||||
remote_audio_track_subscribers: Mutex<Vec<mpsc::UnboundedSender<RemoteAudioTrackUpdate>>>,
|
||||
remote_video_track_subscribers: Mutex<Vec<mpsc::UnboundedSender<RemoteVideoTrackUpdate>>>,
|
||||
_delegate: RoomDelegate,
|
||||
}
|
||||
@@ -100,6 +131,7 @@ impl Room {
|
||||
Self {
|
||||
native_room: unsafe { LKRoomCreate(delegate.native_delegate) },
|
||||
connection: Mutex::new(watch::channel_with(ConnectionState::Disconnected)),
|
||||
remote_audio_track_subscribers: Default::default(),
|
||||
remote_video_track_subscribers: Default::default(),
|
||||
_delegate: delegate,
|
||||
}
|
||||
@@ -191,6 +223,32 @@ impl Room {
|
||||
async { rx.await.unwrap().context("error publishing video track") }
|
||||
}
|
||||
|
||||
pub fn publish_audio_track(
|
||||
self: &Arc<Self>,
|
||||
track: &LocalAudioTrack,
|
||||
) -> impl Future<Output = Result<LocalTrackPublication>> {
|
||||
let (tx, rx) = oneshot::channel::<Result<LocalTrackPublication>>();
|
||||
extern "C" fn callback(tx: *mut c_void, publication: *mut c_void, error: CFStringRef) {
|
||||
let tx =
|
||||
unsafe { Box::from_raw(tx as *mut oneshot::Sender<Result<LocalTrackPublication>>) };
|
||||
if error.is_null() {
|
||||
let _ = tx.send(Ok(LocalTrackPublication(publication)));
|
||||
} else {
|
||||
let error = unsafe { CFString::wrap_under_get_rule(error).to_string() };
|
||||
let _ = tx.send(Err(anyhow!(error)));
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
LKRoomPublishAudioTrack(
|
||||
self.native_room,
|
||||
track.0,
|
||||
callback,
|
||||
Box::into_raw(Box::new(tx)) as *mut c_void,
|
||||
);
|
||||
}
|
||||
async { rx.await.unwrap().context("error publishing video track") }
|
||||
}
|
||||
|
||||
pub fn unpublish_track(&self, publication: LocalTrackPublication) {
|
||||
unsafe {
|
||||
LKRoomUnpublishTrack(self.native_room, publication.0);
|
||||
@@ -226,12 +284,65 @@ impl Room {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remote_audio_tracks(&self, participant_id: &str) -> Vec<Arc<RemoteAudioTrack>> {
|
||||
unsafe {
|
||||
let tracks = LKRoomAudioTracksForRemoteParticipant(
|
||||
self.native_room,
|
||||
CFString::new(participant_id).as_concrete_TypeRef(),
|
||||
);
|
||||
|
||||
if tracks.is_null() {
|
||||
Vec::new()
|
||||
} else {
|
||||
let tracks = CFArray::wrap_under_get_rule(tracks);
|
||||
tracks
|
||||
.into_iter()
|
||||
.map(|native_track| {
|
||||
let native_track = *native_track;
|
||||
let id =
|
||||
CFString::wrap_under_get_rule(LKRemoteAudioTrackGetSid(native_track))
|
||||
.to_string();
|
||||
Arc::new(RemoteAudioTrack::new(
|
||||
native_track,
|
||||
id,
|
||||
participant_id.into(),
|
||||
))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remote_audio_track_updates(&self) -> mpsc::UnboundedReceiver<RemoteAudioTrackUpdate> {
|
||||
let (tx, rx) = mpsc::unbounded();
|
||||
self.remote_audio_track_subscribers.lock().push(tx);
|
||||
rx
|
||||
}
|
||||
|
||||
pub fn remote_video_track_updates(&self) -> mpsc::UnboundedReceiver<RemoteVideoTrackUpdate> {
|
||||
let (tx, rx) = mpsc::unbounded();
|
||||
self.remote_video_track_subscribers.lock().push(tx);
|
||||
rx
|
||||
}
|
||||
|
||||
fn did_subscribe_to_remote_audio_track(&self, track: RemoteAudioTrack) {
|
||||
let track = Arc::new(track);
|
||||
self.remote_audio_track_subscribers.lock().retain(|tx| {
|
||||
tx.unbounded_send(RemoteAudioTrackUpdate::Subscribed(track.clone()))
|
||||
.is_ok()
|
||||
});
|
||||
}
|
||||
|
||||
fn did_unsubscribe_from_remote_audio_track(&self, publisher_id: String, track_id: String) {
|
||||
self.remote_audio_track_subscribers.lock().retain(|tx| {
|
||||
tx.unbounded_send(RemoteAudioTrackUpdate::Unsubscribed {
|
||||
publisher_id: publisher_id.clone(),
|
||||
track_id: track_id.clone(),
|
||||
})
|
||||
.is_ok()
|
||||
});
|
||||
}
|
||||
|
||||
fn did_subscribe_to_remote_video_track(&self, track: RemoteVideoTrack) {
|
||||
let track = Arc::new(track);
|
||||
self.remote_video_track_subscribers.lock().retain(|tx| {
|
||||
@@ -294,6 +405,8 @@ impl RoomDelegate {
|
||||
LKRoomDelegateCreate(
|
||||
weak_room as *mut c_void,
|
||||
Self::on_did_disconnect,
|
||||
Self::on_did_subscribe_to_remote_audio_track,
|
||||
Self::on_did_unsubscribe_from_remote_audio_track,
|
||||
Self::on_did_subscribe_to_remote_video_track,
|
||||
Self::on_did_unsubscribe_from_remote_video_track,
|
||||
)
|
||||
@@ -312,6 +425,36 @@ impl RoomDelegate {
|
||||
let _ = Weak::into_raw(room);
|
||||
}
|
||||
|
||||
extern "C" fn on_did_subscribe_to_remote_audio_track(
|
||||
room: *mut c_void,
|
||||
publisher_id: CFStringRef,
|
||||
track_id: CFStringRef,
|
||||
track: *const c_void,
|
||||
) {
|
||||
let room = unsafe { Weak::from_raw(room as *mut Room) };
|
||||
let publisher_id = unsafe { CFString::wrap_under_get_rule(publisher_id).to_string() };
|
||||
let track_id = unsafe { CFString::wrap_under_get_rule(track_id).to_string() };
|
||||
let track = RemoteAudioTrack::new(track, track_id, publisher_id);
|
||||
if let Some(room) = room.upgrade() {
|
||||
room.did_subscribe_to_remote_audio_track(track);
|
||||
}
|
||||
let _ = Weak::into_raw(room);
|
||||
}
|
||||
|
||||
extern "C" fn on_did_unsubscribe_from_remote_audio_track(
|
||||
room: *mut c_void,
|
||||
publisher_id: CFStringRef,
|
||||
track_id: CFStringRef,
|
||||
) {
|
||||
let room = unsafe { Weak::from_raw(room as *mut Room) };
|
||||
let publisher_id = unsafe { CFString::wrap_under_get_rule(publisher_id).to_string() };
|
||||
let track_id = unsafe { CFString::wrap_under_get_rule(track_id).to_string() };
|
||||
if let Some(room) = room.upgrade() {
|
||||
room.did_unsubscribe_from_remote_audio_track(publisher_id, track_id);
|
||||
}
|
||||
let _ = Weak::into_raw(room);
|
||||
}
|
||||
|
||||
extern "C" fn on_did_subscribe_to_remote_video_track(
|
||||
room: *mut c_void,
|
||||
publisher_id: CFStringRef,
|
||||
@@ -352,6 +495,20 @@ impl Drop for RoomDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LocalAudioTrack(*const c_void);
|
||||
|
||||
impl LocalAudioTrack {
|
||||
pub fn create() -> Self {
|
||||
Self(unsafe { LKLocalAudioTrackCreateTrack() })
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for LocalAudioTrack {
|
||||
fn drop(&mut self) {
|
||||
unsafe { CFRelease(self.0) }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LocalVideoTrack(*const c_void);
|
||||
|
||||
impl LocalVideoTrack {
|
||||
@@ -374,6 +531,34 @@ impl Drop for LocalTrackPublication {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RemoteAudioTrack {
|
||||
_native_track: *const c_void,
|
||||
sid: Sid,
|
||||
publisher_id: String,
|
||||
}
|
||||
|
||||
impl RemoteAudioTrack {
|
||||
fn new(native_track: *const c_void, sid: Sid, publisher_id: String) -> Self {
|
||||
unsafe {
|
||||
CFRetain(native_track);
|
||||
}
|
||||
Self {
|
||||
_native_track: native_track,
|
||||
sid,
|
||||
publisher_id,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sid(&self) -> &str {
|
||||
&self.sid
|
||||
}
|
||||
|
||||
pub fn publisher_id(&self) -> &str {
|
||||
&self.publisher_id
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RemoteVideoTrack {
|
||||
native_track: *const c_void,
|
||||
@@ -453,6 +638,11 @@ pub enum RemoteVideoTrackUpdate {
|
||||
Unsubscribed { publisher_id: Sid, track_id: Sid },
|
||||
}
|
||||
|
||||
pub enum RemoteAudioTrackUpdate {
|
||||
Subscribed(Arc<RemoteAudioTrack>),
|
||||
Unsubscribed { publisher_id: Sid, track_id: Sid },
|
||||
}
|
||||
|
||||
pub struct MacOSDisplay(*const c_void);
|
||||
|
||||
impl MacOSDisplay {
|
||||
|
||||
@@ -67,7 +67,7 @@ impl TestServer {
|
||||
}
|
||||
}
|
||||
|
||||
async fn create_room(&self, room: String) -> Result<()> {
|
||||
pub async fn create_room(&self, room: String) -> Result<()> {
|
||||
self.background.simulate_random_delay().await;
|
||||
let mut server_rooms = self.rooms.lock();
|
||||
if server_rooms.contains_key(&room) {
|
||||
@@ -104,7 +104,7 @@ impl TestServer {
|
||||
room_name
|
||||
))
|
||||
} else {
|
||||
for track in &room.tracks {
|
||||
for track in &room.video_tracks {
|
||||
client_room
|
||||
.0
|
||||
.lock()
|
||||
@@ -182,7 +182,7 @@ impl TestServer {
|
||||
frames_rx: local_track.frames_rx.clone(),
|
||||
});
|
||||
|
||||
room.tracks.push(track.clone());
|
||||
room.video_tracks.push(track.clone());
|
||||
|
||||
for (id, client_room) in &room.client_rooms {
|
||||
if *id != identity {
|
||||
@@ -199,6 +199,43 @@ impl TestServer {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn publish_audio_track(
|
||||
&self,
|
||||
token: String,
|
||||
_local_track: &LocalAudioTrack,
|
||||
) -> Result<()> {
|
||||
self.background.simulate_random_delay().await;
|
||||
let claims = live_kit_server::token::validate(&token, &self.secret_key)?;
|
||||
let identity = claims.sub.unwrap().to_string();
|
||||
let room_name = claims.video.room.unwrap();
|
||||
|
||||
let mut server_rooms = self.rooms.lock();
|
||||
let room = server_rooms
|
||||
.get_mut(&*room_name)
|
||||
.ok_or_else(|| anyhow!("room {} does not exist", room_name))?;
|
||||
|
||||
let track = Arc::new(RemoteAudioTrack {
|
||||
sid: nanoid::nanoid!(17),
|
||||
publisher_id: identity.clone(),
|
||||
});
|
||||
|
||||
room.audio_tracks.push(track.clone());
|
||||
|
||||
for (id, client_room) in &room.client_rooms {
|
||||
if *id != identity {
|
||||
let _ = client_room
|
||||
.0
|
||||
.lock()
|
||||
.audio_track_updates
|
||||
.0
|
||||
.try_broadcast(RemoteAudioTrackUpdate::Subscribed(track.clone()))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn video_tracks(&self, token: String) -> Result<Vec<Arc<RemoteVideoTrack>>> {
|
||||
let claims = live_kit_server::token::validate(&token, &self.secret_key)?;
|
||||
let room_name = claims.video.room.unwrap();
|
||||
@@ -207,14 +244,26 @@ impl TestServer {
|
||||
let room = server_rooms
|
||||
.get_mut(&*room_name)
|
||||
.ok_or_else(|| anyhow!("room {} does not exist", room_name))?;
|
||||
Ok(room.tracks.clone())
|
||||
Ok(room.video_tracks.clone())
|
||||
}
|
||||
|
||||
fn audio_tracks(&self, token: String) -> Result<Vec<Arc<RemoteAudioTrack>>> {
|
||||
let claims = live_kit_server::token::validate(&token, &self.secret_key)?;
|
||||
let room_name = claims.video.room.unwrap();
|
||||
|
||||
let mut server_rooms = self.rooms.lock();
|
||||
let room = server_rooms
|
||||
.get_mut(&*room_name)
|
||||
.ok_or_else(|| anyhow!("room {} does not exist", room_name))?;
|
||||
Ok(room.audio_tracks.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct TestServerRoom {
|
||||
client_rooms: HashMap<Sid, Arc<Room>>,
|
||||
tracks: Vec<Arc<RemoteVideoTrack>>,
|
||||
video_tracks: Vec<Arc<RemoteVideoTrack>>,
|
||||
audio_tracks: Vec<Arc<RemoteAudioTrack>>,
|
||||
}
|
||||
|
||||
impl TestServerRoom {}
|
||||
@@ -266,6 +315,10 @@ struct RoomState {
|
||||
watch::Receiver<ConnectionState>,
|
||||
),
|
||||
display_sources: Vec<MacOSDisplay>,
|
||||
audio_track_updates: (
|
||||
async_broadcast::Sender<RemoteAudioTrackUpdate>,
|
||||
async_broadcast::Receiver<RemoteAudioTrackUpdate>,
|
||||
),
|
||||
video_track_updates: (
|
||||
async_broadcast::Sender<RemoteVideoTrackUpdate>,
|
||||
async_broadcast::Receiver<RemoteVideoTrackUpdate>,
|
||||
@@ -286,6 +339,7 @@ impl Room {
|
||||
connection: watch::channel_with(ConnectionState::Disconnected),
|
||||
display_sources: Default::default(),
|
||||
video_track_updates: async_broadcast::broadcast(128),
|
||||
audio_track_updates: async_broadcast::broadcast(128),
|
||||
})))
|
||||
}
|
||||
|
||||
@@ -327,8 +381,34 @@ impl Room {
|
||||
Ok(LocalTrackPublication)
|
||||
}
|
||||
}
|
||||
pub fn publish_audio_track(
|
||||
self: &Arc<Self>,
|
||||
track: &LocalAudioTrack,
|
||||
) -> impl Future<Output = Result<LocalTrackPublication>> {
|
||||
let this = self.clone();
|
||||
let track = track.clone();
|
||||
async move {
|
||||
this.test_server()
|
||||
.publish_audio_track(this.token(), &track)
|
||||
.await?;
|
||||
Ok(LocalTrackPublication)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unpublish_track(&self, _: LocalTrackPublication) {}
|
||||
pub fn unpublish_track(&self, _publication: LocalTrackPublication) {}
|
||||
|
||||
pub fn remote_audio_tracks(&self, publisher_id: &str) -> Vec<Arc<RemoteAudioTrack>> {
|
||||
if !self.is_connected() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
self.test_server()
|
||||
.audio_tracks(self.token())
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.filter(|track| track.publisher_id() == publisher_id)
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn remote_video_tracks(&self, publisher_id: &str) -> Vec<Arc<RemoteVideoTrack>> {
|
||||
if !self.is_connected() {
|
||||
@@ -343,6 +423,10 @@ impl Room {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn remote_audio_track_updates(&self) -> impl Stream<Item = RemoteAudioTrackUpdate> {
|
||||
self.0.lock().audio_track_updates.1.clone()
|
||||
}
|
||||
|
||||
pub fn remote_video_track_updates(&self) -> impl Stream<Item = RemoteVideoTrackUpdate> {
|
||||
self.0.lock().video_track_updates.1.clone()
|
||||
}
|
||||
@@ -404,6 +488,15 @@ impl LocalVideoTrack {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct LocalAudioTrack;
|
||||
|
||||
impl LocalAudioTrack {
|
||||
pub fn create() -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RemoteVideoTrack {
|
||||
sid: Sid,
|
||||
publisher_id: Sid,
|
||||
@@ -424,12 +517,33 @@ impl RemoteVideoTrack {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RemoteAudioTrack {
|
||||
sid: Sid,
|
||||
publisher_id: Sid,
|
||||
}
|
||||
|
||||
impl RemoteAudioTrack {
|
||||
pub fn sid(&self) -> &str {
|
||||
&self.sid
|
||||
}
|
||||
|
||||
pub fn publisher_id(&self) -> &str {
|
||||
&self.publisher_id
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum RemoteVideoTrackUpdate {
|
||||
Subscribed(Arc<RemoteVideoTrack>),
|
||||
Unsubscribed { publisher_id: Sid, track_id: Sid },
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum RemoteAudioTrackUpdate {
|
||||
Subscribed(Arc<RemoteAudioTrack>),
|
||||
Unsubscribed { publisher_id: Sid, track_id: Sid },
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct MacOSDisplay {
|
||||
frames: (
|
||||
|
||||
+20
-7
@@ -103,14 +103,14 @@ struct Notification<'a, T> {
|
||||
params: T,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
struct AnyNotification<'a> {
|
||||
#[serde(default)]
|
||||
id: Option<usize>,
|
||||
#[serde(borrow)]
|
||||
method: &'a str,
|
||||
#[serde(borrow)]
|
||||
params: &'a RawValue,
|
||||
#[serde(borrow, default)]
|
||||
params: Option<&'a RawValue>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
@@ -157,9 +157,12 @@ impl LanguageServer {
|
||||
"unhandled notification {}:\n{}",
|
||||
notification.method,
|
||||
serde_json::to_string_pretty(
|
||||
&Value::from_str(notification.params.get()).unwrap()
|
||||
¬ification
|
||||
.params
|
||||
.and_then(|params| Value::from_str(params.get()).ok())
|
||||
.unwrap_or(Value::Null)
|
||||
)
|
||||
.unwrap()
|
||||
.unwrap(),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -279,7 +282,11 @@ impl LanguageServer {
|
||||
|
||||
if let Ok(msg) = serde_json::from_slice::<AnyNotification>(&buffer) {
|
||||
if let Some(handler) = notification_handlers.lock().get_mut(msg.method) {
|
||||
handler(msg.id, msg.params.get(), cx.clone());
|
||||
handler(
|
||||
msg.id,
|
||||
&msg.params.map(|params| params.get()).unwrap_or("null"),
|
||||
cx.clone(),
|
||||
);
|
||||
} else {
|
||||
on_unhandled_notification(msg);
|
||||
}
|
||||
@@ -828,7 +835,13 @@ impl LanguageServer {
|
||||
cx,
|
||||
move |msg| {
|
||||
notifications_tx
|
||||
.try_send((msg.method.to_string(), msg.params.get().to_string()))
|
||||
.try_send((
|
||||
msg.method.to_string(),
|
||||
msg.params
|
||||
.map(|raw_value| raw_value.get())
|
||||
.unwrap_or("null")
|
||||
.to_string(),
|
||||
))
|
||||
.ok();
|
||||
},
|
||||
)),
|
||||
|
||||
@@ -598,8 +598,8 @@ impl StatusItemView for PanelButtons {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod test {
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub mod test {
|
||||
use super::*;
|
||||
use gpui::{ViewContext, WindowContext};
|
||||
|
||||
|
||||
@@ -710,8 +710,8 @@ impl<T: FollowableItem> FollowableItemHandle for ViewHandle<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod test {
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub mod test {
|
||||
use super::{Item, ItemEvent};
|
||||
use crate::{ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId};
|
||||
use gpui::{
|
||||
|
||||
@@ -162,6 +162,12 @@ define_connection! {
|
||||
ALTER TABLE workspaces ADD COLUMN right_dock_active_panel TEXT;
|
||||
ALTER TABLE workspaces ADD COLUMN bottom_dock_visible INTEGER; //bool
|
||||
ALTER TABLE workspaces ADD COLUMN bottom_dock_active_panel TEXT;
|
||||
),
|
||||
// Add panel zoom persistence
|
||||
sql!(
|
||||
ALTER TABLE workspaces ADD COLUMN left_dock_zoom INTEGER; //bool
|
||||
ALTER TABLE workspaces ADD COLUMN right_dock_zoom INTEGER; //bool
|
||||
ALTER TABLE workspaces ADD COLUMN bottom_dock_zoom INTEGER; //bool
|
||||
)];
|
||||
}
|
||||
|
||||
@@ -196,10 +202,13 @@ impl WorkspaceDb {
|
||||
display,
|
||||
left_dock_visible,
|
||||
left_dock_active_panel,
|
||||
left_dock_zoom,
|
||||
right_dock_visible,
|
||||
right_dock_active_panel,
|
||||
right_dock_zoom,
|
||||
bottom_dock_visible,
|
||||
bottom_dock_active_panel
|
||||
bottom_dock_active_panel,
|
||||
bottom_dock_zoom
|
||||
FROM workspaces
|
||||
WHERE workspace_location = ?
|
||||
})
|
||||
@@ -244,22 +253,28 @@ impl WorkspaceDb {
|
||||
workspace_location,
|
||||
left_dock_visible,
|
||||
left_dock_active_panel,
|
||||
left_dock_zoom,
|
||||
right_dock_visible,
|
||||
right_dock_active_panel,
|
||||
right_dock_zoom,
|
||||
bottom_dock_visible,
|
||||
bottom_dock_active_panel,
|
||||
bottom_dock_zoom,
|
||||
timestamp
|
||||
)
|
||||
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, CURRENT_TIMESTAMP)
|
||||
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT DO
|
||||
UPDATE SET
|
||||
workspace_location = ?2,
|
||||
left_dock_visible = ?3,
|
||||
left_dock_active_panel = ?4,
|
||||
right_dock_visible = ?5,
|
||||
right_dock_active_panel = ?6,
|
||||
bottom_dock_visible = ?7,
|
||||
bottom_dock_active_panel = ?8,
|
||||
left_dock_zoom = ?5,
|
||||
right_dock_visible = ?6,
|
||||
right_dock_active_panel = ?7,
|
||||
right_dock_zoom = ?8,
|
||||
bottom_dock_visible = ?9,
|
||||
bottom_dock_active_panel = ?10,
|
||||
bottom_dock_zoom = ?11,
|
||||
timestamp = CURRENT_TIMESTAMP
|
||||
))?((workspace.id, &workspace.location, workspace.docks))
|
||||
.context("Updating workspace")?;
|
||||
|
||||
@@ -100,16 +100,19 @@ impl Bind for DockStructure {
|
||||
pub struct DockData {
|
||||
pub(crate) visible: bool,
|
||||
pub(crate) active_panel: Option<String>,
|
||||
pub(crate) zoom: bool,
|
||||
}
|
||||
|
||||
impl Column for DockData {
|
||||
fn column(statement: &mut Statement, start_index: i32) -> Result<(Self, i32)> {
|
||||
let (visible, next_index) = Option::<bool>::column(statement, start_index)?;
|
||||
let (active_panel, next_index) = Option::<String>::column(statement, next_index)?;
|
||||
let (zoom, next_index) = Option::<bool>::column(statement, next_index)?;
|
||||
Ok((
|
||||
DockData {
|
||||
visible: visible.unwrap_or(false),
|
||||
active_panel,
|
||||
zoom: zoom.unwrap_or(false),
|
||||
},
|
||||
next_index,
|
||||
))
|
||||
@@ -119,7 +122,8 @@ impl Column for DockData {
|
||||
impl Bind for DockData {
|
||||
fn bind(&self, statement: &Statement, start_index: i32) -> Result<i32> {
|
||||
let next_index = statement.bind(&self.visible, start_index)?;
|
||||
statement.bind(&self.active_panel, next_index)
|
||||
let next_index = statement.bind(&self.active_panel, next_index)?;
|
||||
statement.bind(&self.zoom, next_index)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -919,6 +919,7 @@ impl Workspace {
|
||||
this.zoomed = None;
|
||||
this.zoomed_position = None;
|
||||
}
|
||||
this.update_active_view_for_followers(cx);
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
@@ -1598,9 +1599,7 @@ impl Workspace {
|
||||
focus_center = true;
|
||||
}
|
||||
} else {
|
||||
if active_panel.is_zoomed(cx) {
|
||||
cx.focus(active_panel.as_any());
|
||||
}
|
||||
cx.focus(active_panel.as_any());
|
||||
reveal_dock = true;
|
||||
}
|
||||
}
|
||||
@@ -1946,18 +1945,7 @@ impl Workspace {
|
||||
self.zoomed = None;
|
||||
}
|
||||
self.zoomed_position = None;
|
||||
|
||||
self.update_followers(
|
||||
proto::update_followers::Variant::UpdateActiveView(proto::UpdateActiveView {
|
||||
id: self.active_item(cx).and_then(|item| {
|
||||
item.to_followable_item_handle(cx)?
|
||||
.remote_id(&self.app_state.client, cx)
|
||||
.map(|id| id.to_proto())
|
||||
}),
|
||||
leader_id: self.leader_for_pane(&pane),
|
||||
}),
|
||||
cx,
|
||||
);
|
||||
self.update_active_view_for_followers(cx);
|
||||
|
||||
cx.notify();
|
||||
}
|
||||
@@ -2646,6 +2634,30 @@ impl Workspace {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_active_view_for_followers(&self, cx: &AppContext) {
|
||||
if self.active_pane.read(cx).has_focus() {
|
||||
self.update_followers(
|
||||
proto::update_followers::Variant::UpdateActiveView(proto::UpdateActiveView {
|
||||
id: self.active_item(cx).and_then(|item| {
|
||||
item.to_followable_item_handle(cx)?
|
||||
.remote_id(&self.app_state.client, cx)
|
||||
.map(|id| id.to_proto())
|
||||
}),
|
||||
leader_id: self.leader_for_pane(&self.active_pane),
|
||||
}),
|
||||
cx,
|
||||
);
|
||||
} else {
|
||||
self.update_followers(
|
||||
proto::update_followers::Variant::UpdateActiveView(proto::UpdateActiveView {
|
||||
id: None,
|
||||
leader_id: None,
|
||||
}),
|
||||
cx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn update_followers(
|
||||
&self,
|
||||
update: proto::update_followers::Variant,
|
||||
@@ -2693,12 +2705,10 @@ impl Workspace {
|
||||
.and_then(|id| state.items_by_leader_view_id.get(&id))
|
||||
{
|
||||
items_to_activate.push((pane.clone(), item.boxed_clone()));
|
||||
} else {
|
||||
if let Some(shared_screen) =
|
||||
self.shared_screen_for_peer(leader_id, pane, cx)
|
||||
{
|
||||
items_to_activate.push((pane.clone(), Box::new(shared_screen)));
|
||||
}
|
||||
} else if let Some(shared_screen) =
|
||||
self.shared_screen_for_peer(leader_id, pane, cx)
|
||||
{
|
||||
items_to_activate.push((pane.clone(), Box::new(shared_screen)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2838,7 +2848,7 @@ impl Workspace {
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn serialize_workspace(&self, cx: &AppContext) {
|
||||
fn serialize_workspace(&self, cx: &ViewContext<Self>) {
|
||||
fn serialize_pane_handle(
|
||||
pane_handle: &ViewHandle<Pane>,
|
||||
cx: &AppContext,
|
||||
@@ -2881,7 +2891,7 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
fn build_serialized_docks(this: &Workspace, cx: &AppContext) -> DockStructure {
|
||||
fn build_serialized_docks(this: &Workspace, cx: &ViewContext<Workspace>) -> DockStructure {
|
||||
let left_dock = this.left_dock.read(cx);
|
||||
let left_visible = left_dock.is_open();
|
||||
let left_active_panel = left_dock.visible_panel().and_then(|panel| {
|
||||
@@ -2890,6 +2900,10 @@ impl Workspace {
|
||||
.to_string(),
|
||||
)
|
||||
});
|
||||
let left_dock_zoom = left_dock
|
||||
.visible_panel()
|
||||
.map(|panel| panel.is_zoomed(cx))
|
||||
.unwrap_or(false);
|
||||
|
||||
let right_dock = this.right_dock.read(cx);
|
||||
let right_visible = right_dock.is_open();
|
||||
@@ -2899,6 +2913,10 @@ impl Workspace {
|
||||
.to_string(),
|
||||
)
|
||||
});
|
||||
let right_dock_zoom = right_dock
|
||||
.visible_panel()
|
||||
.map(|panel| panel.is_zoomed(cx))
|
||||
.unwrap_or(false);
|
||||
|
||||
let bottom_dock = this.bottom_dock.read(cx);
|
||||
let bottom_visible = bottom_dock.is_open();
|
||||
@@ -2908,19 +2926,26 @@ impl Workspace {
|
||||
.to_string(),
|
||||
)
|
||||
});
|
||||
let bottom_dock_zoom = bottom_dock
|
||||
.visible_panel()
|
||||
.map(|panel| panel.is_zoomed(cx))
|
||||
.unwrap_or(false);
|
||||
|
||||
DockStructure {
|
||||
left: DockData {
|
||||
visible: left_visible,
|
||||
active_panel: left_active_panel,
|
||||
zoom: left_dock_zoom,
|
||||
},
|
||||
right: DockData {
|
||||
visible: right_visible,
|
||||
active_panel: right_active_panel,
|
||||
zoom: right_dock_zoom,
|
||||
},
|
||||
bottom: DockData {
|
||||
visible: bottom_visible,
|
||||
active_panel: bottom_active_panel,
|
||||
zoom: bottom_dock_zoom,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -3033,14 +3058,31 @@ impl Workspace {
|
||||
dock.activate_panel(ix, cx);
|
||||
}
|
||||
}
|
||||
dock.active_panel()
|
||||
.map(|panel| {
|
||||
panel.set_zoomed(docks.left.zoom, cx)
|
||||
});
|
||||
if docks.left.visible && docks.left.zoom {
|
||||
cx.focus_self()
|
||||
}
|
||||
});
|
||||
// TODO: I think the bug is that setting zoom or active undoes the bottom zoom or something
|
||||
workspace.right_dock.update(cx, |dock, cx| {
|
||||
dock.set_open(docks.right.visible, cx);
|
||||
if let Some(active_panel) = docks.right.active_panel {
|
||||
if let Some(ix) = dock.panel_index_for_ui_name(&active_panel, cx) {
|
||||
dock.activate_panel(ix, cx);
|
||||
|
||||
}
|
||||
}
|
||||
dock.active_panel()
|
||||
.map(|panel| {
|
||||
panel.set_zoomed(docks.right.zoom, cx)
|
||||
});
|
||||
|
||||
if docks.right.visible && docks.right.zoom {
|
||||
cx.focus_self()
|
||||
}
|
||||
});
|
||||
workspace.bottom_dock.update(cx, |dock, cx| {
|
||||
dock.set_open(docks.bottom.visible, cx);
|
||||
@@ -3049,8 +3091,18 @@ impl Workspace {
|
||||
dock.activate_panel(ix, cx);
|
||||
}
|
||||
}
|
||||
|
||||
dock.active_panel()
|
||||
.map(|panel| {
|
||||
panel.set_zoomed(docks.bottom.zoom, cx)
|
||||
});
|
||||
|
||||
if docks.bottom.visible && docks.bottom.zoom {
|
||||
cx.focus_self()
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
cx.notify();
|
||||
})?;
|
||||
|
||||
@@ -4413,7 +4465,7 @@ mod tests {
|
||||
workspace.read_with(cx, |workspace, cx| {
|
||||
assert!(workspace.right_dock().read(cx).is_open());
|
||||
assert!(!panel.is_zoomed(cx));
|
||||
assert!(!panel.has_focus(cx));
|
||||
assert!(panel.has_focus(cx));
|
||||
});
|
||||
|
||||
// Focus and zoom panel
|
||||
@@ -4488,7 +4540,7 @@ mod tests {
|
||||
workspace.read_with(cx, |workspace, cx| {
|
||||
let pane = pane.read(cx);
|
||||
assert!(!pane.is_zoomed());
|
||||
assert!(pane.has_focus());
|
||||
assert!(!pane.has_focus());
|
||||
assert!(workspace.right_dock().read(cx).is_open());
|
||||
assert!(workspace.zoomed.is_none());
|
||||
});
|
||||
|
||||
+59
-84
@@ -31,7 +31,6 @@ use std::{
|
||||
ffi::OsStr,
|
||||
fs::OpenOptions,
|
||||
io::Write as _,
|
||||
ops::Not,
|
||||
os::unix::prelude::OsStrExt,
|
||||
panic,
|
||||
path::{Path, PathBuf},
|
||||
@@ -373,7 +372,6 @@ struct Panic {
|
||||
os_version: Option<String>,
|
||||
architecture: String,
|
||||
panicked_on: u128,
|
||||
identifying_backtrace: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -401,61 +399,18 @@ fn init_panic_hook(app: &App) {
|
||||
.unwrap_or_else(|| "Box<Any>".to_string());
|
||||
|
||||
let backtrace = Backtrace::new();
|
||||
let backtrace = backtrace
|
||||
let mut backtrace = backtrace
|
||||
.frames()
|
||||
.iter()
|
||||
.filter_map(|frame| {
|
||||
let symbol = frame.symbols().first()?;
|
||||
let path = symbol.filename()?;
|
||||
Some((path, symbol.lineno(), format!("{:#}", symbol.name()?)))
|
||||
})
|
||||
.filter_map(|frame| Some(format!("{:#}", frame.symbols().first()?.name()?)))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let this_file_path = Path::new(file!());
|
||||
|
||||
// Find the first frame in the backtrace for this panic hook itself. Exclude
|
||||
// that frame and all frames before it.
|
||||
let mut start_frame_ix = 0;
|
||||
let mut codebase_root_path = None;
|
||||
for (ix, (path, _, _)) in backtrace.iter().enumerate() {
|
||||
if path.ends_with(this_file_path) {
|
||||
start_frame_ix = ix + 1;
|
||||
codebase_root_path = path.ancestors().nth(this_file_path.components().count());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Exclude any subsequent frames inside of rust's panic handling system.
|
||||
while let Some((path, _, _)) = backtrace.get(start_frame_ix) {
|
||||
if path.starts_with("/rustc") {
|
||||
start_frame_ix += 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Build two backtraces:
|
||||
// * one for display, which includes symbol names for all frames, and files
|
||||
// and line numbers for symbols in this codebase
|
||||
// * one for identification and de-duplication, which only includes symbol
|
||||
// names for symbols in this codebase.
|
||||
let mut display_backtrace = Vec::new();
|
||||
let mut identifying_backtrace = Vec::new();
|
||||
for (path, line, symbol) in &backtrace[start_frame_ix..] {
|
||||
display_backtrace.push(symbol.clone());
|
||||
|
||||
if let Some(codebase_root_path) = &codebase_root_path {
|
||||
if let Ok(suffix) = path.strip_prefix(&codebase_root_path) {
|
||||
identifying_backtrace.push(symbol.clone());
|
||||
|
||||
let display_path = suffix.to_string_lossy();
|
||||
if let Some(line) = line {
|
||||
display_backtrace.push(format!(" {display_path}:{line}"));
|
||||
} else {
|
||||
display_backtrace.push(format!(" {display_path}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Strip out leading stack frames for rust panic-handling.
|
||||
if let Some(ix) = backtrace
|
||||
.iter()
|
||||
.position(|name| name == "rust_begin_unwind")
|
||||
{
|
||||
backtrace.drain(0..=ix);
|
||||
}
|
||||
|
||||
let panic_data = Panic {
|
||||
@@ -477,29 +432,27 @@ fn init_panic_hook(app: &App) {
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_millis(),
|
||||
backtrace: display_backtrace,
|
||||
identifying_backtrace: identifying_backtrace
|
||||
.is_empty()
|
||||
.not()
|
||||
.then_some(identifying_backtrace),
|
||||
backtrace,
|
||||
};
|
||||
|
||||
if let Some(panic_data_json) = serde_json::to_string_pretty(&panic_data).log_err() {
|
||||
if is_pty {
|
||||
if is_pty {
|
||||
if let Some(panic_data_json) = serde_json::to_string_pretty(&panic_data).log_err() {
|
||||
eprintln!("{}", panic_data_json);
|
||||
return;
|
||||
}
|
||||
|
||||
let timestamp = chrono::Utc::now().format("%Y_%m_%d %H_%M_%S").to_string();
|
||||
let panic_file_path = paths::LOGS_DIR.join(format!("zed-{}.panic", timestamp));
|
||||
let panic_file = std::fs::OpenOptions::new()
|
||||
.append(true)
|
||||
.create(true)
|
||||
.open(&panic_file_path)
|
||||
.log_err();
|
||||
if let Some(mut panic_file) = panic_file {
|
||||
write!(&mut panic_file, "{}", panic_data_json).log_err();
|
||||
panic_file.flush().log_err();
|
||||
} else {
|
||||
if let Some(panic_data_json) = serde_json::to_string(&panic_data).log_err() {
|
||||
let timestamp = chrono::Utc::now().format("%Y_%m_%d %H_%M_%S").to_string();
|
||||
let panic_file_path = paths::LOGS_DIR.join(format!("zed-{}.panic", timestamp));
|
||||
let panic_file = std::fs::OpenOptions::new()
|
||||
.append(true)
|
||||
.create(true)
|
||||
.open(&panic_file_path)
|
||||
.log_err();
|
||||
if let Some(mut panic_file) = panic_file {
|
||||
writeln!(&mut panic_file, "{}", panic_data_json).log_err();
|
||||
panic_file.flush().log_err();
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
@@ -531,23 +484,45 @@ fn upload_previous_panics(http: Arc<dyn HttpClient>, cx: &mut AppContext) {
|
||||
}
|
||||
|
||||
if telemetry_settings.diagnostics {
|
||||
let panic_data_text = smol::fs::read_to_string(&child_path)
|
||||
let panic_file_content = smol::fs::read_to_string(&child_path)
|
||||
.await
|
||||
.context("error reading panic file")?;
|
||||
|
||||
let body = serde_json::to_string(&PanicRequest {
|
||||
panic: serde_json::from_str(&panic_data_text)?,
|
||||
token: ZED_SECRET_CLIENT_TOKEN.into(),
|
||||
})
|
||||
.unwrap();
|
||||
let panic = serde_json::from_str(&panic_file_content)
|
||||
.ok()
|
||||
.or_else(|| {
|
||||
panic_file_content
|
||||
.lines()
|
||||
.next()
|
||||
.and_then(|line| serde_json::from_str(line).ok())
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
log::error!(
|
||||
"failed to deserialize panic file {:?}",
|
||||
panic_file_content
|
||||
);
|
||||
None
|
||||
});
|
||||
|
||||
let request = Request::post(&panic_report_url)
|
||||
.redirect_policy(isahc::config::RedirectPolicy::Follow)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(body.into())?;
|
||||
let response = http.send(request).await.context("error sending panic")?;
|
||||
if !response.status().is_success() {
|
||||
log::error!("Error uploading panic to server: {}", response.status());
|
||||
if let Some(panic) = panic {
|
||||
let body = serde_json::to_string(&PanicRequest {
|
||||
panic,
|
||||
token: ZED_SECRET_CLIENT_TOKEN.into(),
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let request = Request::post(&panic_report_url)
|
||||
.redirect_policy(isahc::config::RedirectPolicy::Follow)
|
||||
.header("Content-Type", "application/json")
|
||||
.body(body.into())?;
|
||||
let response =
|
||||
http.send(request).await.context("error sending panic")?;
|
||||
if !response.status().is_success() {
|
||||
log::error!(
|
||||
"Error uploading panic to server: {}",
|
||||
response.status()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -384,6 +384,8 @@ pub fn initialize_workspace(
|
||||
workspace.toggle_dock(project_panel_position, cx);
|
||||
}
|
||||
|
||||
cx.focus_self();
|
||||
|
||||
workspace.add_panel(terminal_panel, cx);
|
||||
if let Some(assistant_panel) = assistant_panel {
|
||||
workspace.add_panel(assistant_panel, cx);
|
||||
|
||||
Reference in New Issue
Block a user