Add macOS support (#23)
* Add macOS support * Update README * Update to v0.2.0 * Document breaking changes * Delete widget tests
This commit is contained in:
@@ -17,7 +17,7 @@ class AppService extends ChangeNotifier {
|
||||
NearbyConnectionAndroidInfo? _connectionAndroidInfo;
|
||||
CommunicationChannelState _communicationChannelState =
|
||||
CommunicationChannelState.notConnected;
|
||||
bool _isIOSBrowser = true;
|
||||
bool _isDarwinBrowser = true;
|
||||
|
||||
String platformVersion = 'Unknown';
|
||||
String platformModel = 'Unknown';
|
||||
@@ -40,17 +40,17 @@ class AppService extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<String> getSavedIOSDeviceName() async {
|
||||
return (await _nearbyService.ios?.getSavedDeviceName()) ?? platformModel;
|
||||
Future<String> getSavedDarwinDeviceName() async {
|
||||
return (await _nearbyService.darwin?.getSavedDeviceName()) ?? platformModel;
|
||||
}
|
||||
|
||||
Future<void> initialize(String? iosDeviceName) async {
|
||||
Future<void> initialize(String? darwinDeviceName) async {
|
||||
try {
|
||||
await _nearbyService.initialize(
|
||||
data: NearbyInitializeData(iosDeviceName: iosDeviceName),
|
||||
data: NearbyInitializeData(darwinDeviceName: darwinDeviceName),
|
||||
);
|
||||
_nearbyService.ios?.getIsBrowserStream().listen((event) {
|
||||
_isIOSBrowser = event;
|
||||
_nearbyService.darwin?.getIsBrowserStream().listen((event) {
|
||||
_isDarwinBrowser = event;
|
||||
});
|
||||
startListeningCommunicationChannelState();
|
||||
updateState(
|
||||
@@ -97,7 +97,7 @@ class AppService extends ChangeNotifier {
|
||||
}
|
||||
|
||||
void setIsBrowser({required bool value}) {
|
||||
_nearbyService.ios?.setIsBrowser(value: value);
|
||||
_nearbyService.darwin?.setIsBrowser(value: value);
|
||||
updateState(AppState.readyToDiscover);
|
||||
}
|
||||
|
||||
@@ -213,8 +213,8 @@ extension GettersExtension on AppService {
|
||||
CommunicationChannelState get communicationChannelState =>
|
||||
_communicationChannelState;
|
||||
|
||||
bool get isIOSBrowser {
|
||||
return _isIOSBrowser;
|
||||
bool get isDarwinBrowser {
|
||||
return _isDarwinBrowser;
|
||||
}
|
||||
|
||||
bool? get isAndroidGroupOwner {
|
||||
|
||||
@@ -23,7 +23,7 @@ enum AppState {
|
||||
AppState.connected,
|
||||
AppState.communicationChannelCreated,
|
||||
];
|
||||
static final List<AppState> iosSteps = [
|
||||
static final List<AppState> darwinSteps = [
|
||||
AppState.idle,
|
||||
AppState.selectClientType,
|
||||
AppState.readyToDiscover,
|
||||
@@ -36,7 +36,7 @@ enum AppState {
|
||||
|
||||
static final List<AppState> steps = [
|
||||
if (Platform.isAndroid) ...androidSteps,
|
||||
if (Platform.isIOS) ...iosSteps,
|
||||
if (Platform.isIOS || Platform.isMacOS) ...darwinSteps,
|
||||
];
|
||||
|
||||
int get step {
|
||||
|
||||
@@ -46,8 +46,8 @@ class DevicePreview extends StatelessWidget {
|
||||
final status = Text(
|
||||
device.byPlatform(
|
||||
onAny: (d) => d.status.name,
|
||||
onIOS: (d) =>
|
||||
context.select<AppService, bool>((v) => v.isIOSBrowser)
|
||||
onDarwin: (d) =>
|
||||
context.select<AppService, bool>((v) => v.isDarwinBrowser)
|
||||
? "Peer found | ${d.status.name}"
|
||||
: "Pending invitation | ${d.status.name}",
|
||||
) ??
|
||||
|
||||
@@ -53,10 +53,10 @@ class InfoPanel extends StatelessWidget {
|
||||
label: 'Communication channel state',
|
||||
value: service.communicationChannelState.previewName,
|
||||
),
|
||||
if (Platform.isIOS)
|
||||
if (Platform.isIOS || Platform.isMacOS)
|
||||
_InfoChip(
|
||||
label: 'Role',
|
||||
value: service.isIOSBrowser
|
||||
value: service.isDarwinBrowser
|
||||
? 'You are going to find your friend'
|
||||
: 'You are waiting for another user to connect',
|
||||
),
|
||||
@@ -94,7 +94,8 @@ class AdditionalInfoPanel extends StatelessWidget {
|
||||
label: 'Model',
|
||||
value: service.platformModel,
|
||||
),
|
||||
if (service.currentDeviceInfo != null && Platform.isIOS)
|
||||
if (service.currentDeviceInfo != null &&
|
||||
(Platform.isIOS || Platform.isMacOS))
|
||||
_InfoChip(
|
||||
label: 'Device P2P ID',
|
||||
value: service.currentDeviceInfo!.id,
|
||||
|
||||
@@ -19,7 +19,7 @@ class _IdleViewState extends State<IdleView> {
|
||||
@override
|
||||
void initState() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
context.read<AppService>().getSavedIOSDeviceName().then((value) {
|
||||
context.read<AppService>().getSavedDarwinDeviceName().then((value) {
|
||||
controller.text = value;
|
||||
controller.selection = TextSelection.collapsed(offset: value.length);
|
||||
setState(() {
|
||||
@@ -56,7 +56,7 @@ class _IdleViewState extends State<IdleView> {
|
||||
return Center(
|
||||
child: Column(
|
||||
children: [
|
||||
if (Platform.isIOS)
|
||||
if (Platform.isIOS || Platform.isMacOS)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10.0),
|
||||
child: TextFormField(
|
||||
|
||||
@@ -19,7 +19,7 @@ class ReadyView extends StatelessWidget {
|
||||
title: 'Start discover peers',
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
if (Platform.isIOS)
|
||||
if (Platform.isIOS || Platform.isMacOS)
|
||||
ActionButton(
|
||||
onTap: () {
|
||||
context.read<AppService>().updateState(AppState.selectClientType);
|
||||
|
||||
@@ -34,8 +34,8 @@ class _PeersBody extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Selector<AppService, bool>(
|
||||
selector: (context, service) => service.isIOSBrowser,
|
||||
builder: (context, isIOSBrowser, _) {
|
||||
selector: (context, service) => service.isDarwinBrowser,
|
||||
builder: (context, isDarwinBrowser, _) {
|
||||
return Selector<AppService, List<NearbyDevice>?>(
|
||||
selector: (context, service) => service.peers,
|
||||
builder: (context, peers, _) {
|
||||
@@ -55,7 +55,7 @@ class _PeersBody extends StatelessWidget {
|
||||
],
|
||||
)
|
||||
: Text(
|
||||
Platform.isAndroid || isIOSBrowser
|
||||
Platform.isAndroid || isDarwinBrowser
|
||||
? 'No one here ('
|
||||
: "Wait until someone invites you!",
|
||||
textAlign: TextAlign.center,
|
||||
|
||||
Reference in New Issue
Block a user