From 7592c17b3e83ae70d9900251715cadb2e73e4a63 Mon Sep 17 00:00:00 2001 From: ye-qianqian1997 Date: Thu, 12 Sep 2024 10:33:49 +0800 Subject: [PATCH 1/2] =?UTF-8?q?note=204.1-Release=20jscrash=20=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ye-qianqian1997 --- .../main/ets/components/NoteContentComp.ets | 230 ++++++++++++------ .../src/main/ets/components/NoteListComp.ets | 2 +- 2 files changed, 152 insertions(+), 80 deletions(-) diff --git a/features/src/main/ets/components/NoteContentComp.ets b/features/src/main/ets/components/NoteContentComp.ets index 555d401..1b45e23 100644 --- a/features/src/main/ets/components/NoteContentComp.ets +++ b/features/src/main/ets/components/NoteContentComp.ets @@ -69,8 +69,12 @@ export struct NoteContentComp { if (!this.refreshCurrentNote) { return } - this.controllerShow.runJavaScript("RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')") - this.refreshCurrentNote = false + try { + this.controllerShow.runJavaScript("RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')") + this.refreshCurrentNote = false + } catch (e) { + console.info('WebviewController', e); + } } storeScrollTop(scrollTop: number) { @@ -88,9 +92,13 @@ export struct NoteContentComp { if (scrollTopPercent < 0) { return } - this.controllerShow.runJavaScript( - 'document.documentElement.scrollTop = ' + this.controllerShow.getPageHeight() * scrollTopPercent - ) + try { + this.controllerShow.runJavaScript( + 'document.documentElement.scrollTop = ' + this.controllerShow.getPageHeight() * scrollTopPercent + ) + } catch (e) { + console.info('WebviewController', e); + } } restoreFocus() { @@ -190,7 +198,11 @@ export struct NoteContentComp { realHtml = "file://" + filePath } LogUtil.info(TAG, 'paste info11-' + realHtml) - this.controllerShow.runJavaScript("javascript:RICH_EDITOR.insertImageHtml('" + realHtml + "')") + try { + this.controllerShow.runJavaScript("javascript:RICH_EDITOR.insertImageHtml('" + realHtml + "')") + } catch (e) { + console.info('WebviewController', e); + } LogUtil.info(TAG, 'paste info11--' + realHtml) } else { LogUtil.info(TAG, 'paste info22225') @@ -235,33 +247,45 @@ export struct NoteContentComp { }) .enabled(this.sectionStatus !== 1 ? false : true) .onPageEnd((e) => { - if (this.dpi <= 240) { - this.controllerShow.runJavaScript("changeSizeToRk()") - } else if (this.dpi <= 320 && this.dpi > 240) { - this.controllerShow.runJavaScript("changeSizeToPhone()") - } else { - this.controllerShow.runJavaScript("changeSizeToTablet()") - } - if (AppStorage.Get('breakPoint') !== 'sm') { - this.controllerShow.runJavaScript("hiddenButton()") + try { + if (this.dpi <= 240) { + this.controllerShow.runJavaScript("changeSizeToRk()") + } else if (this.dpi <= 320 && this.dpi > 240) { + this.controllerShow.runJavaScript("changeSizeToPhone()") + } else { + this.controllerShow.runJavaScript("changeSizeToTablet()") + } + if (AppStorage.Get('breakPoint') !== 'sm') { + this.controllerShow.runJavaScript("hiddenButton()") + } + } catch (e) { + console.info('WebviewController', e); } LogUtil.info(TAG, "finish loadurl") if (this.selectedNoteData) { let self = this - this.controllerShow.runJavaScript( - "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')", - () => { - // wait for the image in the note to load - setTimeout(function () { - self.restoreScrollTop() - self.restoreFocus() - }, 100) - } - ) + try { + this.controllerShow.runJavaScript( + "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')", + () => { + // wait for the image in the note to load + setTimeout(function () { + self.restoreScrollTop() + self.restoreFocus() + }, 100) + } + ) + } catch (e) { + console.info('WebviewController', e); + } } // 初次加载为为小屏预览模式 if (this.sectionStatus != 1) { - this.controllerShow.runJavaScript("RICH_EDITOR.setInputEnabled(false)") + try { + this.controllerShow.runJavaScript("RICH_EDITOR.setInputEnabled(false)") + } catch (e) { + console.info('WebviewController', e); + } } }) .imageAccess(true) @@ -288,14 +312,18 @@ export struct NoteContentComp { this.asideWidth = 0 this.lastSectionStatus = this.sectionStatus this.sectionStatus = 1 - this.controllerShow.runJavaScript("RICH_EDITOR.setInputEnabled(true)") - // 添加定时器:3s自动保存 - if (timeId) { - clearInterval(timeId) + try { + this.controllerShow.runJavaScript("RICH_EDITOR.setInputEnabled(true)") + // 添加定时器:3s自动保存 + if (timeId) { + clearInterval(timeId) + } + timeId = setInterval(() => { + this.controllerShow.runJavaScript("scheduledSaveContent()") + }, 3000) + } catch (e) { + console.info('WebviewController', e); } - timeId = setInterval(() => { - this.controllerShow.runJavaScript("scheduledSaveContent()") - }, 3000) LogUtil.info(TAG, "setInterval timeId : " + timeId) // save continue data AppStorage.SetOrCreate('ContinueSection', this.sectionStatus) @@ -397,9 +425,13 @@ export struct NoteContentOverViewComp { RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null) if (this.sectionStatus != 1) { this.selectedNoteData = NoteUtil.getFirstNoteData(this.AllNoteArray, this.selectedFolderData.uuid) - this.controllerShow.runJavaScript( - "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')" - ) + try { + this.controllerShow.runJavaScript( + "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')" + ) + } catch (e) { + console.info('WebviewController', e); + } this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) } else { this.selectedFolderData = FolderUtil.getFolderData(AppStorage.Get('AllFolderArray'), item.uuid) @@ -519,7 +551,11 @@ export struct ToolBarComp { } this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) - this.controllerShow.runJavaScript("RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')") + try { + this.controllerShow.runJavaScript("RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')") + } catch (e) { + console.info('WebviewController', e); + } this.chooseNote = false // save continue data let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject()) @@ -536,7 +572,11 @@ export struct ToolBarComp { }) confirm(excuteJs: string) { - this.controllerShow.runJavaScript(excuteJs) + try { + this.controllerShow.runJavaScript(excuteJs) + } catch (e) { + console.info('WebviewController', e); + } } build() { @@ -546,31 +586,35 @@ export struct ToolBarComp { .height(24) .width(24) .onClick(() => { - if (this.sectionStatus != 1) { - this.lastSectionStatus = this.sectionStatus - this.sectionStatus = 1 - this.asideWidth = 0 - this.controllerShow.runJavaScript("RICH_EDITOR.setInputEnabled(true)") - } else { - if (this.lastSectionStatus != undefined) { - this.asideWidth = 200 - // 切换为小屏预览模式 - this.controllerShow.runJavaScript("RICH_EDITOR.setInputEnabled(false)") - this.sectionStatus = this.lastSectionStatus - // 退出全屏时存库 - LogUtil.info(TAG, "close note" + this.selectedNoteData.uuid) - this.controllerShow.runJavaScript("saveHtmlContent()") - //退出键盘 - // @ts-ignore - inputMethod.getController().stopInputSession(); - // 清除定时器 - if (timeId != undefined) { - LogUtil.info(TAG, "zoom, clearInterval timeId : " + timeId) - clearInterval(timeId) - } + try { + if (this.sectionStatus != 1) { + this.lastSectionStatus = this.sectionStatus + this.sectionStatus = 1 + this.asideWidth = 0 + this.controllerShow.runJavaScript("RICH_EDITOR.setInputEnabled(true)") } else { - this.sectionStatus = 3 + if (this.lastSectionStatus != undefined) { + this.asideWidth = 200 + // 切换为小屏预览模式 + this.controllerShow.runJavaScript("RICH_EDITOR.setInputEnabled(false)") + this.sectionStatus = this.lastSectionStatus + // 退出全屏时存库 + LogUtil.info(TAG, "close note" + this.selectedNoteData.uuid) + this.controllerShow.runJavaScript("saveHtmlContent()") + //退出键盘 + // @ts-ignore + inputMethod.getController().stopInputSession(); + // 清除定时器 + if (timeId != undefined) { + LogUtil.info(TAG, "zoom, clearInterval timeId : " + timeId) + clearInterval(timeId) + } + } else { + this.sectionStatus = 3 + } } + } catch (e) { + console.info('WebviewController', e); } this.editModel = !this.editModel // save continue data @@ -616,9 +660,13 @@ export struct ToolBarComp { RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null) this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) - this.controllerShow.runJavaScript( - "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')" - ) + try { + this.controllerShow.runJavaScript( + "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')" + ) + } catch (e) { + console.info('WebviewController', e); + } // save continue data let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject()) AppStorage.SetOrCreate('ContinueNote', continueNote) @@ -634,7 +682,11 @@ export struct ToolBarComp { .width(24) .onClick(() => { // 清单 - this.controllerShow.runJavaScript("javascript:RICH_EDITOR.setTodo()") + try { + this.controllerShow.runJavaScript("javascript:RICH_EDITOR.setTodo()") + } catch (e) { + console.info('WebviewController', e); + } // 退出键盘 // @ts-ignore inputMethod.getController().stopInputSession(); @@ -705,12 +757,16 @@ export struct ToolBarComp { OperationUtils.copy(imageUri).then((uriPath) => { var path = "file://" + uriPath LogUtil.info(TAG, 'image uri is:' + path) - this.controllerShow.runJavaScript( - "javascript:RICH_EDITOR.insertImage('" + path + "')" - ) - this.issave = 1 - // 保存笔记信息到数据库 - this.controllerShow.runJavaScript("getHtmlContent()") + try { + this.controllerShow.runJavaScript( + "javascript:RICH_EDITOR.insertImage('" + path + "')" + ) + this.issave = 1 + // 保存笔记信息到数据库 + this.controllerShow.runJavaScript("getHtmlContent()") + } catch (e) { + console.info('WebviewController', e); + } }) } } @@ -730,7 +786,11 @@ export struct ToolBarComp { // 退出键盘 // @ts-ignore inputMethod.getController().stopInputSession(); - this.controllerShow.runJavaScript("RICH_EDITOR.undo()") + try { + this.controllerShow.runJavaScript("RICH_EDITOR.undo()") + } catch (e) { + console.info('WebviewController', e); + } }) }.width(42) .height(42) @@ -745,7 +805,11 @@ export struct ToolBarComp { // 退出键盘 // @ts-ignore inputMethod.getController().stopInputSession(); - this.controllerShow.runJavaScript("RICH_EDITOR.redo()") + try { + this.controllerShow.runJavaScript("RICH_EDITOR.redo()") + } catch (e) { + console.info('WebviewController', e); + } }) }.width(42) .height(42) @@ -760,8 +824,12 @@ export struct ToolBarComp { .fillColor(this.issave == 0 ? Color.Black : Color.Grey) .onClick(() => { // 保存笔记信息到数据库 - this.controllerShow.runJavaScript("getHtmlContent()") - this.controllerShow.runJavaScript("javascript:RICH_EDITOR.getBlur()") + try { + this.controllerShow.runJavaScript("getHtmlContent()") + this.controllerShow.runJavaScript("javascript:RICH_EDITOR.getBlur()") + } catch (e) { + console.info('WebviewController', e); + } if (this.selectedNoteData.title == "标题" && this.selectedNoteData.content_text == "") { LogUtil.info(TAG, "note is empty,save note failed") } @@ -784,12 +852,16 @@ export struct ToolBarComp { // update note to db let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid) - RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null) + RdbStoreUtil.update(this.selectedNoteData?.toNoteObject(), predicates_note, null) if (this.selectedFolderData.uuid === SysDefFolderUuid.MyFavorites) { this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), SysDefFolderUuid.MyFavorites) - this.controllerShow.runJavaScript( - "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')" - ) + try { + this.controllerShow.runJavaScript( + "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')" + ) + } catch (e) { + console.info('WebviewController', e); + } // save continue data let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject()) AppStorage.SetOrCreate('ContinueNote', continueNote) diff --git a/features/src/main/ets/components/NoteListComp.ets b/features/src/main/ets/components/NoteListComp.ets index f56149e..cad4991 100644 --- a/features/src/main/ets/components/NoteListComp.ets +++ b/features/src/main/ets/components/NoteListComp.ets @@ -423,7 +423,7 @@ export struct NoteItemComp { .borderRadius(24) .linearGradient({ direction: GradientDirection.Right, - colors: this.selectedNoteData?.uuid == this.noteItem.uuid ? [[0xffcdae, 0.0], [0xFfece2, 1.0]] : [[0xffffff, 0.0], [0xffffff, 1.0]] + colors: this.selectedNoteData?.uuid == this.noteItem?.uuid ? [[0xffcdae, 0.0], [0xFfece2, 1.0]] : [[0xffffff, 0.0], [0xffffff, 1.0]] }) .onClick(() => { if (this.search) { -- Gitee From 05d85e2a3db6bf659ac7453a0d173be1670283e7 Mon Sep 17 00:00:00 2001 From: ye-qianqian1997 Date: Thu, 12 Sep 2024 11:26:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?note=204.1-Release=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=8B=B1=E6=96=87=E5=AD=97=E6=AE=B5=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ye-qianqian1997 --- AppScope/resources/en_US/element/string.json | 8 ++++++++ AppScope/resources/zh_CN/element/string.json | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 AppScope/resources/en_US/element/string.json create mode 100644 AppScope/resources/zh_CN/element/string.json diff --git a/AppScope/resources/en_US/element/string.json b/AppScope/resources/en_US/element/string.json new file mode 100644 index 0000000..98f69c1 --- /dev/null +++ b/AppScope/resources/en_US/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "Notepad" + } + ] +} \ No newline at end of file diff --git a/AppScope/resources/zh_CN/element/string.json b/AppScope/resources/zh_CN/element/string.json new file mode 100644 index 0000000..57a2e1f --- /dev/null +++ b/AppScope/resources/zh_CN/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "备忘录" + } + ] +} \ No newline at end of file -- Gitee