Skip to content

feat: 适配HarmonyOS平台 #2

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

Merged
merged 1 commit into from
Jun 26, 2024
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
6 changes: 6 additions & 0 deletions harmony/doc-viewer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test
6 changes: 6 additions & 0 deletions harmony/doc-viewer/BuildProfile.ets
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default class BuildProfile {
static readonly HAR_VERSION = '2.7.8-0.0.1';
static readonly BUILD_MODE_NAME = 'debug';
static readonly DEBUG = true;
static readonly TARGET_NAME = 'default';
}
25 changes: 25 additions & 0 deletions harmony/doc-viewer/build-profile.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"apiType": "stageMode",
"buildOption": {
},
"buildOptionSet": [
{
"name": "release",
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": true,
"files": [
"./obfuscation-rules.txt"
]
}
}
}
},
],
"targets": [
{
"name": "default"
}
]
}
2 changes: 2 additions & 0 deletions harmony/doc-viewer/hvigorfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

export { harTasks } from '@ohos/hvigor-ohos-plugin';
1 change: 1 addition & 0 deletions harmony/doc-viewer/index.ets
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ts'
18 changes: 18 additions & 0 deletions harmony/doc-viewer/obfuscation-rules.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Define project specific obfuscation rules here.
# You can include the obfuscation configuration files in the current module's build-profile.json5.
#
# For more details, see
# https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md

# Obfuscation options:
# -disable-obfuscation: disable all obfuscations
# -enable-property-obfuscation: obfuscate the property names
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
# -compact: remove unnecessary blank spaces and all line feeds
# -remove-log: remove all console.* statements
# -print-namecache: print the name cache that contains the mapping from the old names to new names
# -apply-namecache: reuse the given cache file

# Keep options:
# -keep-property-name: specifies property names that you want to keep
# -keep-global-name: specifies names that you want to keep in the global scope
9 changes: 9 additions & 0 deletions harmony/doc-viewer/oh-package.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@react-native-oh-tpl/react-native-doc-viewer",
"version": "2.7.8-0.0.1",
type: 'module',
dependencies: {
"@rnoh/react-native-openharmony": 'file:../react_native_openharmony'
}
}

64 changes: 64 additions & 0 deletions harmony/doc-viewer/src/main/ets/Log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* MIT License
*
* Copyright (C) 2023 Huawei Device Co., Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import hilog from '@ohos.hilog';

class Logger {
private domain: number;
private prefix: string;
private format: string = '%{public}s';
private isDebug: boolean;

/**
* constructor.
*
* @param Prefix Identifies the log tag.
* @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
*/
constructor(prefix: string = 'MyApp', domain: number = 0xFF00, isDebug = false) {
this.prefix = prefix;
this.domain = domain;
this.isDebug = isDebug;
}

debug(...args: string[]): void {
if (this.isDebug) {
hilog.debug(this.domain, this.prefix, this.format, args);
}
}

info(...args: string[]): void {
hilog.info(this.domain, this.prefix, this.format, args);
}

warn(...args: string[]): void {
hilog.warn(this.domain, this.prefix, this.format, args);
}

error(...args: string[]): void {
hilog.error(this.domain, this.prefix, this.format, args);
}
}

export default new Logger('RNCDocViewer', 0xFF00, false)
80 changes: 80 additions & 0 deletions harmony/doc-viewer/src/main/ets/mime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// 参考 mdn 常见的MIME类型

const mimeMap = {
aac: 'audio/aac',
abw: 'application/x-abiword',
apng: 'image/apng',
arc: 'application/x-freearc',
avif: 'image/avif',
avi: 'video/x-msvideo',
azw: 'application/vnd.amazon.ebook',
bin: 'application/octet-stream',
bmp: 'image/bmp',
bz: 'application/x-bzip',
bz2: 'application/x-bzip2',
cda: 'application/x-cdf',
csh: 'application/x-csh',
css: 'text/css',
csv: 'text/csv',
doc: 'application/msword',
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
eot: 'application/vnd.ms-fontobject',
epub: 'application/epub+zip',
gz: 'application/gzip',
gif: 'image/gif',
htm: 'text/html',
html: 'text/html',
ico: 'image/vnd.microsoft.icon',
ics: 'text/calendar',
jar: 'application/java-archive',
jpeg: 'image/jpeg',
jpg: 'image/jpeg',
js: 'text/javascript',
json: 'application/json',
jsonld: 'application/ld+json',
mid: 'audio/midi',
midi: 'audio/x-midi',
mjs: 'text/javascript',
mp3: 'audio/mpeg',
mp4: 'video/mp4',
mpeg: 'video/mpeg',
odp: 'application/vnd.oasis.opendocument.presentation',
ods: 'application/vnd.oasis.opendocument.spreadsheet',
odt: 'application/vnd.oasis.opendocument.text',
oga: 'audio/ogg',
ogv: 'video/ogg',
ogx: 'application/ogg',
opus: 'audio/opus',
png: 'image/png',
pdf: 'application/pdf',
ppt: 'application/vnd.ms-powerpoint',
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
rar: 'application/vnd.rar',
rtf: 'application/rtf',
sh: 'application/x-sh',
svg: 'image/svg+xml',
tar: 'application/x-tar',
tif: 'image/tiff',
tiff: 'image/tiff',
txt: 'text/plain',
vsd: 'application/vnd.visio',
wav: 'audio/wav',
weba: 'audio/webm',
webm: 'video/webm',
webp: 'image/webp',
woff: 'font/woff',
xhtml: 'application/xhtml+xml',
xls: 'application/vnd.ms-excel',
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
xml: 'application/xml',
xul: 'application/vnd.mozilla.xul+xml',
zip: 'application/zip',
'3gp': 'video/3gpp',
'3g2': 'video/3gpp',
'7z': 'application/x-7z-compressed'
}

export function getMimeType(fileType: string) {
fileType = fileType.toLowerCase()
return mimeMap[fileType] || mimeMap['pdf']
}
21 changes: 21 additions & 0 deletions harmony/doc-viewer/src/main/ets/package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { RNOHContext, RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts'
import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts'
import { DocViewTurboModule } from './turborModules'

class DocViewTurboModulesFactory extends TurboModulesFactory{
createTurboModule(name: string): TurboModule | null {
if (name === 'RNCDocViewer') {
return new DocViewTurboModule(this.ctx)
}
return null
}
hasTurboModule(name: string): boolean {
return name === 'RNCDocViewer'
}
}

export class DocViewPackage extends RNPackage{
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
return new DocViewTurboModulesFactory(ctx)
}
}
Loading