Skip to content

Commit

Permalink
feat!: add support for Capacitor 3
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Update to Capacitor 3
  • Loading branch information
robingenz authored Apr 9, 2021
2 parents b8643ee + ddc0ea4 commit a8a361b
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 66 deletions.
2 changes: 1 addition & 1 deletion CapacitorCommunityKeepAwake.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
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.android.tools.build:gradle:4.1.2'
}
}

Expand Down
3 changes: 2 additions & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Fri Feb 12 14:20:40 WET 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import android.view.Window;
import android.view.WindowManager;
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
@CapacitorPlugin(name = "KeepAwake")
public class KeepAwake extends Plugin {

@PluginMethod
Expand Down
8 changes: 4 additions & 4 deletions ios/Plugin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -429,7 +429,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand All @@ -452,7 +452,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Plugin/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)\n$(FRAMEWORK_SEARCH_PATHS)\n$(FRAMEWORK_SEARCH_PATHS)";
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.getcapacitor.Plugin;
Expand All @@ -477,7 +477,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Plugin/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)";
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = com.getcapacitor.Plugin;
Expand Down
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :ios, '11.0'
platform :ios, '12.0'

def capacitor_pods
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
Expand Down
28 changes: 18 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"author": "Kevin Boosten <kboosten@icloud.com>",
"license": "MIT",
"devDependencies": {
"@capacitor/android": "^2.4.1",
"@capacitor/core": "^2.4.1",
"@capacitor/ios": "^2.4.1",
"@capacitor/android": "^3.0.0-beta.2",
"@capacitor/core": "^3.0.0-beta.2",
"@capacitor/ios": "^3.0.0-beta.2",
"@ionic/prettier-config": "^1.0.0",
"@ionic/swiftlint-config": "^1.0.0",
"@rollup/plugin-node-resolve": "^8.1.0",
Expand All @@ -33,7 +33,7 @@
"typescript": "~3.8.3"
},
"peerDependencies": {
"@capacitor/core": "^2.4.1"
"@capacitor/core": "^3.0.0-beta.2"
},
"files": [
"dist/",
Expand Down
33 changes: 17 additions & 16 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import nodeResolve from '@rollup/plugin-node-resolve';

export default {
input: 'dist/esm/index.js',
output: {
file: 'dist/plugin.js',
format: 'iife',
name: 'capacitorPlugin', // TODO: change this
globals: {
'@capacitor/core': 'capacitorExports',
output: [
{
file: 'dist/plugin.js',
format: 'iife',
name: 'capacitorKeepAwake',
globals: {
'@capacitor/core': 'capacitorExports',
},
sourcemap: true,
inlineDynamicImports: true,
},
{
file: 'dist/plugin.cjs.js',
format: 'cjs',
sourcemap: true,
inlineDynamicImports: true,
},
sourcemap: true,
},
plugins: [
nodeResolve({
// allowlist of dependencies to bundle in
// @see https://github.com/rollup/plugins/tree/master/packages/node-resolve#resolveonly
resolveOnly: ['lodash'],
}),
],
external: ['@capacitor/core'],
};
6 changes: 0 additions & 6 deletions src/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
declare module '@capacitor/core' {
interface PluginRegistry {
KeepAwake: KeepAwakePlugin;
}
}

export interface KeepAwakePlugin {
keepAwake(): Promise<void>;
allowSleep(): Promise<void>;
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
import { registerPlugin } from '@capacitor/core';
import type { KeepAwakePlugin } from './definitions';

const KeepAwake = registerPlugin<KeepAwakePlugin>('KeepAwake', {
web: () => import('./web').then(m => new m.KeepAwakeWeb()),
});

export * from './definitions';
export * from './web';
export { KeepAwake };
10 changes: 1 addition & 9 deletions src/web.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { registerWebPlugin, WebPlugin } from '@capacitor/core';
import { WebPlugin } from '@capacitor/core';
import { KeepAwakePlugin } from './definitions';

export class KeepAwakeWeb extends WebPlugin implements KeepAwakePlugin {
constructor() {
super({
name: 'KeepAwake',
platforms: ['web'],
});
}
async keepAwake(): Promise<void> {
console.log('KeepAwake does not support web');
return Promise.resolve();
Expand All @@ -22,5 +16,3 @@ export class KeepAwakeWeb extends WebPlugin implements KeepAwakePlugin {
const KeepAwake = new KeepAwakeWeb();

export { KeepAwake };

registerWebPlugin(KeepAwake);
13 changes: 4 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
"allowUnreachableCode": false,
"declaration": true,
"esModuleInterop": true,
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"lib": ["dom", "es2017"],
"module": "esnext",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
Expand All @@ -16,9 +13,7 @@
"pretty": true,
"sourceMap": true,
"strict": true,
"target": "es2015"
"target": "es2017"
},
"files": [
"src/index.ts"
]
"files": ["src/index.ts"]
}

0 comments on commit a8a361b

Please sign in to comment.