mirror of
https://gitee.com/openharmony/applications_notes
synced 2024-12-04 05:49:30 +00:00
!92 修复流转中发现的bug,解决日志不能正常打印
Merge pull request !92 from tangyiqiang/master
This commit is contained in:
commit
eeacadeab7
@ -443,7 +443,7 @@ export struct DeleteNoteComp {
|
||||
let context: any = getContext(this)
|
||||
let resource = {
|
||||
bundleName: "com.ohos.note",
|
||||
moduleName: "phone",
|
||||
moduleName: "tablet",
|
||||
id: $r('app.string.restore').id
|
||||
};
|
||||
context.resourceManager.getString(resource, (error, value) => {
|
||||
|
@ -894,7 +894,7 @@ export struct OperateNoteCompForPortrait {
|
||||
let context: any = getContext(this)
|
||||
let resource = {
|
||||
bundleName: "com.ohos.note",
|
||||
moduleName: "phone",
|
||||
moduleName: "tablet",
|
||||
id: $r('app.string.restore').id
|
||||
};
|
||||
context.resourceManager.getString(resource, (error, value) => {
|
||||
|
@ -12,40 +12,37 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Log Util
|
||||
*/
|
||||
import hilog from '@ohos.hilog'
|
||||
|
||||
export class LogUtil {
|
||||
private static readonly IS_DEBUG_ON: boolean = false;
|
||||
private static readonly CONTACTS_DOMAIN: string = "00902";
|
||||
private static readonly CONTACTS_DOMAIN: number = 0x0927;
|
||||
private static readonly SLASH: string = "/";
|
||||
private static readonly COLON: string = ": ";
|
||||
constructor() {
|
||||
}
|
||||
|
||||
private static prefix(tag: string) {
|
||||
return this.CONTACTS_DOMAIN + this.SLASH + tag + this.COLON;
|
||||
return this.SLASH + tag + this.COLON;
|
||||
}
|
||||
|
||||
static debug(tag: string, msg: string, ...args: any[]) {
|
||||
if (this.IS_DEBUG_ON) {
|
||||
console.info(this.prefix(tag) + msg, args);
|
||||
hilog.info(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args);
|
||||
} else {
|
||||
console.debug(this.prefix(tag) + msg, args);
|
||||
hilog.debug(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args);
|
||||
}
|
||||
}
|
||||
|
||||
static info(tag: string, msg: string, ...args: any[]) {
|
||||
console.info(this.prefix(tag) + msg, args);
|
||||
hilog.info(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args);
|
||||
}
|
||||
|
||||
static warn(tag: string, msg: string, ...args: any[]) {
|
||||
console.warn(this.prefix(tag) + msg, args);
|
||||
hilog.warn(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args);
|
||||
}
|
||||
|
||||
static error(tag: string, msg: string, ...args: any[]) {
|
||||
console.error(this.prefix(tag) + msg, args);
|
||||
hilog.error(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args);
|
||||
}
|
||||
}
|
@ -341,16 +341,24 @@ export default {
|
||||
} catch (err) {
|
||||
LogUtil.warn(TAG, "desPath has not existed, need to write")
|
||||
}
|
||||
|
||||
let srcPath = globalThis.noteContext.distributedFilesDir + "/" + fileName
|
||||
LogUtil.info(TAG, "srcPath : " + srcPath)
|
||||
let size = fileio.statSync(srcPath).size
|
||||
LogUtil.info(TAG, "srcPath size : " + size)
|
||||
if (size > FileMaxSize) {
|
||||
LogUtil.warn(TAG, "srcPath size more then FileMaxSize, return")
|
||||
let srcPath
|
||||
let size
|
||||
try{
|
||||
srcPath = globalThis.noteContext.distributedFilesDir + "/" + fileName
|
||||
LogUtil.info(TAG, "srcPath : " + srcPath)
|
||||
size = fileio.statSync(srcPath).size
|
||||
LogUtil.info(TAG, "srcPath size : " + size)
|
||||
if (size > FileMaxSize) {
|
||||
LogUtil.warn(TAG, "srcPath size more then FileMaxSize, return")
|
||||
return
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
LogUtil.warn(TAG, "desPath has not existed, need to write two")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let srcFd
|
||||
try {
|
||||
srcFd = fileio.openSync(srcPath, 0o0)
|
||||
|
@ -18,13 +18,15 @@ import deviceInfo from '@ohos.deviceInfo';
|
||||
import AbilityConstant from '@ohos.application.AbilityConstant'
|
||||
import fileio from '@ohos.fileio'
|
||||
import inputMethod from '@ohos.inputmethod';
|
||||
import { LogUtil } from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil'
|
||||
import { atob } from 'js-base64'
|
||||
globalThis.rdbStore = undefined
|
||||
export default class MainAbility extends Ability {
|
||||
private Tag = "MainAbility_Tablet"
|
||||
|
||||
onCreate(want, launchParam) {
|
||||
console.info(this.Tag + " onCreate, launchReason is " + launchParam.launchReason)
|
||||
console.info(this.Tag + " onCreate, deviceType" + deviceInfo.deviceType)
|
||||
LogUtil.info(this.Tag, " onCreate, launchReason is " + launchParam.launchReason)
|
||||
LogUtil.info(this.Tag, " onCreate, deviceType" + deviceInfo.deviceType)
|
||||
if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') {
|
||||
AppStorage.SetOrCreate<boolean>('Expand', false)
|
||||
AppStorage.SetOrCreate<boolean>('Choose', true)
|
||||
@ -35,17 +37,17 @@ export default class MainAbility extends Ability {
|
||||
// 获取对端的迁移数据
|
||||
let continueNote: string = want.parameters["ContinueNote"]
|
||||
let continueSection: number = want.parameters["ContinueSection"]
|
||||
console.info(this.Tag + " continueSection : " + continueSection)
|
||||
LogUtil.info(this.Tag, " continueSection : " + continueSection)
|
||||
AppStorage.SetOrCreate<string>('ContinueNote', continueNote)
|
||||
AppStorage.SetOrCreate<number>('ContinueSection', continueSection)
|
||||
// 来自手机的迁移
|
||||
let continueChoose: boolean = want.parameters["ContinueChoose"]
|
||||
if (continueChoose) {
|
||||
console.info(this.Tag + " continue from phone")
|
||||
LogUtil.info(this.Tag, " continue from phone")
|
||||
AppStorage.SetOrCreate<boolean>('ContinueFromPhone', true)
|
||||
} else {
|
||||
AppStorage.SetOrCreate<boolean>('ContinueFromTablet', true)
|
||||
console.info(this.Tag + " continue from tablet")
|
||||
LogUtil.info(this.Tag, " continue from tablet")
|
||||
}
|
||||
this.context.restoreWindowStage(null)
|
||||
}
|
||||
@ -53,43 +55,43 @@ export default class MainAbility extends Ability {
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
console.info(this.Tag + " onDestroy")
|
||||
LogUtil.info(this.Tag, " onDestroy")
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage) {
|
||||
console.info(this.Tag + " onWindowStageCreate")
|
||||
LogUtil.info(this.Tag, " onWindowStageCreate")
|
||||
windowStage.setUIContent(this.context, "pages/MyNoteHome", null)
|
||||
}
|
||||
|
||||
onWindowStageDestroy() {
|
||||
console.info(this.Tag + " onWindowStageDestroy")
|
||||
LogUtil.info(this.Tag, " onWindowStageDestroy")
|
||||
}
|
||||
|
||||
onForeground() {
|
||||
console.info(this.Tag + " onForeground")
|
||||
LogUtil.info(this.Tag, " onForeground")
|
||||
}
|
||||
|
||||
onBackground() {
|
||||
console.info(this.Tag + " onBackground")
|
||||
LogUtil.info(this.Tag, " onBackground")
|
||||
// 退出键盘
|
||||
inputMethod.getInputMethodController().stopInput();
|
||||
}
|
||||
|
||||
onContinue(wantParam: { [key: string]: any }) {
|
||||
console.info(this.Tag + " onContinue")
|
||||
LogUtil.info(this.Tag, " onContinue")
|
||||
// 获取本端的迁移数据
|
||||
let continueNote = AppStorage.Get<string>('ContinueNote')
|
||||
if (continueNote == undefined || continueNote == null) {
|
||||
console.info(this.Tag + " onContinue, continueNote is error, default [0]")
|
||||
LogUtil.info(this.Tag, " onContinue, continueNote is error, default [0]")
|
||||
continueNote = JSON.stringify(AppStorage.Get('AllNoteArray')[0].toNoteObject())
|
||||
}
|
||||
|
||||
let continueSection = AppStorage.Get<number>('ContinueSection')
|
||||
if (continueSection == undefined || continueSection == null) {
|
||||
console.info(this.Tag + " onContinue, continueSection is error, default 3")
|
||||
LogUtil.info(this.Tag, " onContinue, continueSection is error, default 3")
|
||||
continueSection = 3
|
||||
}
|
||||
console.info(this.Tag + " onContinue, continueSection : " + continueSection)
|
||||
LogUtil.info(this.Tag, " onContinue, continueSection : " + continueSection)
|
||||
|
||||
// 保存本端的迁移数据
|
||||
wantParam["ContinueNote"] = continueNote
|
||||
@ -99,7 +101,7 @@ export default class MainAbility extends Ability {
|
||||
}
|
||||
|
||||
// save img to DisFileDir
|
||||
console.info(this.Tag + " onContinue, save img to DisFileDir")
|
||||
LogUtil.info(this.Tag, " onContinue, save img to DisFileDir")
|
||||
let continueNoteObj = JSON.parse(continueNote)
|
||||
let srcArray = this.getSrcFromHtml(continueNoteObj.content_text)
|
||||
srcArray.forEach((src: string) => {
|
||||
@ -109,7 +111,7 @@ export default class MainAbility extends Ability {
|
||||
this.writeToDisFileDir(imgName)
|
||||
}
|
||||
})
|
||||
console.info(this.Tag + " onContinue end")
|
||||
LogUtil.info(this.Tag, " onContinue end")
|
||||
return AbilityConstant.OnContinueResult.AGREE
|
||||
}
|
||||
|
||||
@ -118,14 +120,15 @@ export default class MainAbility extends Ability {
|
||||
if (html == undefined || html == null || html == "") {
|
||||
return srcArray
|
||||
}
|
||||
let realHtml = atob(html)
|
||||
let imgReg = /<img[^>]+>/g
|
||||
let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i
|
||||
let imgArray = html.match(imgReg)
|
||||
let imgArray = realHtml.match(imgReg)
|
||||
if (imgArray != null) {
|
||||
for (let i = 0; i < imgArray.length; i++) {
|
||||
let src = imgArray[i].match(srcReg)
|
||||
if (src != null && src.length > 1) {
|
||||
console.info(this.Tag + " getSrcFromHtml, src[1] : " + src[1])
|
||||
LogUtil.info(this.Tag, " getSrcFromHtml, src[1] : " + src[1])
|
||||
srcArray.push(src[1])
|
||||
}
|
||||
}
|
||||
@ -134,16 +137,16 @@ export default class MainAbility extends Ability {
|
||||
}
|
||||
|
||||
writeToDisFileDir(fileName: string) {
|
||||
console.info(this.Tag + " writeToDisFileDir, fileName : " + fileName)
|
||||
LogUtil.info(this.Tag, " writeToDisFileDir, fileName : " + fileName)
|
||||
let filesDir = this.context.filesDir
|
||||
let srcPath = filesDir + "/" + fileName
|
||||
let distributedFilesDir = this.context.distributedFilesDir
|
||||
let desPath = distributedFilesDir + "/" + fileName
|
||||
try {
|
||||
fileio.copyFileSync(srcPath, desPath)
|
||||
console.info(this.Tag + " onContinue, writeToDisFileDir, copyFile successfully")
|
||||
LogUtil.info(this.Tag, " onContinue, writeToDisFileDir, copyFile successfully" + desPath + " " + srcPath)
|
||||
} catch (err) {
|
||||
console.warn(this.Tag + " onContinue, writeToDisFileDir, copyFile failed : " + err)
|
||||
LogUtil.warn(this.Tag, " onContinue, writeToDisFileDir, copyFile failed : " + err)
|
||||
}
|
||||
}
|
||||
}
|
@ -58,11 +58,13 @@ export struct MyNoteHomeComp {
|
||||
|
||||
let permissionList: Array<string> = [
|
||||
"ohos.permission.READ_MEDIA",
|
||||
"ohos.permission.WRITE_MEDIA",
|
||||
"ohos.permission.DISTRIBUTED_DATASYNC"
|
||||
]
|
||||
if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') {
|
||||
permissionList = [
|
||||
"ohos.permission.READ_MEDIA",
|
||||
"ohos.permission.WRITE_MEDIA",
|
||||
"ohos.permission.MEDIA_LOCATION",
|
||||
"ohos.permission.DISTRIBUTED_DATASYNC"
|
||||
]
|
||||
|
@ -28,6 +28,10 @@
|
||||
"name": "ohos.permission.READ_MEDIA",
|
||||
"reason": "$string:read_media_permission"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.WRITE_MEDIA",
|
||||
"reason": "$string:write_media_permission"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.MEDIA_LOCATION",
|
||||
"reason": "$string:media_location_permission"
|
||||
|
@ -11,6 +11,10 @@
|
||||
{
|
||||
"name": "distributed_dataSync_permission",
|
||||
"value": "Used for memo data exchange between different equipment"
|
||||
},
|
||||
{
|
||||
"name": "write_media_permission",
|
||||
"value": "Used to write media file information in external storage of users"
|
||||
}
|
||||
]
|
||||
}
|
@ -11,6 +11,10 @@
|
||||
{
|
||||
"name": "distributed_dataSync_permission",
|
||||
"value": "用于备忘录进行不同设备间的数据交换"
|
||||
},
|
||||
{
|
||||
"name": "write_media_permission",
|
||||
"value": "用于备忘录记录用户外部存储中的图片文件信息"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user