diff --git a/.gitignore b/.gitignore index 7c2b7c1..d2ff201 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,4 @@ /.clang-format /.clang-tidy **/.test -/.appanalyzer -auto_build.bat \ No newline at end of file +/.appanalyzer \ No newline at end of file diff --git a/auto_build.bat b/auto_build.bat new file mode 100644 index 0000000..295c979 --- /dev/null +++ b/auto_build.bat @@ -0,0 +1,11 @@ +"D:\Program Files\Huawei\DevEco Studio\tools\node\node.exe" "D:\Program Files\Huawei\DevEco Studio\tools\hvigor\bin\hvigorw.js" --sync -p product=ohos --analyze=normal --parallel --incremental --daemon +"D:\Program Files\Huawei\DevEco Studio\tools\node\node.exe" "D:\Program Files\Huawei\DevEco Studio\tools\hvigor\bin\hvigorw.js" --mode module -p product=ohos assembleHap --analyze=normal --parallel --incremental --daemon + +"D:\Program Files\Huawei\DevEco Studio\tools\node\node.exe" "D:\Program Files\Huawei\DevEco Studio\tools\hvigor\bin\hvigorw.js" --sync -p product=default --analyze=normal --parallel --incremental --daemon +"D:\Program Files\Huawei\DevEco Studio\tools\node\node.exe" "D:\Program Files\Huawei\DevEco Studio\tools\hvigor\bin\hvigorw.js" --mode module -p product=default assembleHap --analyze=normal --parallel --incremental --daemon + +set PROJECT_PATH="E:\linys\Harmony_Projects\Linys_Browser_NEXT\" + +echo F| xcopy %PROJECT_PATH%"home\build\default\outputs\default\home-default-unsigned.hap" %PROJECT_PATH%"build_auto\HMOS-home-default-unsigned.hap" /Y +echo F| xcopy %PROJECT_PATH%"home\build\ohos\outputs\default\home-default-unsigned.hap" %PROJECT_PATH%"build_auto\OHOS-home-default-unsigned.hap" /Y +echo F| xcopy %PROJECT_PATH%"home\build\ohos\outputs\default\home-default-signed.hap" %PROJECT_PATH%"build_auto\entry.hap" /Y diff --git a/build-profile.json5 b/build-profile.json5 index eae0d23..1fde6ac 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -43,7 +43,7 @@ { "name": "ohos", "signingConfig": "ohos", - "compileSdkVersion": 12, + "compileSdkVersion": 13, "compatibleSdkVersion": 12, "runtimeOS": "OpenHarmony", "buildOption": { diff --git a/build_auto/HMOS-home-default-unsigned.hap b/build_auto/HMOS-home-default-unsigned.hap index 6aaeb6c..437cd06 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 29481f4..f5c6179 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 d37f58b..7d11d43 100644 Binary files a/build_auto/entry.hap and b/build_auto/entry.hap differ diff --git a/home/src/main/ets/blocks/meowAppSettings.ets b/home/src/main/ets/blocks/meowAppSettings.ets index 6e5ddd9..ea08903 100644 --- a/home/src/main/ets/blocks/meowAppSettings.ets +++ b/home/src/main/ets/blocks/meowAppSettings.ets @@ -105,7 +105,7 @@ struct meowAppSettings { woofHistory_control: CustomDialogController = new CustomDialogController({ builder: woofHistory({ showing_settings: this.show }), alignment: DialogAlignment.Center, - cornerRadius: 16, + cornerRadius: 22, showInSubWindow: true, width: "90%", }); @@ -465,7 +465,7 @@ struct meowAppSettings { linysText({ text: $r('app.string.Settings_storage_clear_webview') }) linysText({ text: $r('app.string.Settings_storage_clear_webview_desc'), max_lines: 6 }) - Row({ space: 10 }) { + Row({ space: 12 }) { linysTitleText({ text: "󰂼 " + add_units_to_size(this.web_cache_size) }) .layoutWeight(1) diff --git a/home/src/main/ets/blocks/meowTabs.ets b/home/src/main/ets/blocks/meowTabs.ets index d86a631..fa488b8 100644 --- a/home/src/main/ets/blocks/meowTabs.ets +++ b/home/src/main/ets/blocks/meowTabs.ets @@ -1,12 +1,19 @@ import linysSymbol from '../components/linysSymbol'; import { bunch_of_tabs, tab_label } from '../hosts/bunch_of_tabs'; import { url_resource_to_meow } from '../utils/url_tools'; -import { animation_default, fontSize_Large, fontSize_Normal, url_default_blank } from '../hosts/bunch_of_defaults'; +import { + animation_default, + click_effect_default, + fontSize_Large, + fontSize_Normal, + url_default_blank +} from '../hosts/bunch_of_defaults'; import { kv_store_get, kv_store_put } from '../utils/kv_store_tools'; import { bunch_of_settings } from '../hosts/bunch_of_settings'; import linysShowButton from '../components/linysShowButton'; import linysText from '../components/linysText'; import { sandbox_open_array_sync } from '../utils/storage_tools'; +import { fileIo as fs } from '@kit.CoreFileKit'; @Component struct meowTabs { @@ -126,10 +133,15 @@ struct meowTabs { let web_state_arrays_to_restore: Uint8Array[] = []; for (let index = 0; index < continue_tabs_count; index++) { // Read continue tabs data - let key = "continue_tabs_web_state_array_" + index.toString(); + let key = "continue/continue_tabs_web_state_array_" + index.toString(); let array_buffer = sandbox_open_array_sync(key); if (array_buffer) { web_state_arrays_to_restore.push(new Uint8Array(array_buffer)); + } else { + // An unexpected error may occur. + web_state_arrays_to_restore.push(new Uint8Array()) + this.current_sub_tab_index = -1; + this.current_main_tab_index = 0; } } @@ -157,6 +169,17 @@ struct meowTabs { } } + // clear continue storage + for (let index = 0; index < continue_tabs_count; index++) { + let key = "continue/continue_tabs_web_state_array_" + index.toString(); + let filesDir = getContext().filesDir; + try { + fs.unlink(filesDir + '/' + key); + } catch (e) { + console.error(e); + } + } + this.recover_tabs_finished = true; } @@ -165,72 +188,11 @@ struct meowTabs { Scroll(this.scroll_controller) { Column({ space: 5 }) { ForEach(this.bunch_of_tabs.Labels, (Label: tab_label) => { - RelativeContainer() { - Row() { - Text("󰇀") - .padding({ right: 5 }) - .fontSize(fontSize_Large()) - .fontColor(this.color_current_font) - .fontWeight((this.current_main_tab_index == Label.index_key || - this.current_sub_tab_index == Label.index_key) - ? FontWeight.Medium : undefined) - .visibility(this.current_sub_tab_index == Label.index_key ? Visibility.Visible : Visibility.None) - .animation(animation_default()) - .offset({ y: -2 }) - - Text(this.tab_titles[Label.index_key] == "" ? "Meow" : this.tab_titles[Label.index_key]) - .padding({ left: 2 }) - .fontSize(fontSize_Normal()) - .fontColor(this.color_current_font) - .fontWeight((this.current_main_tab_index == Label.index_key || - this.current_sub_tab_index == Label.index_key) - ? FontWeight.Medium : undefined) - .maxLines(1) - .textOverflow({ overflow: TextOverflow.Ellipsis }) - .layoutWeight(1) - - SymbolGlyph($r('sys.symbol.xmark')) - .fontSize(fontSize_Normal()) - .fontColor([this.color_current_font]) - .fontWeight(FontWeight.Medium) - - } // Title and xmark - .border({ - radius: 10, - width: 2, - color: (this.current_main_tab_index == Label.index_key || - this.current_sub_tab_index == Label.index_key) - ? this.color_current_font : "transparent" - }) - .animation({ duration: 100 }) - .width("100%") - .height(this.tab_height_default) - .padding(10) - .backgroundColor(this.color_current_secondary) - .offset({ y: this.offset_area[Label.index_key] }) - .alignRules({ - middle: { anchor: "__container__", align: HorizontalAlign.Center }, - top: { anchor: "__container__", align: VerticalAlign.Top } - }) - .onClick(() => { - this.click_tab_button(Label.index_key); - }) - - Column() { - } // The True Tab Closer - .width(70) - .height("100%") - .alignRules({ - middle: { anchor: "__container__", align: HorizontalAlign.End }, - center: { anchor: "__container__", align: VerticalAlign.Center } - }) - .onClick(() => { - this.close_tab(Label.index_key) - }) - - } - .width("100%") - .height(this.tab_height_default + this.extension_area[Label.index_key]) + TabButton({ + Label: Label, + extension_area: this.extension_area, + offset_area: this.offset_area, + }) }, (Label: tab_label) => Label.timestamp.toString()) } @@ -432,6 +394,10 @@ struct meowTabs { this.current_sub_tab_index = -1; this.choosing_paralleow = false; } + if (target < this.current_sub_tab_index) { + this.current_sub_tab_index -= 1; + } + this.bunch_of_tabs.re_save_web_state(target); } choose_paralleow() { @@ -527,7 +493,7 @@ struct meowTabs { // if choosing and is not main web then set as sub view (Paralleow) this.choosing_paralleow = false; this.current_sub_tab_index = index; - this.showing_tabs = false; + // this.showing_tabs = false; } else { if (this.current_sub_tab_index >= 0) { // Paralleow enabled @@ -603,4 +569,104 @@ struct meowTabs { } } -export default meowTabs; \ No newline at end of file +export default meowTabs; + + +@Component +struct TabButton { + // Sync + @Link offset_area: number[]; + @Link extension_area: number[]; + @Prop Label: tab_label; + tab_height_default: number = 42; + // Public + @StorageLink('current_main_tab_index') current_main_tab_index: number = 0; + @StorageLink('current_sub_tab_index') current_sub_tab_index: number = -1; + @StorageLink('tab_titles') tab_titles: string[] = [] + // Gateways + @StorageLink('universal_tab_button_clicked_gateway') uni_tab_button_clicked: number = -1; + @StorageLink('universal_close_tab_gateway') close_tab_gateway: number = -1; + // Colors + @StorageProp('color_current_secondary') color_current_secondary: ResourceColor = $r('app.color.block_color'); + @StorageProp('color_current_font') color_current_font: ResourceColor = $r('app.color.font_color_title'); + // Animation + @State pressing: boolean = false; + + build() { + RelativeContainer() { + Row() { + Text("󰇀") + .padding({ right: 5 }) + .fontSize(fontSize_Large()) + .fontColor(this.color_current_font) + .fontWeight((this.current_main_tab_index == this.Label.index_key || + this.current_sub_tab_index == this.Label.index_key) + ? FontWeight.Medium : undefined) + .visibility(this.current_sub_tab_index == this.Label.index_key ? Visibility.Visible : Visibility.None) + .animation(animation_default()) + .offset({ y: -2 }) + + Text(this.tab_titles[this.Label.index_key] == "" ? "Meow" : this.tab_titles[this.Label.index_key]) + .padding({ left: 2 }) + .fontSize(fontSize_Normal()) + .fontColor(this.color_current_font) + .fontWeight((this.current_main_tab_index == this.Label.index_key || + this.current_sub_tab_index == this.Label.index_key) + ? FontWeight.Medium : undefined) + .maxLines(1) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .layoutWeight(1) + + SymbolGlyph($r('sys.symbol.xmark')) + .fontSize(fontSize_Normal()) + .fontColor([this.color_current_font]) + .fontWeight(FontWeight.Medium) + + } // Title and xmark + .border({ + radius: 10, + width: 2, + color: (this.current_main_tab_index == this.Label.index_key || + this.current_sub_tab_index == this.Label.index_key) + ? this.color_current_font : "transparent" + }) + .backgroundColor(this.color_current_secondary) + .animation(animation_default()) + .width("100%") + .height(this.tab_height_default) + .padding(10) + .offset({ y: this.offset_area[this.Label.index_key] }) + .alignRules({ + middle: { anchor: "__container__", align: HorizontalAlign.Center }, + top: { anchor: "__container__", align: VerticalAlign.Top } + }) + .onClick(() => { + this.uni_tab_button_clicked = this.Label.index_key; + }) + + Column() { + } // The True Tab Closer + .width(70) + .height("100%") + .alignRules({ + middle: { anchor: "__container__", align: HorizontalAlign.End }, + center: { anchor: "__container__", align: VerticalAlign.Center } + }) + .onClick(() => { + this.close_tab_gateway = this.Label.index_key; + }) + } + .onTouch((event) => { + if (event.type == TouchType.Up) { + this.pressing = false; + // If touch ends + } else { + this.pressing = true; + // If touching + } + }) + .width("100%") + .height(this.tab_height_default + this.extension_area[this.Label.index_key]) + .clickEffect(click_effect_default()) + } +} \ No newline at end of file diff --git a/home/src/main/ets/blocks/meowTabsHorizontal.ets b/home/src/main/ets/blocks/meowTabsHorizontal.ets index 135f972..adf3f4a 100644 --- a/home/src/main/ets/blocks/meowTabsHorizontal.ets +++ b/home/src/main/ets/blocks/meowTabsHorizontal.ets @@ -1,6 +1,6 @@ import linysShowButton from '../components/linysShowButton'; import linysSymbol from '../components/linysSymbol'; -import { animation_default, fontSize_Large, fontSize_Normal } from '../hosts/bunch_of_defaults'; +import { animation_default, click_effect_default, fontSize_Large, fontSize_Normal } from '../hosts/bunch_of_defaults'; import { bunch_of_tabs } from '../hosts/bunch_of_tabs'; import { LengthMetrics } from '@kit.ArkUI'; @@ -53,7 +53,7 @@ struct meowTabsHorizontal { .animation(animation_default()) } // Scroll of tab buttons .scrollBarWidth(5) - .scrollBar(this.tab_width() == 60 ? BarState.On : BarState.Off) + .scrollBar(this.tab_width() == 80 ? BarState.On : BarState.Off) .scrollable(ScrollDirection.Horizontal) .edgeEffect(EdgeEffect.Spring) .align(Alignment.Start) @@ -112,8 +112,8 @@ struct meowTabsHorizontal { if (result > 200) { return 200; } - if (result < 60) { - return 60; + if (result < 80) { + return 80; } return result; } @@ -127,7 +127,6 @@ struct HorizontalTabButton { @Link current_sub_tab_index: number; @Prop index: number; @Prop title: string; - @Link full_area_width: number; @Link tab_titles: string[]; // Gateways @@ -164,11 +163,10 @@ struct HorizontalTabButton { .fontColor([this.color_current_font]) .fontWeight(FontWeight.Medium) .onClick(() => { - this.close_tab_gateway = this.index; // Close tab }) - .visibility(this.tab_width() < 80 ? this.visibility_visible_on_chosen(this.index) : Visibility.Visible) + .visibility(this.tab_width() <= 80 ? this.visibility_visible_on_chosen(this.index) : Visibility.Visible) .animation(animation_default()) } .offset({ y: this.offset_y }) @@ -191,6 +189,7 @@ struct HorizontalTabButton { this.offset_y = 0; }, 50) }) + .clickEffect(click_effect_default()) } tab_width() { diff --git a/home/src/main/ets/blocks/meowWebView.ets b/home/src/main/ets/blocks/meowWebView.ets index df3722c..4997a60 100644 --- a/home/src/main/ets/blocks/meowWebView.ets +++ b/home/src/main/ets/blocks/meowWebView.ets @@ -5,6 +5,7 @@ import { sandbox_save } from '../utils/storage_tools'; import { url_meow_to_resource, url_resource_to_meow } from '../utils/url_tools'; import { webview } from '@kit.ArkWeb'; import { bunch_of_settings } from '../hosts/bunch_of_settings'; +import { fileIo as fs } from '@kit.CoreFileKit'; @Component struct meowWebView { @@ -185,12 +186,12 @@ struct meowWebView { } // Get web_state - const web_state = this.bunch_of_tabs.Tabs[Label.index_key].controller.serializeWebState(); + let web_state = this.bunch_of_tabs.Tabs[Label.index_key].controller.serializeWebState(); // Sync to bunch_of_tabs this.bunch_of_tabs.Tabs[Label.index_key].web_state_array = web_state; // save web state to sandbox storage if (web_state) { - let identifier = "continue_tabs_web_state_array_" + Label.index_key.toString(); + let identifier = "continue/continue_tabs_web_state_array_" + Label.index_key.toString(); sandbox_save(identifier, web_state.buffer); } }) diff --git a/home/src/main/ets/dialogs/woofHistory.ets b/home/src/main/ets/dialogs/woofHistory.ets index dda6e98..d8972cd 100644 --- a/home/src/main/ets/dialogs/woofHistory.ets +++ b/home/src/main/ets/dialogs/woofHistory.ets @@ -92,9 +92,11 @@ struct woofHistory { .animation(animation_default()) .id("title_history") - Column({ space: 5 }) { + Column({ space: 10 }) { Row() { + linysText({ text: $r('app.string.Settings_experience_history_date_format') }) + .opacity(0.7) linysText({ text: " (" + this.history_list.length.toString() + ")" }) .opacity(0.7) } // Time elapse description @@ -132,14 +134,13 @@ struct woofHistory { }) .align(Alignment.Top) .layoutWeight(1) - .margin({ top: 3, bottom: 3 }) .width("100%") .borderRadius(13.5) .backgroundColor(this.color_current_secondary) Scroll() { Row({ space: 5 }) { - ForEach(this.available_months.reverse(), (item: number[], key: number) => { + ForEach(this.available_months.reverse(), (item: number[], _key: number) => { month_button({ year: item[0], month: item[1], @@ -148,7 +149,7 @@ struct woofHistory { }) .onClick(() => { // MEOW - this.bunch_of_history.open_month_from_disk(item[0], item[1]); + this.bunch_of_history.open_month_from_disk(item[0], item[1], false); this.refresh_current_history_list(); this.viewing_year = item[0]; this.viewing_month = item[1]; @@ -163,7 +164,6 @@ struct woofHistory { }) .padding(5) .align(Alignment.Start) - .margin({ top: 3, bottom: 3 }) .width("100%") .borderRadius(13.5) .backgroundColor(this.color_current_secondary) @@ -418,36 +418,23 @@ struct month_button { @Link viewing_month: number; @StorageProp('color_current_primary') color_current_primary: ResourceColor = $r('app.color.start_window_background'); @StorageProp('color_current_font') color_current_font: ResourceColor = $r('app.color.font_color_title'); - // Animation - @State pressing: boolean = false; build() { Column({ space: 0 }) { linysText({ text: this.year.toString(), font_weight: this.selected() ? FontWeight.Medium : FontWeight.Normal, - color: this.pressing ? this.color_current_primary : this.color_current_font, }) linysText({ text: this.month.toString(), font_weight: this.selected() ? FontWeight.Medium : FontWeight.Normal, - color: this.pressing ? this.color_current_primary : this.color_current_font, }) } - .onTouch((event) => { - if (event.type == TouchType.Up) { - this.pressing = false; - // If touch ends - } else { - this.pressing = true; - // If touching - } - }) .border({ color: this.selected() ? this.color_current_font : 'transparent', width: 2, radius: 10 }) .alignItems(HorizontalAlign.Start) .clickEffect(click_effect_default()) .padding(8) - .backgroundColor(this.pressing ? this.color_current_font : this.color_current_primary) + .backgroundColor(this.color_current_primary) .animation(animation_default()) } diff --git a/home/src/main/ets/dialogs/woofUpdateHistory.ets b/home/src/main/ets/dialogs/woofUpdateHistory.ets index 6fb3443..62351c0 100644 --- a/home/src/main/ets/dialogs/woofUpdateHistory.ets +++ b/home/src/main/ets/dialogs/woofUpdateHistory.ets @@ -1,6 +1,6 @@ import linysText from '../components/linysText'; import linysTitleText from '../components/linysTitleText'; -import { animation_default } from '../hosts/bunch_of_defaults'; +import { animation_default, click_effect_default } from '../hosts/bunch_of_defaults'; @CustomDialog struct woofUpdateHistory { @@ -10,6 +10,12 @@ struct woofUpdateHistory { @StorageProp('color_current_secondary') color_current_secondary: ResourceColor = $r('app.color.block_color'); @StorageProp('color_current_font') color_current_font: ResourceColor = $r('app.color.font_color_title'); @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...', + '一个关键的发行版更新,将网页深色模式、更新记录、致谢和一些体验优化带入冲浪喵~\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!', '一个体面的发行版更新,将网页深色模式、更新记录、致谢和一些体验优化带入冲浪喵~', @@ -100,6 +106,7 @@ struct release_card { .width("100%") .opacity(0.7) } + .clickEffect(click_effect_default()) .alignItems(HorizontalAlign.Start) .padding(10) .borderRadius(10) diff --git a/home/src/main/ets/hosts/bunch_of_downloads.ets b/home/src/main/ets/hosts/bunch_of_downloads.ets index f7cc81b..4b38436 100644 --- a/home/src/main/ets/hosts/bunch_of_downloads.ets +++ b/home/src/main/ets/hosts/bunch_of_downloads.ets @@ -1,4 +1,3 @@ -import { common } from '@kit.AbilityKit'; import { BusinessError, request } from '@kit.BasicServicesKit'; import { fileUri, fileIo as fs, picker } from '@kit.CoreFileKit'; @@ -10,12 +9,19 @@ export class bunch_of_downloads { list_of_paused: boolean[] = []; list_of_urls: string[] = []; last_action: number = 0; - context = AppStorage.get('context') as common.UIAbilityContext; + context = getContext(); /** * A class to handle download tasks. + * Will ENSURE there is a downloads directory in the sandbox directory on creation. */ constructor() { + let filesDir = this.context.filesDir; + try { + fs.mkdirSync(filesDir + '/downloads'); + } catch (e) { + console.log('[Meow][bunch_of_downloads] E: /downloads already exists.') + } } /** @@ -23,17 +29,10 @@ export class bunch_of_downloads { * @param url The https:// proxy url of the download target * */ start_download_task(url: string) { - let filesDir = getContext().filesDir; - try { - fs.mkdirSync(filesDir + '/downloads'); - } catch (e) { - console.log('[Meow][bunch_of_downloads] E: /downloads already exists.') - } - let file_url_split = url.split("/"); let file_name_question_mark_split = file_url_split[file_url_split.length-1].split("?"); let file_name = file_name_question_mark_split[0]; - let download_target_path = filesDir + '/downloads/' + file_name; + let download_target_path = this.context.filesDir + '/downloads/' + file_name; let config: request.DownloadConfig = { url: url, diff --git a/home/src/main/ets/hosts/bunch_of_history.ets b/home/src/main/ets/hosts/bunch_of_history.ets index 31961fe..f2bbea1 100644 --- a/home/src/main/ets/hosts/bunch_of_history.ets +++ b/home/src/main/ets/hosts/bunch_of_history.ets @@ -37,7 +37,7 @@ export class bunch_of_history { if (plain_history_max_length) { this.plain_history_default_max_length = plain_history_max_length; } - this.open_month_from_disk(this.current_year, this.current_month); + this.open_month_from_disk(this.current_year, this.current_month, true); } // Settings @@ -63,7 +63,7 @@ export class bunch_of_history { let month = history_date.getMonth() + 1; // Opens the month required - this.open_month_from_disk(year, month); + this.open_month_from_disk(year, month, false); let insert_position = this.index_of_record_after_time(history.accessed_time); if (insert_position < 0) { @@ -86,7 +86,7 @@ export class bunch_of_history { * */ remove_history(year: number, month: number, index: number, instantly_save_to_disk: boolean) { // Opens the month required - this.open_month_from_disk(year, month); + this.open_month_from_disk(year, month, false); // Delete this.history_this_month.splice(index, 1); // Save @@ -105,7 +105,7 @@ export class bunch_of_history { remove_selected_history(year: number, month: number, selections: number[], instantly_save_to_disk: boolean) { // Opens the month required - this.open_month_from_disk(year, month); + this.open_month_from_disk(year, month, false); selections.sort((a, b) => { return a - b; @@ -209,7 +209,7 @@ export class bunch_of_history { * @returns "\n" connected string of history records in the format of: * @example 'bing\nbing.com\n127771721' * */ - export_string() { + 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]; @@ -227,7 +227,7 @@ export class bunch_of_history { * @param imp The string in the correct format: * @example 'bing\nbing.com\n127771721' * */ - import_string(imp: string) { + private import_string(imp: string) { this.history_this_month = []; if (imp.split("\n").length % 3 > 0) { @@ -253,15 +253,15 @@ export class bunch_of_history { /** * Check the history file structure on disk. - * After executing this, there will be ENSURED a History/History_year_month.txt existing for use. + * After executing this, there will be ENSURED a history/history_year_month.txt existing for use. * */ check_disk_month(year: number, month: number) { let filesDir = getContext().filesDir; let new_history = true; try { - fs.mkdirSync(filesDir + '/History'); + fs.mkdirSync(filesDir + '/history'); } catch (e) { - console.log('[Meow][bunch_of_downloads] E: History folder already exists.') + console.log('[Meow][bunch_of_downloads] E: history folder already exists.') new_history = false; } @@ -272,7 +272,7 @@ export class bunch_of_history { console.log("[Meow][meowAppSettings] NO HISTORY BEFORE!"); sandbox_save(history_year_month_path, ''); } else { - // check if this month have a History + // check if this month have a history let this_month_history = sandbox_open_sync(history_year_month_path); if (this_month_history as string == "undefined") { // This month doesn't have a history file @@ -289,10 +289,10 @@ export class bunch_of_history { * Opens a month of history. * @param path A string, the path of the file. * */ - open_month_from_disk(year: number, month: number) { + open_month_from_disk(year: number, month: number, construct_monthly_plain_history: boolean) { if (this.history_path_of_month(year, month) == this.current_opened_file_path) { // Already opened - console.log('already opened') + // console.log('already opened') return; } this.check_disk_month(year, month); @@ -302,7 +302,9 @@ export class bunch_of_history { this.current_year = year; this.current_month = month; this.import_string(the_file); - this.construct_this_month_plain_history(); + if (construct_monthly_plain_history) { + this.construct_this_month_plain_history(); + } } /** @@ -316,14 +318,14 @@ export class bunch_of_history { * Constructs the file name of history records in which history in [year, month] should be. * @param year A number, the year, like 2024. * @param month A number, the month, like 12. - * @returns A string, 'History/History_year_month.txt' + * @returns A string, 'history/history_year_month.txt' * */ history_path_of_month(year: number, month: number) { let month_unified = month.toString(); if (month_unified.length == 1) { month_unified = '0' + month_unified; } - return 'History/History_' + year.toString() + "_" + month_unified + '.txt'; + return 'history/history_' + year.toString() + "_" + month_unified + '.txt'; } /** @@ -334,10 +336,10 @@ export class bunch_of_history { this.check_disk_month(new Date().getFullYear(), new Date().getMonth() + 1); let result: number[][] = []; let filesDir = getContext().filesDir; - let history_files = fs.listFileSync(filesDir + '/History', { recursion: false }); + let history_files = fs.listFileSync(filesDir + '/history', { recursion: false }); for (let index = 0; index < history_files.length; index++) { let f_name = history_files[index].split('.')[0]; - // 'History_2024_2.txt' + // 'history_2024_2.txt' let f_split = f_name.split('_'); let year = parseInt(f_split[1]); let month = parseInt(f_split[2]); diff --git a/home/src/main/ets/hosts/bunch_of_tabs.ets b/home/src/main/ets/hosts/bunch_of_tabs.ets index 3d46741..60f6ce6 100644 --- a/home/src/main/ets/hosts/bunch_of_tabs.ets +++ b/home/src/main/ets/hosts/bunch_of_tabs.ets @@ -1,6 +1,8 @@ import { webview } from '@kit.ArkWeb'; import { url_meow_to_resource } from '../utils/url_tools'; import { url_default_blank } from './bunch_of_defaults'; +import { fileIo as fs } from '@kit.CoreFileKit'; +import { sandbox_save } from '../utils/storage_tools'; @Observed export class tab_label { @@ -90,6 +92,12 @@ export class bunch_of_tabs { * Provides methods to operate tabs. */ constructor() { + let filesDir = getContext().filesDir; + try { + fs.mkdirSync(filesDir + '/continue'); + } catch (e) { + // console.log('[Meow][meowWebViews] E: continue folder already exists.') + } } // Operations and Actions @@ -390,4 +398,16 @@ export class bunch_of_tabs { console.error("[ERROR][Meow][meowWebView] Restore web state failed for an undefined web_state!") } } + + /** + * Re-save all web states, usually used to ensure the correct order of tab indices. + * @param start A number, all tabs with index greater or equal to start would re-save their web states to disk. + * */ + re_save_web_state(start: number) { + for (let index = start; index < this.Tabs.length; index++) { + let web_state = this.Tabs[index].web_state_array; + let identifier = "continue/continue_tabs_web_state_array_" + index.toString(); + sandbox_save(identifier, web_state.buffer); + } + } } diff --git a/home/src/main/ets/utils/storage_tools.ets b/home/src/main/ets/utils/storage_tools.ets index d1c329c..76d776d 100644 --- a/home/src/main/ets/utils/storage_tools.ets +++ b/home/src/main/ets/utils/storage_tools.ets @@ -171,5 +171,5 @@ export function add_units_to_size(size_in_bytes: number) { result /= 1024; unit += 1; } - return result.toFixed(3) + " " + units[unit]; + return result.toFixed(2) + " " + units[unit]; } diff --git a/home/src/main/resources/base/element/string.json b/home/src/main/resources/base/element/string.json index 7df2c12..b2059f8 100644 --- a/home/src/main/resources/base/element/string.json +++ b/home/src/main/resources/base/element/string.json @@ -176,6 +176,10 @@ "name": "Settings_experience_history_to", "value": "Before" }, + { + "name": "Settings_experience_history_date_format", + "value": "Month/Date/Year, Hour:Minute:Second" + }, { "name": "Settings_experience_history_selecting", "value": "Selecting" @@ -386,7 +390,7 @@ }, { "name": "Whats_new_content", - "value": "1. Dark mode for webs;\n2. Now blank pages are in the set theme color;\n3. Copying text from the Scratching Board;\n4. Credits~" + "value": "1. Better History management~" }, { "name": "Whats_new_content_extra", diff --git a/home/src/main/resources/zh_CN/element/string.json b/home/src/main/resources/zh_CN/element/string.json index 139cd31..7ad913b 100644 --- a/home/src/main/resources/zh_CN/element/string.json +++ b/home/src/main/resources/zh_CN/element/string.json @@ -176,6 +176,10 @@ "name": "Settings_experience_history_to", "value": "至" }, + { + "name": "Settings_experience_history_date_format", + "value": "月/日/年, 时:分:秒" + }, { "name": "Settings_experience_history_selecting", "value": "选中" @@ -386,7 +390,7 @@ }, { "name": "Whats_new_content", - "value": "1. 网页的深色模式;\n2. 现在空白页会以设置的主题色为背景;\n3. 可以从猫抓板点击复制文字了!\n4. 致谢~" + "value": "1. 更好的历史管理系统~" }, { "name": "Whats_new_content_extra",