Skip to content

Commit

Permalink
Merge branch 'main' into RDMR-298
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Dec 12, 2024
2 parents 9d05f41 + 1d5798f commit da92e09
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 91 deletions.
5 changes: 0 additions & 5 deletions core/src/definitions-internal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { CapacitorGlobal, PluginCallback, PluginResultData, PluginResultError } from './definitions';
import type { CapacitorPlatformsInstance } from './platforms';

export interface PluginHeaderMethod {
readonly name: string;
Expand Down Expand Up @@ -148,10 +147,6 @@ export interface WindowCapacitor {
CapacitorHttpAndroidInterface?: any;
CapacitorWebFetch?: any;
CapacitorWebXMLHttpRequest?: any;
/**
* @deprecated Use `CapacitorCustomPlatform` instead
*/
CapacitorPlatforms?: CapacitorPlatformsInstance;
CapacitorCustomPlatform?: CapacitorCustomPlatformInstance;
Ionic?: {
WebView?: {
Expand Down
3 changes: 0 additions & 3 deletions core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ export type {
PluginResultError,
} from './definitions';

// Platforms Map
export { CapacitorPlatforms, addPlatform, setPlatform } from './platforms';

// Global APIs
export { Capacitor, registerPlugin } from './global';

Expand Down
68 changes: 0 additions & 68 deletions core/src/platforms.ts

This file was deleted.

20 changes: 5 additions & 15 deletions core/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
PluginHeader,
WindowCapacitor,
} from './definitions-internal';
import type { CapacitorPlatformsInstance } from './platforms';
import { CapacitorException, getPlatformId, ExceptionCode } from './util';

export interface RegisteredPlugin {
Expand All @@ -18,20 +17,14 @@ export const createCapacitor = (win: WindowCapacitor): CapacitorInstance => {
const capCustomPlatform: CapacitorCustomPlatformInstance = win.CapacitorCustomPlatform || null;
const cap: CapacitorInstance = win.Capacitor || ({} as any);
const Plugins = (cap.Plugins = cap.Plugins || ({} as any));
/**
* @deprecated Use `capCustomPlatform` instead, default functions like registerPlugin will function with the new object.
*/
const capPlatforms: CapacitorPlatformsInstance = win.CapacitorPlatforms;

const defaultGetPlatform = () => {
const getPlatform = () => {
return capCustomPlatform !== null ? capCustomPlatform.name : getPlatformId(win);
};
const getPlatform = capPlatforms?.currentPlatform?.getPlatform || defaultGetPlatform;

const defaultIsNativePlatform = () => getPlatform() !== 'web';
const isNativePlatform = capPlatforms?.currentPlatform?.isNativePlatform || defaultIsNativePlatform;
const isNativePlatform = () => getPlatform() !== 'web';

const defaultIsPluginAvailable = (pluginName: string): boolean => {
const isPluginAvailable = (pluginName: string): boolean => {
const plugin = registeredPlugins.get(pluginName);

if (plugin?.platforms.has(getPlatform())) {
Expand All @@ -46,17 +39,15 @@ export const createCapacitor = (win: WindowCapacitor): CapacitorInstance => {

return false;
};
const isPluginAvailable = capPlatforms?.currentPlatform?.isPluginAvailable || defaultIsPluginAvailable;

const defaultGetPluginHeader = (pluginName: string): PluginHeader | undefined =>
const getPluginHeader = (pluginName: string): PluginHeader | undefined =>
cap.PluginHeaders?.find((h) => h.name === pluginName);
const getPluginHeader = capPlatforms?.currentPlatform?.getPluginHeader || defaultGetPluginHeader;

const handleError = (err: Error) => win.console.error(err);

const registeredPlugins = new Map<string, RegisteredPlugin>();

const defaultRegisterPlugin = (pluginName: string, jsImplementations: PluginImplementations = {}): any => {
const registerPlugin = (pluginName: string, jsImplementations: PluginImplementations = {}): any => {
const registeredPlugin = registeredPlugins.get(pluginName);
if (registeredPlugin) {
console.warn(`Capacitor plugin "${pluginName}" already registered. Cannot register plugins twice.`);
Expand Down Expand Up @@ -199,7 +190,6 @@ export const createCapacitor = (win: WindowCapacitor): CapacitorInstance => {

return proxy;
};
const registerPlugin = capPlatforms?.currentPlatform?.registerPlugin || defaultRegisterPlugin;

// Add in convertFileSrc for web, it will already be available in native context
if (!cap.convertFileSrc) {
Expand Down

0 comments on commit da92e09

Please sign in to comment.