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

initial stubs #3

Merged
merged 7 commits into from
Nov 29, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class CompanycamVibeCheckModule(reactContext: ReactApplicationContext) :
fun multiply(a: Double, b: Double, promise: Promise) {
promise.resolve(a * b)
}
// fun getCurrentVibes(promise: Promise) {
// promise.resolve();
// }

companion object {
const val NAME = "CompanycamVibeCheck"
Expand Down
8 changes: 7 additions & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ PODS:
- React-jsi (= 0.72.7)
- React-logger (= 0.72.7)
- React-perflogger (= 0.72.7)
- RNDeviceInfo (10.12.0):
- React-Core
- SocketRocket (0.6.1)
- Yoga (1.14.0)
- YogaKit (1.18.1):
Expand Down Expand Up @@ -557,6 +559,7 @@ DEPENDENCIES:
- React-runtimescheduler (from `../node_modules/react-native/ReactCommon/react/renderer/runtimescheduler`)
- React-utils (from `../node_modules/react-native/ReactCommon/react/utils`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- RNDeviceInfo (from `../node_modules/react-native-device-info`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

SPEC REPOS:
Expand Down Expand Up @@ -656,6 +659,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/react/utils"
ReactCommon:
:path: "../node_modules/react-native/ReactCommon"
RNDeviceInfo:
:path: "../node_modules/react-native-device-info"
Yoga:
:path: "../node_modules/react-native/ReactCommon/yoga"

Expand Down Expand Up @@ -711,10 +716,11 @@ SPEC CHECKSUMS:
React-runtimescheduler: 7649c3b46c8dee1853691ecf60146a16ae59253c
React-utils: 56838edeaaf651220d1e53cd0b8934fb8ce68415
ReactCommon: 5f704096ccf7733b390f59043b6fa9cc180ee4f6
RNDeviceInfo: db5c64a060e66e5db3102d041ebe3ef307a85120
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: 40107a9462d13c1b70b4400bb6ce65c797be5a6a

COCOAPODS: 1.12.1
COCOAPODS: 1.14.3
3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"dependencies": {
"react": "18.2.0",
"react-native": "0.72.7"
"react-native": "0.72.7",
"react-native-device-info": "^10.12.0"
},
"devDependencies": {
"@babel/core": "^7.20.0",
Expand Down
14 changes: 9 additions & 5 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import * as React from 'react';

import { StyleSheet, View, Text } from 'react-native';
import { multiply } from 'companycam-vibe-check';
import { getCurrentVibe, type FullVibeCheckType } from 'companycam-vibe-check';

export default function App() {
const [result, setResult] = React.useState<number | undefined>();
const [info, setInfo] = React.useState<FullVibeCheckType>();

// I am a meaningless comment
React.useEffect(() => {
multiply(3, 7).then(setResult);
const lookAtVibe = async () => {
const vibe = await getCurrentVibe();
setInfo(vibe);
};

lookAtVibe();
}, []);

return (
<View style={styles.container}>
<Text>Result: {result}</Text>
<Text>Device Info: {JSON.stringify(info)} </Text>
</View>
);
}
Expand Down
4 changes: 4 additions & 0 deletions ios/CompanycamVibeCheck.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ @interface RCT_EXTERN_MODULE(CompanycamVibeCheck, NSObject)
withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)

// RCT_EXTERN_METHOD(getThermalState) {
// return @"omfg";
// }

+ (BOOL)requiresMainQueueSetup
{
return NO;
Expand Down
4 changes: 4 additions & 0 deletions ios/CompanycamVibeCheck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ class CompanycamVibeCheck: NSObject {
func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
resolve(a*b)
}
// @objc(getCurrentVibes:withResolver:withRejecter:)
// func getCurrentVibes() -> Void {
// resolve();
// }
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"react": "18.2.0",
"react-native": "0.72.7",
"react-native-builder-bob": "^0.20.0",
"react-native-device-info": "^10.12.0",
"release-it": "^15.0.0",
"semantic-release": "^22.0.7",
"turbo": "^1.10.7",
Expand All @@ -82,7 +83,8 @@
},
"peerDependencies": {
"react": "*",
"react-native": "*"
"react-native": "*",
"react-native-device-info": "*"
},
"workspaces": [
"example"
Expand Down
135 changes: 133 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { NativeModules, Platform } from 'react-native';
import DeviceInfo from 'react-native-device-info';
import type { BatteryState } from 'react-native-device-info/lib/typescript/internal/types';

const LINKING_ERROR =
`The package 'companycam-vibe-check' doesn't seem to be linked. Make sure: \n\n` +
Expand All @@ -17,6 +19,135 @@ const CompanycamVibeCheck = NativeModules.CompanycamVibeCheck
}
);

export function multiply(a: number, b: number): Promise<number> {
export type FullVibeCheckType = {
battery: Awaited<BatteryVibeType>;
connectivity: ConnectionVibeType;
cpuUsage: number;
diskUsage: Awaited<number>;
ramUsage: number;
thermalState: string;
};

type BatteryVibeType = {
batteryLevel: number | undefined;
batteryState: BatteryState | undefined;
lowPowerMode: boolean | undefined;
isBatteryCharging: boolean;
};

type ConnectionVibeType = {
connection: {
isConnected: boolean;
isInternetReachable: boolean;
type: string;
details: {
isConnectionExpensive: boolean;
cellularGeneration: string;
};
};
};

export const multiply = (a: number, b: number): Promise<number> => {
return CompanycamVibeCheck.multiply(a, b);
}
};

/**
* Function to get device's current {@link https://github.com/CompanyCam/companycam-vibe-check/blob/main/README.md#getcurrentvibes | Vibes}.
* @returns A FullVibeCheckType object that contains all current device vibes.
*/
export const getCurrentVibe = async (): Promise<FullVibeCheckType> => {
const battery = await getBatteryInfo();
const connectivity = getConnectionInfo();
const cpuUsage = getCPUUsage();
const diskUsage = await getDiskUsage();
const ramUsage = getRAMUsage();
const thermalState = getThermalState();

return {
battery,
connectivity,
cpuUsage,
diskUsage,
ramUsage,
thermalState,
};
};

///
// TODO: Add in threshold for battery level notifications
// EX: If the battery level is < X%, we should notify the user
///

/**
* Gets the current Battery info from the DeviceInfo library
* @returns A BatteryVibeType object that contains all data related to Battery Info
*/
export const getBatteryInfo = async (): Promise<BatteryVibeType> => {
const isBatteryCharging = await DeviceInfo.isBatteryCharging();
const { batteryLevel, batteryState, lowPowerMode } =
await DeviceInfo.getPowerState();
const batteryVibe = {
batteryLevel,
batteryState,
lowPowerMode,
isBatteryCharging,
};
console.log(batteryVibe);
return batteryVibe;
};

/**
* Gets the current Connection info from the Reachability library
* @returns A ConnectionVibeType object that contains all data related to Connection Info
*/
export const getConnectionInfo = (): ConnectionVibeType => {
console.log('getConnectionVibe');
const connectionVibe = {
connection: {
isConnected: true,
isInternetReachable: true,
type: 'cellular',
details: {
isConnectionExpensive: false,
cellularGeneration: '4g',
},
},
};

return connectionVibe;
};

/**
* Gets the percentage of the CPU currently being used.
* @returns Current CPU usage percentage
*/
export const getCPUUsage = (): number => {
return 20.0;
};

/**
* Gets the total percentage of used disk space on the device from the DeviceInfo library.
* @returns Current percentage of utilized disk space
*/
export const getDiskUsage = async () => {
const freeDiskSpace = await DeviceInfo.getFreeDiskStorage();
const totalDiskSpace = await DeviceInfo.getTotalDiskCapacity();
const percentageOfDiskSpaceUsed = freeDiskSpace / totalDiskSpace;
return percentageOfDiskSpaceUsed;
};

/**
* Gets the total percentage of used RAM on the device.
* @returns Current percentage of utilized RAM
*/
export const getRAMUsage = (): number => {
return 20.0;
};

/**
* Gets the current ThermalState from the hardware
* @returns Current ThermalState from the hardware.
*/
export const getThermalState = (): string => {
return 'fair';
};
Loading