diff --git a/AppScope/app.json5 b/AppScope/app.json5 index 5c1330a..efb1d5b 100644 --- a/AppScope/app.json5 +++ b/AppScope/app.json5 @@ -2,8 +2,8 @@ "app": { "bundleName": "com.next.liny.linysbrowserNEXT", "vendor": "example", - "versionCode": 1000015, - "versionName": "1.7.0", + "versionCode": 1000016, + "versionName": "1.7.1", "icon": "$media:app_icon", "label": "$string:app_name" } diff --git a/build_auto/HMOS-home-default-unsigned.hap b/build_auto/HMOS-home-default-unsigned.hap index 437cd06..5d83c4a 100644 Binary files a/build_auto/HMOS-home-default-unsigned.hap and b/build_auto/HMOS-home-default-unsigned.hap differ diff --git a/build_auto/OHOS-home-default-unsigned.hap b/build_auto/OHOS-home-default-unsigned.hap index f5c6179..4505d30 100644 Binary files a/build_auto/OHOS-home-default-unsigned.hap and b/build_auto/OHOS-home-default-unsigned.hap differ diff --git a/build_auto/entry.hap b/build_auto/entry.hap index 7d11d43..6884707 100644 Binary files a/build_auto/entry.hap and b/build_auto/entry.hap differ diff --git a/home/src/main/ets/dialogs/woofHistory.ets b/home/src/main/ets/dialogs/woofHistory.ets index d8972cd..9d6f182 100644 --- a/home/src/main/ets/dialogs/woofHistory.ets +++ b/home/src/main/ets/dialogs/woofHistory.ets @@ -125,6 +125,7 @@ struct woofHistory { .animation(animation_default()) } } + .reverse(true) .width("100%") } // Main history list .scrollable(ScrollDirection.Vertical) diff --git a/home/src/main/ets/dialogs/woofUpdateHistory.ets b/home/src/main/ets/dialogs/woofUpdateHistory.ets index 62351c0..f968374 100644 --- a/home/src/main/ets/dialogs/woofUpdateHistory.ets +++ b/home/src/main/ets/dialogs/woofUpdateHistory.ets @@ -12,9 +12,11 @@ struct woofUpdateHistory { @State texts: string[] = [ 'v1.7.0-beta', 'A KEY release of a KEY update, bringing better History system and a few experience optimizations into Browser Cat!\n' + - 'However, the previous History records and last status of opened tabs are not inherited. So sorry for that...', + 'This version is trying to solve some performance issue of parts of this project, but this requires some deep level modification.\n' + + 'Therefore, the previous History records and last status of opened tabs are not inherited. So sorry for that...', '一个关键的发行版更新,将网页深色模式、更新记录、致谢和一些体验优化带入冲浪喵~\n' + - '不过,以前的历史浏览记录和上一次打开的标签页并没有得到继承……对不起!!!\n>︿<', + '这个版本正在尝试优化一些组件的性能问题,但是这需要一些深层的修改。\n' + + '所以,以前的历史浏览记录和上一次打开的标签页并没有得到继承……对不起!!!\n>︿<', 'v1.6.4-beta', 'A decent release of update, bringing Web Dark Mode, Update History, Credits and a few experience optimizations into Browser Cat!', diff --git a/home/src/main/ets/hosts/bunch_of_history.ets b/home/src/main/ets/hosts/bunch_of_history.ets index f2bbea1..23b2609 100644 --- a/home/src/main/ets/hosts/bunch_of_history.ets +++ b/home/src/main/ets/hosts/bunch_of_history.ets @@ -1,4 +1,4 @@ -import { sandbox_open_sync, sandbox_save } from '../utils/storage_tools'; +import { sandbox_open_sync, sandbox_save, sandbox_unlink } from '../utils/storage_tools'; import { fileIo as fs } from '@kit.CoreFileKit'; export class history_record { @@ -37,7 +37,26 @@ export class bunch_of_history { if (plain_history_max_length) { this.plain_history_default_max_length = plain_history_max_length; } + // Load today this.open_month_from_disk(this.current_year, this.current_month, true); + + // Compatibility path for older BrowserCats + this.patch_old_history_files(); + } + + // PATCHES + + /** + * Executed when an old format history.txt is found. + * This migrates old histories to new format and deletes the old file. + * */ + patch_old_history_files() { + let old_history = sandbox_open_sync('history.txt'); + if (old_history != 'undefined') { + console.log('found old history' + old_history.toString()) + this.import_string(old_history); + sandbox_unlink('history.txt'); + } } // Settings @@ -204,53 +223,6 @@ export class bunch_of_history { // External interaction - /** - * Export history records in a specific plain text format. - * @returns "\n" connected string of history records in the format of: - * @example 'bing\nbing.com\n127771721' - * */ - private export_string() { - let export_list: string[] = [] - for (let index = 0; index < this.history_this_month.length; index++) { - let history_item: history_record = this.history_this_month[index]; - export_list.push(history_item.label); - export_list.push(history_item.link); - export_list.push(history_item.accessed_time.toString()); - } - return export_list.join("\n"); - } - - /** - * Import history records in a specific plain text format. - * - * In default overwrites whatever was in this history_list. - * @param imp The string in the correct format: - * @example 'bing\nbing.com\n127771721' - * */ - private import_string(imp: string) { - this.history_this_month = []; - - if (imp.split("\n").length % 3 > 0) { - // Incorrect format, log an error. - // Though this is not very likely to happen so often - // since all the txt files are generated by a fixed algorithm. - console.error("[ERROR][Meow][bunch_of_history] Import Error: not 3*n length: " + imp) - return; - } - - this.history_this_month = []; - // Clear - let import_list: string[] = imp.split("\n"); - for (let index = 0; index < import_list.length; index += 3) { - if (import_list[index] != "") { - let new_history_record = - new history_record(import_list[index], import_list[index+1], Number.parseInt(import_list[index+2])); - this.add_history(new_history_record, false); - } - } - console.log("[Meow][bunch_of_history] Import history success, length: " + this.history_this_month.length.toString()) - } - /** * Check the history file structure on disk. * After executing this, there will be ENSURED a history/history_year_month.txt existing for use. @@ -349,4 +321,66 @@ export class bunch_of_history { // console.log(result.toString()) return result; } + + /** + * Export history records in a specific plain text format. + * @returns "\n" connected string of history records in the format of: + * @example 'bing\nbing.com\n127771721' + * */ + private export_string() { + let export_list: string[] = [] + for (let index = 0; index < this.history_this_month.length; index++) { + let history_item: history_record = this.history_this_month[index]; + export_list.push(history_item.label); + export_list.push(history_item.link); + export_list.push(history_item.accessed_time.toString()); + } + return export_list.join("\n"); + } + + /** + * Import history records in a specific plain text format. + * + * In default overwrites whatever was in this history_list. + * @param imp The string in the correct format: + * @example 'bing\nbing.com\n127771721' + * */ + private import_string(imp: string) { + this.history_this_month = []; + + if (imp.split("\n").length % 3 > 0) { + // Incorrect format, log an error. + // Though this is not very likely to happen so often + // since all the txt files are generated by a fixed algorithm. + console.error("[ERROR][Meow][bunch_of_history] Import Error: not 3*n length: " + imp) + return; + } + + this.history_this_month = []; + // Clear + let import_list: string[] = imp.split("\n"); + let last_month = [0, 0]; + for (let index = 0; index < import_list.length; index += 3) { + if (import_list[index] != "") { + let access_time = Number.parseInt(import_list[index+2]); + let access_Date = new Date(access_time); + let new_month = [new Date(access_time).getFullYear(), new Date(access_time).getMonth() + 1]; + + if ((last_month[0] != new_month[0]) || (last_month[1] != new_month[1])) { + // if changed month, then save this file + if ((last_month[0] != 0) && (last_month[1] != 0)) { + console.log('[Meow][bunch_of_history] Import history save month to disk: ' + last_month.toString()); + this.save_month_to_disk(); + } + } + + let new_history_record = + new history_record(import_list[index], import_list[index+1], access_time); + this.add_history(new_history_record, false); + + last_month = [access_Date.getFullYear(), access_Date.getMonth() + 1]; + } + } + console.log("[Meow][bunch_of_history] Import history success, length: " + this.history_this_month.length.toString()) + } } diff --git a/home/src/main/ets/utils/storage_tools.ets b/home/src/main/ets/utils/storage_tools.ets index 76d776d..c55c644 100644 --- a/home/src/main/ets/utils/storage_tools.ets +++ b/home/src/main/ets/utils/storage_tools.ets @@ -93,6 +93,26 @@ export function sandbox_save(file_name: string, content: string | ArrayBuffer) { fs.closeSync(file); } +/** + * Unlink (delete) a file. + * @param file_name A string, the path of the file. + * */ +export function sandbox_unlink(file_name: string) { + let filesDir = getContext().filesDir; + let full_file_directory = filesDir + '/' + file_name; + fs.unlink(full_file_directory); +} + +/** + * Unlink (delete) a file in a sync way. + * @param file_name A string, the path of the file. + * */ +export function sandbox_unlink_sync(file_name: string) { + let filesDir = getContext().filesDir; + let full_file_directory = filesDir + '/' + file_name; + fs.unlinkSync(full_file_directory); +} + /** * Read a text file from sandbox storage. * @returns A string, of the requested file's content.