Skip to content

Commit

Permalink
echo plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
abegehr committed Apr 16, 2024
1 parent d8636e9 commit 08fc817
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 25 deletions.
27 changes: 22 additions & 5 deletions ios/App/App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/* Begin PBXBuildFile section */
2FAD9763203C412B000D30F8 /* config.xml in Resources */ = {isa = PBXBuildFile; fileRef = 2FAD9762203C412B000D30F8 /* config.xml */; };
3A0D18CA2BCEE83000D03305 /* EchoPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A0D18C92BCEE83000D03305 /* EchoPlugin.swift */; };
3A0D18CD2BCEE86800D03305 /* EchoPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A0D18CC2BCEE86800D03305 /* EchoPlugin.m */; };
4D22ABE92AF431CB00220026 /* CapApp-SPM in Frameworks */ = {isa = PBXBuildFile; productRef = 4D22ABE82AF431CB00220026 /* CapApp-SPM */; };
50379B232058CBB4000EE86E /* capacitor.config.json in Resources */ = {isa = PBXBuildFile; fileRef = 50379B222058CBB4000EE86E /* capacitor.config.json */; };
504EC3081FED79650016851F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504EC3071FED79650016851F /* AppDelegate.swift */; };
Expand All @@ -19,6 +21,9 @@

/* Begin PBXFileReference section */
2FAD9762203C412B000D30F8 /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = config.xml; sourceTree = "<group>"; };
3A0D18C92BCEE83000D03305 /* EchoPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EchoPlugin.swift; sourceTree = "<group>"; };
3A0D18CB2BCEE86700D03305 /* App-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "App-Bridging-Header.h"; sourceTree = "<group>"; };
3A0D18CC2BCEE86800D03305 /* EchoPlugin.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EchoPlugin.m; sourceTree = "<group>"; };
50379B222058CBB4000EE86E /* capacitor.config.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = capacitor.config.json; sourceTree = "<group>"; };
504EC3041FED79650016851F /* App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = App.app; sourceTree = BUILT_PRODUCTS_DIR; };
504EC3071FED79650016851F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -60,13 +65,16 @@
504EC3061FED79650016851F /* App */ = {
isa = PBXGroup;
children = (
50379B222058CBB4000EE86E /* capacitor.config.json */,
3A0D18CB2BCEE86700D03305 /* App-Bridging-Header.h */,
504EC3071FED79650016851F /* AppDelegate.swift */,
504EC30B1FED79650016851F /* Main.storyboard */,
504EC30E1FED79650016851F /* Assets.xcassets */,
504EC3101FED79650016851F /* LaunchScreen.storyboard */,
504EC3131FED79650016851F /* Info.plist */,
50379B222058CBB4000EE86E /* capacitor.config.json */,
2FAD9762203C412B000D30F8 /* config.xml */,
3A0D18CC2BCEE86800D03305 /* EchoPlugin.m */,
3A0D18C92BCEE83000D03305 /* EchoPlugin.swift */,
504EC3131FED79650016851F /* Info.plist */,
504EC3101FED79650016851F /* LaunchScreen.storyboard */,
504EC30B1FED79650016851F /* Main.storyboard */,
50B271D01FEDC1A000F3C39B /* public */,
);
path = App;
Expand Down Expand Up @@ -106,7 +114,7 @@
TargetAttributes = {
504EC3031FED79650016851F = {
CreatedOnToolsVersion = 9.2;
LastSwiftMigration = 1100;
LastSwiftMigration = 1530;
ProvisioningStyle = Automatic;
};
};
Expand Down Expand Up @@ -154,6 +162,8 @@
buildActionMask = 2147483647;
files = (
504EC3081FED79650016851F /* AppDelegate.swift in Sources */,
3A0D18CA2BCEE83000D03305 /* EchoPlugin.swift in Sources */,
3A0D18CD2BCEE86800D03305 /* EchoPlugin.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -291,8 +301,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = EW3E677XMJ;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -304,6 +316,8 @@
PRODUCT_BUNDLE_IDENTIFIER = me.begehr.capacitorsample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OBJC_BRIDGING_HEADER = "App/App-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -313,8 +327,10 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = EW3E677XMJ;
INFOPLIST_FILE = App/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -325,6 +341,7 @@
PRODUCT_BUNDLE_IDENTIFIER = me.begehr.capacitorsample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";
SWIFT_OBJC_BRIDGING_HEADER = "App/App-Bridging-Header.h";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"originHash" : "cc5c8fd0002bb367887e77c3546d22b9a24af4298dae9781fb5085dc16409e10",
"pins" : [
{
"identity" : "capacitor-swift-pm",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ionic-team/capacitor-swift-pm.git",
"state" : {
"branch" : "main",
"revision" : "8a46dff3a8292761df1bded13a508da1c85859e8"
}
}
],
"version" : 3
}
4 changes: 4 additions & 0 deletions ios/App/App/App-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

13 changes: 13 additions & 0 deletions ios/App/App/EchoPlugin.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// EchoPlugin.m
// App
//
// Created by Anton Begehr on 16.04.24.
//

#import <Foundation/Foundation.h>
#import <Capacitor/Capacitor.h>

CAP_PLUGIN(EchoPlugin, "Echo",
CAP_PLUGIN_METHOD(echo, CAPPluginReturnPromise);
)
22 changes: 22 additions & 0 deletions ios/App/App/EchoPlugin.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// EchoPlugin.swift
// App
//
// Created by Anton Begehr on 16.04.24.
//

import Capacitor

@objc(EchoPlugin)
public class EchoPlugin: CAPPlugin {
@objc override public func load() {
debugPrint("EchoPlugin.load()")
}

@objc func echo(_ call: CAPPluginCall) {
debugPrint("EchoPlugin.echo()")
let value = call.getString("value") ?? ""
debugPrint("EchoPlugin.echo - value: \(value)")
call.resolve(["value": value])
}
}
49 changes: 29 additions & 20 deletions src/js/capacitor-welcome.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { SplashScreen } from '@capacitor/splash-screen';
import { Camera } from '@capacitor/camera';
import { SplashScreen } from "@capacitor/splash-screen";
import { Camera } from "@capacitor/camera";
import Echo from "./echo";

const { value } = await Echo.echo({ value: "Hello World!" });
console.log("Response from native:", value);

window.customElements.define(
'capacitor-welcome',
"capacitor-welcome",
class extends HTMLElement {
constructor() {
super();

SplashScreen.hide();

const root = this.attachShadow({ mode: 'open' });
const root = this.attachShadow({ mode: "open" });

root.innerHTML = `
<style>
Expand Down Expand Up @@ -92,32 +96,37 @@ window.customElements.define(
connectedCallback() {
const self = this;

self.shadowRoot.querySelector('#take-photo').addEventListener('click', async function (e) {
try {
const photo = await Camera.getPhoto({
resultType: 'uri',
});
self.shadowRoot
.querySelector("#take-photo")
.addEventListener("click", async function (e) {
try {
const { value } = await Echo.echo({ value: "Take photo!" });
console.log("Response from native:", value);

const image = self.shadowRoot.querySelector('#image');
if (!image) {
return;
}
const photo = await Camera.getPhoto({
resultType: "uri",
});

image.src = photo.webPath;
} catch (e) {
console.warn('User cancelled', e);
}
});
const image = self.shadowRoot.querySelector("#image");
if (!image) {
return;
}

image.src = photo.webPath;
} catch (e) {
console.warn("User cancelled", e);
}
});
}
}
);

window.customElements.define(
'capacitor-welcome-titlebar',
"capacitor-welcome-titlebar",
class extends HTMLElement {
constructor() {
super();
const root = this.attachShadow({ mode: 'open' });
const root = this.attachShadow({ mode: "open" });
root.innerHTML = `
<style>
:host {
Expand Down
5 changes: 5 additions & 0 deletions src/js/echo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { registerPlugin } from "@capacitor/core";

const Echo = registerPlugin("Echo");

export default Echo;

0 comments on commit 08fc817

Please sign in to comment.