Skip to content

Commit

Permalink
Version_0.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
censujiang committed Oct 29, 2023
1 parent 661501f commit 6573c63
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
18 changes: 9 additions & 9 deletions esm/device.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as origin from 'galanga';
import { clipboard as clipboardO, checkDeviceType as checkDeviceTypeO, checkNotNull, checkNull, share as shareO, shakeObject } from 'galanga';
export const clipboard = {
read: async (onlyString = true) => {
let result;
// #ifdef H5
result = await origin.clipboard.read(onlyString);
result = await clipboardO.read(onlyString);
// #endif
// #ifndef H5
result = await uni.getClipboardData().then((res) => {
Expand All @@ -20,7 +20,7 @@ export const clipboard = {
write: async (value) => {
let result;
// #ifdef H5
result = await origin.clipboard.write(value);
result = await clipboardO.write(value);
// #endif
// #ifndef H5
result = await uni.setClipboardData({
Expand All @@ -38,12 +38,12 @@ export const clipboard = {
export function checkDeviceType(types = ['os', 'browser', 'device', 'platform']) {
let result;
// #ifdef H5
result = origin.checkDeviceType(types);
result = checkDeviceTypeO(types);
// #endif
// #ifndef H5
const res = uni.getSystemInfoSync();
if (res.uniPlatform === 'web') {
return origin.checkDeviceType(types);
return checkDeviceTypeO(types);
}
else {
const deviceInfo = {
Expand All @@ -64,15 +64,15 @@ export function checkDeviceType(types = ['os', 'browser', 'device', 'platform'])
result = deviceInfo[types];
}
else {
result = origin.shakeObject(deviceInfo, types);
result = shakeObject(deviceInfo, types);
}
}
// #endif
return result;
}
export function share({ content = 'none', title = 'galanga', url = '', type = 'system', files = [], } = {}) {
// #ifdef H5
origin.share({
shareO({
content,
title,
url,
Expand All @@ -96,7 +96,7 @@ export function share({ content = 'none', title = 'galanga', url = '', type = 's
if (shareInfo.provider === 'sinaweibo') {
shareInfo.type = 0;
}
if (origin.checkNotNull(url)) {
if (checkNotNull(url)) {
shareInfo.href = url;
}
uni.share(shareInfo);
Expand All @@ -105,7 +105,7 @@ export function share({ content = 'none', title = 'galanga', url = '', type = 's
// #ifndef H5 || APP-PLUS
uni.showShareMenu({
title: title,
content: origin.checkNull(url) ? content : content + '\n' + url,
content: checkNull(url) ? content : content + '\n' + url,
});
// #endif
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uni-helper/galanga",
"version": "0.2.3",
"version": "0.2.4",
"description": "JS common function library(UNI-APP version of Galanga)",
"main": "esm/index.js",
"jsnext:main": "esm/index.js",
Expand Down
25 changes: 16 additions & 9 deletions src/device.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import * as origin from 'galanga'
import {
clipboard as clipboardO,
checkDeviceType as checkDeviceTypeO,
checkNotNull,
checkNull,
share as shareO,
shakeObject
} from 'galanga'
declare const uni: any

export const clipboard = {
read: async (onlyString = true) => {
let result: string | ClipboardItems | null
// #ifdef H5
result = await origin.clipboard.read(onlyString)
result = await clipboardO.read(onlyString)
// #endif
// #ifndef H5
result = await uni.getClipboardData().then((res) => {
Expand All @@ -22,7 +29,7 @@ export const clipboard = {
write: async (value: any) => {
let result: boolean
// #ifdef H5
result = await origin.clipboard.write(value)
result = await clipboardO.write(value)
// #endif
// #ifndef H5
result = await uni.setClipboardData({
Expand All @@ -48,12 +55,12 @@ interface DeviceInfo {
export function checkDeviceType(types: string[] | string = ['os', 'browser', 'device', 'platform']): DeviceInfo | string | object {
let result: DeviceInfo | string | object
// #ifdef H5
result = origin.checkDeviceType(types) as DeviceInfo | string | object
result = checkDeviceTypeO(types) as DeviceInfo | string | object
// #endif
// #ifndef H5
const res = uni.getSystemInfoSync()
if (res.uniPlatform === 'web') {
return origin.checkDeviceType(types) as DeviceInfo | string | object
return checkDeviceTypeO(types) as DeviceInfo | string | object
} else {
const deviceInfo: DeviceInfo = {
os: res.osName,
Expand All @@ -71,7 +78,7 @@ export function checkDeviceType(types: string[] | string = ['os', 'browser', 'de
if (typeof types === 'string') {
result = deviceInfo[types]
} else {
result = origin.shakeObject(deviceInfo, types);
result = shakeObject(deviceInfo, types);
}
}
// #endif
Expand All @@ -96,7 +103,7 @@ export function share({
files = [] as File[],
} = {}) {
// #ifdef H5
origin.share({
shareO({
content,
title,
url,
Expand All @@ -119,7 +126,7 @@ export function share({
if (shareInfo.provider === 'sinaweibo') {
shareInfo.type = 0
}
if (origin.checkNotNull(url)) {
if (checkNotNull(url)) {
shareInfo.href = url
}
uni.share(shareInfo)
Expand All @@ -128,7 +135,7 @@ export function share({
// #ifndef H5 || APP-PLUS
uni.showShareMenu({
title: title,
content: origin.checkNull(url) ? content : content + '\n' + url,
content: checkNull(url) ? content : content + '\n' + url,
})
// #endif
}

0 comments on commit 6573c63

Please sign in to comment.