Skip to content

Commit 0752b25

Browse files
committed
Initial commit
0 parents  commit 0752b25

58 files changed

Lines changed: 5077 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/
6+
DerivedData/
7+
.swiftpm/config/registries.json
8+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
9+
.netrc
10+
.swiftpm

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Chirag Ramani
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Package.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// swift-tools-version: 5.7
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "SwiftFlipper",
7+
platforms: [
8+
.iOS(.v13),
9+
.macOS(.v12),
10+
.tvOS(.v13),
11+
],
12+
products: [
13+
.library(
14+
name: "SwiftFlipper",
15+
targets: ["SwiftFlipper"]),
16+
],
17+
dependencies: [],
18+
targets: [
19+
.target(
20+
name: "SwiftFlipper",
21+
dependencies: ["PluginUtils"]),
22+
.target(
23+
name: "PluginUtils",
24+
dependencies: [],
25+
publicHeadersPath: "include"),
26+
]
27+
)

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# swift-flipper
2+
3+
<p align="center">
4+
<img src="swift-flipper.png" />
5+
</p>
6+
7+
## What is swift-flipper?
8+
swift-flipper is a new Swift package that exposes a Flipper client to your iOS | MacOS | executable packages | server-side Swift applications and, allows you to easily develop new or reuse existing Flipper plugins.
9+
10+
This new swift-flipper SDK expands Flipper’s focus area and adds support for non-mobile Swift applications.
11+
12+
This repository has a bunch of example applications that you can play with to understand how to write a Flipper plugin, how to send/listen to events, and how the end-to-end integration works. (UserDefaults Plugin, Network Plugin, Custom Logger Plugin, Tic-Tac-Toe to demonstrate bi-directional communication etc.)
13+
14+
The assumptions, working, connection constraints of swift-flipper here are the same as that of [js-flipper](https://developers.facebook.com/blog/post/2022/08/25/flipper-and-js-why-we-added-javascript-support-to-a-mobile-debugging-platform/) (open-sourced by Meta).
15+
16+
## Why swift-flipper?
17+
18+
<p align="center">
19+
<img src="flipper.png" />
20+
</p>
21+
22+
I am a huge fan of Flipper and have been using it in a lot of my projects for quite some time. The following are the benefits I thought would be something that swift-flipper can help with:
23+
24+
Extending the debugging experience for non-mobile Swift applications as this is something that the official Flipper SDK doesn’t support. It is helpful for Swift server-side applications.
25+
swift-flipper has ZERO dependencies. This can be leveraged for mobile applications as well if you are facing issues with the official SDK (dependency hassles - don’t want to support a big dependency stack for your debug builds, etc.)
26+
It is a great alternative to debug your iOS, macOS, React Native, etc applications. Checkout this thread that talks about why something like this would be helpful to the developer community as this package helps you to directly connect to Flipper IDE without needing any intermediate bridges, without going through any dependency management hassles (there are 0 dependencies for this to work in the Swift world) - https://github.com/facebook/flipper/issues/3319.
27+
Swift package support - Flipper is a great tool and this just makes it a bit more accessible to developers that have similar requirements. https://github.com/facebook/flipper/issues/1431.
28+
We also don’t need to install any IDB support. (and so don’t have to deal with any [IDB](https://github.com/facebook/idb) related issues).
29+
Having the entire Client SDK in Swift also makes it easier for the Swift community to maintain, iterate and contribute.
30+
31+
## Limitations of this tool and Solutions
32+
33+
1. Simulator and Device connectivity both work well. However, when debugging on a device(connected via USB), the client needs to connect via web-socket to the Flipper IDE opened on the developer’s machine. So, we need to explicitly provide the developer machine’s IP address. This is taken as a part of the client side configuration. Now, though this sounds doable and also works well, it might not be the ideal developer experience. We ideally would want this connectivity to be purely invisible regardless of simulator/device host. In order to achieve this, we need a bunch of extra libraries like Peertalk, OpenSSL etc to achieve the above as well as have secure connections with the Flipper IDE. In order to keep things light-weight and since this might not be a concern for a few use-cases, we don’t plan to support this in swift-flipper and the solution is to use FlipperLite or the official Flipper SDK.
34+
35+
2. You might want developers to take advantage of device specific support that is provided via IDB, (screenshot captures and video recording from the Flipper IDE, Logs plugin). This is not supported by swift-flipper and the solution is to use FlipperLite or the official Flipper SDK.
36+
37+
## If you are interested to know more about Flipper, the following should help:
38+
39+
1. https://fbflipper.com/
40+
2. https://engineering.fb.com/2018/06/11/android/flipper/
41+
3. https://fbflipper.com/blog/2022/02/21/js-flipper-announcement/
42+
4. Mobile@Scale Tel Aviv – Flipper: An extensible mobile app debugger - https://www.facebook.com/atscaleevents/videos/mobilescale-tel-aviv-flipper-an-extensible-mobile-app-debugger/2210661825632394/
43+
5. [Flipper and JS: why we added JavaScript support to a mobile debugging platform](https://developers.facebook.com/blog/post/2022/08/25/flipper-and-js-why-we-added-javascript-support-to-a-mobile-debugging-platform/)
44+
6. https://www.youtube.com/watch?v=WCs09c1B1Lk
45+
7. Flipper: The Extensible DevTool Platform for React Native - Michel Weststrate aka @mweststrate - https://www.youtube.com/watch?v=WltZTn3ODW4
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#import <dispatch/dispatch.h>
11+
12+
namespace facebook {
13+
namespace flipper {
14+
class DispatchQueue {
15+
public:
16+
virtual void async(dispatch_block_t block) = 0;
17+
virtual ~DispatchQueue() {}
18+
};
19+
20+
class GCDQueue : public DispatchQueue {
21+
public:
22+
GCDQueue(dispatch_queue_t underlyingQueue)
23+
: _underlyingQueue(underlyingQueue) {}
24+
25+
void async(dispatch_block_t block) override {
26+
dispatch_async(_underlyingQueue, block);
27+
}
28+
29+
virtual ~GCDQueue() {}
30+
31+
private:
32+
dispatch_queue_t _underlyingQueue;
33+
};
34+
} // namespace flipper
35+
} // namespace facebook
36+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// @lint-ignore-every LICENSELINT
2+
/*
3+
* The file was derived from FLEXNetworkObserver.h.
4+
* All modifications to the original source are licensed under:
5+
*
6+
* Copyright (c) Meta Platforms, Inc. and affiliates.
7+
*
8+
* This source code is licensed under the MIT license found in the
9+
* LICENSE file in the root directory of this source tree.
10+
*/
11+
12+
//
13+
// FLEXNetworkObserver.h
14+
// Derived from:
15+
//
16+
// PDAFNetworkDomainController.h
17+
// PonyDebugger
18+
//
19+
// Created by Mike Lewis on 2/27/12.
20+
//
21+
// Licensed to Square, Inc. under one or more contributor license agreements.
22+
// See the LICENSE file distributed with this work for the terms under
23+
// which Square, Inc. licenses this file to you.
24+
//
25+
26+
// PonyDebugger Copyright 2012 Square Inc.
27+
// Licensed under the Apache License,
28+
// Version 2.0(the "License");
29+
// you may not use this file except in compliance with the License.
30+
// You may obtain a copy of the License at
31+
// http://www.apache.org/licenses/LICENSE-2.0
32+
// Unless required by applicable law or agreed to in writing, software
33+
// distributed under the License is distributed on an "AS IS" BASIS,
34+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35+
// See the License for the specific language governing permissions and
36+
// limitations under the License.
37+
38+
#import <Foundation/Foundation.h>
39+
40+
FOUNDATION_EXTERN NSString* const
41+
kSKFLEXNetworkObserverEnabledStateChangedNotification;
42+
43+
/// This class swizzles NSURLConnection and NSURLSession delegate methods to
44+
/// observe events in the URL loading system. High level network events are sent
45+
/// to the default SKFLEXNetworkRecorder instance which maintains the request
46+
/// history and caches response bodies.
47+
@interface SKFLEXNetworkObserver : NSObject
48+
49+
+ (void)start;
50+
51+
@end

0 commit comments

Comments
 (0)