Skip to content
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

feat: Use SPM project structure #20

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
dist
example-app
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ node_modules
# iOS files
Pods
Podfile.lock
Package.resolved
Build
xcuserdata
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc


# macOS files
.DS_Store
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
dist
example-app
2 changes: 1 addition & 1 deletion CapacitorCommunityScreenBrightness.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Pod::Spec.new do |s|
s.homepage = package['repository']['url']
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.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
s.ios.deployment_target = '13.0'
s.dependency 'Capacitor'
s.swift_version = '5.1'
Expand Down
28 changes: 28 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version: 5.9
import PackageDescription

let package = Package(
name: "CapacitorCommunityScreenBrightness",
platforms: [.iOS(.v13)],
products: [
.library(
name: "CapacitorCommunityScreenBrightness",
targets: ["ScreenBrightnessPlugin"])
],
dependencies: [
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", branch: "main")
],
targets: [
.target(
name: "ScreenBrightnessPlugin",
dependencies: [
.product(name: "Capacitor", package: "capacitor-swift-pm"),
.product(name: "Cordova", package: "capacitor-swift-pm")
],
path: "ios/Sources/ScreenBrightnessPlugin"),
.testTarget(
name: "ScreenBrightnessPluginTests",
dependencies: ["ScreenBrightnessPlugin"],
path: "ios/Tests/ScreenBrightnessPluginTests")
]
)
1 change: 0 additions & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ org.gradle.jvmargs=-Xmx1536m
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true

Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ public void setBrightness(PluginCall call) {
Activity activity = getActivity();
WindowManager.LayoutParams layoutParams = activity.getWindow().getAttributes();

activity.runOnUiThread(
() -> {
layoutParams.screenBrightness = brightness;
activity.getWindow().setAttributes(layoutParams);
call.resolve();
}
);
activity.runOnUiThread(() -> {
layoutParams.screenBrightness = brightness;
activity.getWindow().setAttributes(layoutParams);
call.resolve();
});
}

@PluginMethod
Expand Down
7 changes: 7 additions & 0 deletions example-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.idea/
node_modules/
.vscode/
*.map
.DS_Store
.sourcemaps
dist/
12 changes: 12 additions & 0 deletions example-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Created with Capacitor Create App

This app was created using [`@capacitor/create-app`](https://github.com/ionic-team/create-capacitor-app),
and comes with a very minimal shell for building an app.

### Running this example

To run the provided example, you can use `npm start` command.

```bash
npm start
```
10 changes: 10 additions & 0 deletions example-app/capacitor.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"appId": "com.example.plugin",
"appName": "example-app",
"webDir": "dist",
"plugins": {
"SplashScreen": {
"launchShowDuration": 0
}
}
}
29 changes: 29 additions & 0 deletions example-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "capacitor-app",
"version": "1.0.0",
"description": "An Amazing Capacitor App",
"type": "module",
"keywords": [
"capacitor",
"mobile"
],
"scripts": {
"start": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@capacitor/core": "latest",
"@capacitor/camera": "latest",
"@capacitor/splash-screen": "latest",
"@capacitor-community/screen-brightness": "file:..",
"@capacitor/ios": "^6.0.0",
"@capacitor/android": "^6.0.0"
},
"devDependencies": {
"@capacitor/cli": "latest",
"vite": "^5.4.2"
},
"author": "",
"license": "ISC"
}
26 changes: 26 additions & 0 deletions example-app/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!doctype html>
<html lang="en" dir="ltr" class="hydrated">
<head>
<meta charset="UTF-8" />
<title>Example Capacitor App</title>
<meta
name="viewport"
content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<meta name="format-detection" content="telephone=no" />
</head>
<body>
<main>
<h1>Capacitor Test Plugin Project</h1>
<p>
This project can be used to test out the functionality of your plugin. Nothing in the
<em>example-app/</em> folder will be published to npm when using this template, so you can create away!
</p>
<label for="echoInput">Echo Text:</label>
<input type="text" id="echoInput" name="echoInput" value="Hello World!" />
<button onclick="testEcho()">Click Me!</button>
</main>

<script src="./js/example.js" type="module"></script>
</body>
</html>
6 changes: 6 additions & 0 deletions example-app/src/js/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ScreenBrightness } from '@capacitor-community&#x2F;screen-brightness';

window.testEcho = () => {
const inputValue = document.getElementById("echoInput").value;
ScreenBrightness.echo({ value: inputValue })
}
10 changes: 10 additions & 0 deletions example-app/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'vite';

export default defineConfig({
root: './src',
build: {
outDir: '../dist',
minify: false,
emptyOutDir: true,
},
});
8 changes: 8 additions & 0 deletions ios/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
Loading