Skip to content

Commit

Permalink
feat!: add Capacitor 3 support (#24)
Browse files Browse the repository at this point in the history

BREAKING CHANGE: Update to Capacitor v3
  • Loading branch information
robingenz authored Mar 10, 2021
1 parent b7de271 commit c405ef4
Show file tree
Hide file tree
Showing 19 changed files with 5,958 additions and 2,323 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
dist
10 changes: 7 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
build:
name: Build web assets
name: Build
runs-on: macos-latest
steps:
- name: Checkout
Expand All @@ -20,8 +20,12 @@ jobs:
node-version: '12'
- name: Install dependencies
run: npm ci
- name: Build web assets
run: npm run build
- name: Build iOS
run: npm run verify:ios
- name: Build Android
run: npm run verify:android
- name: Build Web
run: npm run verify:web
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
Expand Down
52 changes: 52 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Contributing

This guide provides instructions for contributing to this Capacitor plugin.

## Developing

### Local Setup

1. Fork and clone the repo.
2. Install the dependencies.

```shell
npm install
```

3. Install SwiftLint if you're on macOS.
```shell
brew install swiftlint
```
### Scripts
#### `npm run build`
Build the plugin web assets and generate plugin API documentation using [`@capacitor/docgen`](https://github.com/ionic-team/capacitor-docgen).
It will compile the TypeScript code from `src/` into ESM JavaScript in `dist/esm/`. These files are used in apps with bundlers when your plugin is imported.
Then, Rollup will bundle the code into a single file at `dist/plugin.js`. This file is used in apps without bundlers by including it as a script in `index.html`.
#### `npm run verify`
Build and validate the web and native projects.
This is useful to run in CI to verify that the plugin builds for all platforms.
#### `npm run lint` / `npm run fmt`
Check formatting and code quality, autoformat/autofix if possible.
This template is integrated with ESLint, Prettier, and SwiftLint. Using these tools is completely optional, but the [Capacitor Community](https://github.com/capacitor-community/) strives to have consistent code style and structure for easier cooperation.
## Publishing
There is a `prepublishOnly` hook in `package.json` which prepares the plugin before publishing, so all you need to do is run:
```shell
npm publish
```
> **Note**: The [`files`](https://docs.npmjs.com/cli/v7/configuring-npm/package-json#files) array in `package.json` specifies which files get published. If you rename files/directories or add files elsewhere, you may need to update it.
2 changes: 1 addition & 1 deletion CapacitorCommunityPrivacyScreen.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Pod::Spec.new do |s|
s.author = package['author']
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
s.ios.deployment_target = '11.0'
s.ios.deployment_target = '12.0'
s.dependency 'Capacitor'
s.swift_version = '5.1'
end
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,20 @@ On **iOS**, this plugin hides the webview window when the app is no longer activ

## Installation

### Capacitor 3.x

```
npm install @capacitor-community/privacy-screen
npx cap sync
```

### Capacitor 2.x

```
npm install @capacitor-community/privacy-screen@1.1.2
npx cap sync
```

On **iOS**, no further steps are needed.

On **Android**, register the plugin in your main activity:
Expand All @@ -54,7 +63,6 @@ public class MainActivity extends BridgeActivity {
this.init(
savedInstanceState,
new ArrayList<Class<? extends Plugin>>() {

{
// Additional plugins you've installed go here
// Ex: add(TotallyAwesomePlugin.class);
Expand All @@ -64,6 +72,7 @@ public class MainActivity extends BridgeActivity {
);
}
}

```

## Configuration
Expand All @@ -89,6 +98,49 @@ const disable = async () => {
};
```

## API

<docgen-index>

* [`enable()`](#enable)
* [`disable()`](#disable)

</docgen-index>

<docgen-api>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

### enable()

```typescript
enable() => Promise<void>
```

Enables the privacy screen protection.

Only available for Android and iOS.

**Since:** 1.1.0

--------------------


### disable()

```typescript
disable() => Promise<void>
```

Disables the privacy screen protection.

Only available for Android and iOS.

**Since:** 1.1.0

--------------------

</docgen-api>

## Changelog

See [CHANGELOG.md](https://github.com/capacitor-community/privacy-screen/blob/main/CHANGELOG.md).
Expand Down
Empty file modified android/gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import android.view.Window;
import android.view.WindowManager;
import androidx.appcompat.app.AppCompatActivity;
import com.getcapacitor.JSObject;
import com.getcapacitor.NativePlugin;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.getcapacitor.annotation.CapacitorPlugin;

@NativePlugin
public class PrivacyScreen extends Plugin {
@CapacitorPlugin(name = "PrivacyScreen")
public class PrivacyScreenPlugin extends Plugin {

/**
* Called when the plugin is first constructed in the bridge.
Expand Down
32 changes: 16 additions & 16 deletions ios/Plugin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
03FC29A292ACC40490383A1F /* Pods_Plugin.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B2A61DA5A1F2DD4F959604D /* Pods_Plugin.framework */; };
20C0B05DCFC8E3958A738AF2 /* Pods_PluginTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6753A823D3815DB436415E3 /* Pods_PluginTests.framework */; };
50ADFF92201F53D600D50D53 /* Plugin.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50ADFF88201F53D600D50D53 /* Plugin.framework */; };
50ADFF97201F53D600D50D53 /* PluginTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50ADFF96201F53D600D50D53 /* PluginTests.swift */; };
50ADFF99201F53D600D50D53 /* Plugin.h in Headers */ = {isa = PBXBuildFile; fileRef = 50ADFF8B201F53D600D50D53 /* Plugin.h */; settings = {ATTRIBUTES = (Public, ); }; };
50ADFF97201F53D600D50D53 /* PrivacyScreenPluginTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50ADFF96201F53D600D50D53 /* PrivacyScreenPluginTests.swift */; };
50ADFF99201F53D600D50D53 /* PrivacyScreenPlugin.h in Headers */ = {isa = PBXBuildFile; fileRef = 50ADFF8B201F53D600D50D53 /* PrivacyScreenPlugin.h */; settings = {ATTRIBUTES = (Public, ); }; };
50ADFFA42020D75100D50D53 /* Capacitor.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50ADFFA52020D75100D50D53 /* Capacitor.framework */; };
50ADFFA82020EE4F00D50D53 /* Plugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 50ADFFA72020EE4F00D50D53 /* Plugin.m */; };
50E1A94820377CB70090CE1A /* Plugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E1A94720377CB70090CE1A /* Plugin.swift */; };
50ADFFA82020EE4F00D50D53 /* PrivacyScreenPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 50ADFFA72020EE4F00D50D53 /* PrivacyScreenPlugin.m */; };
50E1A94820377CB70090CE1A /* PrivacyScreenPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E1A94720377CB70090CE1A /* PrivacyScreenPlugin.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -30,14 +30,14 @@
/* Begin PBXFileReference section */
3B2A61DA5A1F2DD4F959604D /* Pods_Plugin.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Plugin.framework; sourceTree = BUILT_PRODUCTS_DIR; };
50ADFF88201F53D600D50D53 /* Plugin.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Plugin.framework; sourceTree = BUILT_PRODUCTS_DIR; };
50ADFF8B201F53D600D50D53 /* Plugin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Plugin.h; sourceTree = "<group>"; };
50ADFF8B201F53D600D50D53 /* PrivacyScreenPlugin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PrivacyScreenPlugin.h; sourceTree = "<group>"; };
50ADFF8C201F53D600D50D53 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
50ADFF91201F53D600D50D53 /* PluginTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PluginTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
50ADFF96201F53D600D50D53 /* PluginTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PluginTests.swift; sourceTree = "<group>"; };
50ADFF96201F53D600D50D53 /* PrivacyScreenPluginTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyScreenPluginTests.swift; sourceTree = "<group>"; };
50ADFF98201F53D600D50D53 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
50ADFFA52020D75100D50D53 /* Capacitor.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Capacitor.framework; sourceTree = BUILT_PRODUCTS_DIR; };
50ADFFA72020EE4F00D50D53 /* Plugin.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Plugin.m; sourceTree = "<group>"; };
50E1A94720377CB70090CE1A /* Plugin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Plugin.swift; sourceTree = "<group>"; };
50ADFFA72020EE4F00D50D53 /* PrivacyScreenPlugin.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PrivacyScreenPlugin.m; sourceTree = "<group>"; };
50E1A94720377CB70090CE1A /* PrivacyScreenPlugin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrivacyScreenPlugin.swift; sourceTree = "<group>"; };
5E23F77F099397094342571A /* Pods-Plugin.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Plugin.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Plugin/Pods-Plugin.debug.xcconfig"; sourceTree = "<group>"; };
91781294A431A2A7CC6EB714 /* Pods-Plugin.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Plugin.release.xcconfig"; path = "Pods/Target Support Files/Pods-Plugin/Pods-Plugin.release.xcconfig"; sourceTree = "<group>"; };
96ED1B6440D6672E406C8D19 /* Pods-PluginTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PluginTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PluginTests/Pods-PluginTests.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -90,9 +90,9 @@
50ADFF8A201F53D600D50D53 /* Plugin */ = {
isa = PBXGroup;
children = (
50E1A94720377CB70090CE1A /* Plugin.swift */,
50ADFF8B201F53D600D50D53 /* Plugin.h */,
50ADFFA72020EE4F00D50D53 /* Plugin.m */,
50E1A94720377CB70090CE1A /* PrivacyScreenPlugin.swift */,
50ADFF8B201F53D600D50D53 /* PrivacyScreenPlugin.h */,
50ADFFA72020EE4F00D50D53 /* PrivacyScreenPlugin.m */,
50ADFF8C201F53D600D50D53 /* Info.plist */,
);
path = Plugin;
Expand All @@ -101,7 +101,7 @@
50ADFF95201F53D600D50D53 /* PluginTests */ = {
isa = PBXGroup;
children = (
50ADFF96201F53D600D50D53 /* PluginTests.swift */,
50ADFF96201F53D600D50D53 /* PrivacyScreenPluginTests.swift */,
50ADFF98201F53D600D50D53 /* Info.plist */,
);
path = PluginTests;
Expand Down Expand Up @@ -135,7 +135,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
50ADFF99201F53D600D50D53 /* Plugin.h in Headers */,
50ADFF99201F53D600D50D53 /* PrivacyScreenPlugin.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -303,16 +303,16 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
50E1A94820377CB70090CE1A /* Plugin.swift in Sources */,
50ADFFA82020EE4F00D50D53 /* Plugin.m in Sources */,
50E1A94820377CB70090CE1A /* PrivacyScreenPlugin.swift in Sources */,
50ADFFA82020EE4F00D50D53 /* PrivacyScreenPlugin.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
50ADFF8D201F53D600D50D53 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
50ADFF97201F53D600D50D53 /* PluginTests.swift in Sources */,
50ADFF97201F53D600D50D53 /* PrivacyScreenPluginTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion ios/Plugin/Plugin.m → ios/Plugin/PrivacyScreenPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// Define the plugin using the CAP_PLUGIN Macro, and
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
CAP_PLUGIN(PrivacyScreen, "PrivacyScreen",
CAP_PLUGIN(PrivacyScreenPlugin, "PrivacyScreen",
CAP_PLUGIN_METHOD(enable, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(disable, CAPPluginReturnPromise);
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import Capacitor
* Please read the Capacitor iOS Plugin Development Guide
* here: https://capacitorjs.com/docs/plugins/ios
*/
@objc(PrivacyScreen)
public class PrivacyScreen: CAPPlugin {
@objc(PrivacyScreenPlugin)
public class PrivacyScreenPlugin: CAPPlugin {
private var isEnabled = true
private var privacyViewController: UIViewController?

Expand Down Expand Up @@ -39,7 +39,7 @@ public class PrivacyScreen: CAPPlugin {
self.privacyViewController!.view.backgroundColor = UIColor.gray;
self.privacyViewController!.modalPresentationStyle = UIModalPresentationStyle.overFullScreen
DispatchQueue.main.async {
self.bridge.viewController.present(self.privacyViewController!, animated: false, completion: nil)
self.bridge?.viewController?.present(self.privacyViewController!, animated: false, completion: nil)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import XCTest
import Capacitor
@testable import Plugin

class PluginTests: XCTestCase {
class PrivacyScreenPluginTests: XCTestCase {

override func setUp() {
super.setUp()
Expand Down
8 changes: 4 additions & 4 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PODS:
- Capacitor (2.4.6):
- Capacitor (3.0.0-beta.6):
- CapacitorCordova
- CapacitorCordova (2.4.6)
- CapacitorCordova (3.0.0-beta.6)
- SwiftLint (0.42.0)

DEPENDENCIES:
Expand All @@ -20,8 +20,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/@capacitor/ios"

SPEC CHECKSUMS:
Capacitor: 0f131577d41c082931f00cc080e2289d503465c8
CapacitorCordova: 3375b39b5ebca770ac7869f85e4dea32a642c9e0
Capacitor: d35bd4c1e12e6efdc6d9a862f436dec67cfb081b
CapacitorCordova: 00a0e1fd7dd76b43beb6993aaa6ffacd28cb57cb
SwiftLint: 4fa9579c63416865179bc416f0a92d55f009600d

PODFILE CHECKSUM: 7e65243e44d2ebb870974d311e6a896a975f136b
Expand Down
Loading

0 comments on commit c405ef4

Please sign in to comment.