Index.ets 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. import linysProgress from '../components/linysProgress';
  2. import meowTabs from '../blocks/modules/meowTabsVertical';
  3. import meowWebView from '../blocks/modules/meowWebView';
  4. import meowBookmarks from '../blocks/modules/meowBookmarks';
  5. import { animation_default } from '../hosts/bunch_of_defaults';
  6. import meowTitleBar from '../blocks/modules/meowTitleBar';
  7. import { bunch_of_settings } from '../hosts/bunch_of_settings';
  8. import { bunch_of_tabs } from '../hosts/bunch_of_tabs';
  9. import woofPromptFail from '../dialogs/prompts/woofPromptFail';
  10. import { AbilityConstant, bundleManager, ConfigurationConstant } from '@kit.AbilityKit';
  11. import { bunch_of_user_agents } from '../hosts/bunch_of_user_agents';
  12. import { bunch_of_history } from '../hosts/bunch_of_history';
  13. import { bunch_of_bookmarks } from '../hosts/bunch_of_bookmarks';
  14. import { bunch_of_downloads } from '../hosts/bunch_of_downloads';
  15. import { bunch_of_search_engines, search_engine } from '../hosts/bunch_of_search_engines';
  16. import { window } from '@kit.ArkUI';
  17. import { bunch_of_key_shortcuts } from '../hosts/bunch_of_key_shortcuts';
  18. import { sandbox_save, sandbox_unlink, uri_read_text_sync } from '../utils/storage_tools';
  19. import { deviceInfo } from '@kit.BasicServicesKit';
  20. import { fileIo } from '@kit.CoreFileKit';
  21. import woofHistory from '../dialogs/managers/woofHistory';
  22. import { meowContext } from '../utils/environment_tools';
  23. import { print_web } from '../utils/print_tools';
  24. import woofQuickSE from '../dialogs/quicks/woofQuickSE';
  25. import woofAdsBlocker from '../dialogs/managers/woofAdsBlocker';
  26. import { match_domain } from '../utils/url_tools';
  27. import woofCookies from '../dialogs/managers/woofCookies';
  28. import woofUpdateHistory from '../dialogs/contents/woofUpdateHistory';
  29. import woofPromptOK from '../dialogs/prompts/woofPromptOK';
  30. @Entry
  31. @Component
  32. struct Index {
  33. // Want
  34. @StorageLink('want_uri') @Watch('check_want') want_uri: string = 'want';
  35. @StorageLink('want_action') want_action: string = '';
  36. @StorageLink('want_type') want_type: string = '';
  37. // Init Hosts
  38. @StorageLink('bunch_of_settings') bunch_of_settings: bunch_of_settings = new bunch_of_settings();
  39. @StorageLink('bunch_of_tabs') bunch_of_tabs: bunch_of_tabs = new bunch_of_tabs();
  40. @StorageLink('bunch_of_user_agents') bunch_of_user_agents: bunch_of_user_agents = new bunch_of_user_agents();
  41. @StorageLink('bunch_of_history') bunch_of_history: bunch_of_history = new bunch_of_history();
  42. @StorageLink('bunch_of_bookmarks') bunch_of_bookmarks: bunch_of_bookmarks = new bunch_of_bookmarks("Bookmarks~Meow");
  43. @StorageLink('bunch_of_downloads') bunch_of_downloads: bunch_of_downloads = new bunch_of_downloads();
  44. @StorageLink('bunch_of_search_engines') bunch_of_search_engines: bunch_of_search_engines = new bunch_of_search_engines();
  45. @StorageLink('bunch_of_key_shortcuts') @Watch('on_bunch_of_key_shortcuts_change') bunch_of_key_shortcuts: bunch_of_key_shortcuts = new bunch_of_key_shortcuts();
  46. // UI Environment
  47. @StorageLink('bottomAvoidHeight') bottomAvoidHeight: number = 1;
  48. @StorageLink('topAvoidHeight') topAvoidHeight: number = 1;
  49. @StorageLink('leftAvoidWidth') leftAvoidWidth: number = 1;
  50. @StorageLink('rightAvoidWidth') rightAvoidWidth: number = 1;
  51. @StorageLink('tablet_mode') tablet_mode: boolean = false;
  52. @StorageLink('screen_width') screen_width: number = 0;
  53. @StorageLink('screen_height') screen_height: number = 0;
  54. @StorageLink('full_screen_height') full_screen_height: number = 0;
  55. @StorageLink('fullscreen_mode') @Watch('on_fullscreen_switch') fullscreen_mode: boolean = false;
  56. @StorageLink('animation_response') animation_response: number = 0.36;
  57. @StorageLink('animation_damping_coefficient') animation_damping: number = 0.8;
  58. @StorageProp('currentColorMode') @Watch('on_color_mode_change') current_color_mode: number = 0;
  59. // History Indexing
  60. @StorageProp('reindexing_history') reindexing_history: boolean | undefined = undefined;
  61. @StorageProp('reindexing_history_progress') reindexing_history_progress: string = "";
  62. @StorageProp('history_index_loading') history_index_loading: boolean | undefined = undefined;
  63. @StorageProp('history_index_loading_progress') history_index_loading_progress: string = "";
  64. @StorageProp('history_index_saving') history_index_saving: boolean | undefined = undefined;
  65. @StorageProp('history_index_saving_progress') history_index_saving_progress: string = "";
  66. // UI Statuses
  67. @StorageLink('fullscreen_handler') handler: FullScreenExitHandler | null = null;
  68. @StorageLink('showing_downloads') showing_downloads: boolean = false;
  69. @StorageLink('showing_more_options') showing_more_options: boolean = false;
  70. @StorageLink('showing_app_settings') showing_app_settings: boolean = false;
  71. @StorageLink('showing_tabs') @Watch('on_showing_tabs_change') showing_tabs: boolean = false;
  72. @StorageLink('showing_bookmarks') showing_bookmarks: boolean = false;
  73. @StorageLink('showing_scratching_board') showing_scratching_board: boolean = false;
  74. // UI params
  75. @State title_bar_height: number = 0;
  76. @State title_bar_alignRules: AlignRuleOption = {
  77. middle: { anchor: "__container__", align: HorizontalAlign.Center },
  78. bottom: { anchor: "__container__", align: VerticalAlign.Bottom }
  79. };
  80. // Interactions
  81. @StorageLink('is_search_input_typing') is_search_input_typing: boolean = false;
  82. @StorageLink('search_input') search_input: string = "加载中,请稍后";
  83. // Web Statuses
  84. @StorageLink('tab_titles') tab_titles: string[] = [];
  85. @StorageLink('current_title') current_title: string = "= ̄ω ̄=";
  86. @StorageLink('tab_urls') tab_urls: string[] = [];
  87. @StorageLink('current_url') current_url: string = "= ̄ω ̄=";
  88. @StorageLink('tab_loading_progresses') tab_loading_progresses: number[] = [0];
  89. @StorageLink('current_loading_progress') current_loading_progress: number = 0;
  90. @StorageLink('tab_is_loading') tab_is_loading: boolean[] = [true];
  91. @StorageLink('current_is_loading') current_is_loading: boolean = true;
  92. // Web control
  93. @StorageLink('current_main_tab_index') current_main_tab_index: number = 0;
  94. @StorageLink('current_sub_tab_index') current_sub_tab_index: number = -1;
  95. @StorageLink('current_accessForward') current_accessForward: boolean = false;
  96. @StorageLink('current_accessBackward') current_accessBackward: boolean = false;
  97. // Settings
  98. @StorageLink('title_bar_position') @Watch('on_title_bar_position_change') title_bar_position: string = "";
  99. @StorageLink('sys_back_to_access_backward') sys_back_to_access_backward: boolean = false;
  100. @StorageLink('web_force_dark_mode') web_force_dark_mode: boolean = false;
  101. @StorageLink('tabs_style') tabs_style: string = "";
  102. @StorageLink('tabs_style_non_tablet_mode') tabs_style_non_tablet_mode: string = "";
  103. @StorageLink('collect_new_history') collect_new_history: boolean = true;
  104. @StorageLink('intelligent_tracking_prevention') intelligent_tracking_prevention: boolean = false;
  105. @StorageLink('use_adblock') use_adblock: boolean = true;
  106. @StorageLink('adblock_exceptions') adblock_exceptions: string[] = [];
  107. @StorageLink('max_bookmark_advice') max_bookmark_advice: number = 5;
  108. @StorageLink('max_history_advice') max_history_advice: number = 5;
  109. // Settings - Accessibility
  110. @StorageLink('preferred_hand_left_or_right') preferred_hand_left_or_right: string = 'right';
  111. @StorageLink('preferred_hand_reverse_tabs_panel') preferred_hand_reverse_tabs_panel: boolean = false;
  112. // Gateways
  113. @StorageLink('universal_close_tab_gateway') uni_close_tab_gateway: number = -1;
  114. @StorageLink('universal_new_tab_gateway') uni_new_tab_gateway: string = "";
  115. // Dialogs
  116. @StorageLink('universal_fail_prompt_desc_gateway') @Watch('on_fail_prompt_gateway') universal_fail_prompt_desc_gateway: ResourceStr = "";
  117. @State fail_prompt_desc: ResourceStr = '';
  118. moveFailPrompt_control: CustomDialogController = new CustomDialogController({
  119. builder: woofPromptFail({
  120. desc: this.fail_prompt_desc,
  121. }),
  122. alignment: DialogAlignment.Center,
  123. cornerRadius: 16,
  124. // showInSubWindow: true,
  125. width: "90%",
  126. });
  127. woofHistory_control: CustomDialogController = new CustomDialogController({
  128. builder: woofHistory({ showing_settings: this.showing_app_settings }),
  129. alignment: DialogAlignment.Center,
  130. cornerRadius: 22,
  131. // showInSubWindow: true,
  132. width: "90%",
  133. });
  134. // Colors
  135. @StorageLink('color_light_primary') @Watch('on_color_change') color_light_primary: ResourceColor = $r('app.color.start_window_background');
  136. @StorageLink('color_light_secondary') @Watch('on_color_change') color_light_secondary: ResourceColor = $r('app.color.block_color');
  137. @StorageLink('color_light_font') @Watch('on_color_change') color_light_font: ResourceColor = $r('app.color.font_color_title');
  138. @StorageLink('color_dark_primary') @Watch('on_color_change') color_dark_primary: ResourceColor = $r('app.color.start_window_background');
  139. @StorageLink('color_dark_secondary') @Watch('on_color_change') color_dark_secondary: ResourceColor = $r('app.color.block_color');
  140. @StorageLink('color_dark_font') @Watch('on_color_change') color_dark_font: ResourceColor = $r('app.color.font_color_title');
  141. @StorageLink('color_current_primary') color_current_primary: ResourceColor = $r('app.color.start_window_background');
  142. @StorageLink('color_current_secondary') color_current_secondary: ResourceColor = $r('app.color.block_color');
  143. @StorageLink('color_current_font') color_current_font: ResourceColor = $r('app.color.font_color_title');
  144. async aboutToAppear(): Promise<void> {
  145. this.animation_response = await this.bunch_of_settings.get('animation_response') as number;
  146. this.animation_damping = await this.bunch_of_settings.get('animation_damping_coefficient') as number;
  147. let showing_tabs = await this.bunch_of_settings.get('status_tabs_open') as boolean;
  148. this.showing_tabs = showing_tabs;
  149. // Figure out what color should i use
  150. this.color_light_primary = await this.bunch_of_settings.get('color_light_primary') as string;
  151. this.color_light_secondary = await this.bunch_of_settings.get('color_light_secondary') as string;
  152. this.color_light_font = await this.bunch_of_settings.get('color_light_font') as string;
  153. this.color_dark_primary = await this.bunch_of_settings.get('color_dark_primary') as string;
  154. this.color_dark_secondary = await this.bunch_of_settings.get('color_dark_secondary') as string;
  155. this.color_dark_font = await this.bunch_of_settings.get('color_dark_font') as string;
  156. // Set cache dir of web-dragged image into Scratching Board
  157. try {
  158. fileIo.rmdirSync(this.getUIContext().getHostContext()!.filesDir + '/web-drag-image-cache');
  159. } catch (e) {
  160. console.error('[Index] rmdirSync /web-drag-image-cache failed! ' + e);
  161. }
  162. try {
  163. fileIo.mkdirSync(this.getUIContext().getHostContext()!.filesDir + '/web-drag-image-cache');
  164. } catch (e) {
  165. console.error('[Index] mkdirSync /web-drag-image-cache failed! ' + e);
  166. }
  167. // Respond to want
  168. this.check_want();
  169. // delete Profile package
  170. try {
  171. sandbox_unlink('profile.zip');
  172. } catch (e) {
  173. console.error('[Index] unlink profile.zip! ' + e);
  174. }
  175. // Get and set app version info
  176. bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION).then((bundleInfo) => {
  177. console.log('[Meow][bunch_of_history] Saving app version: ' + bundleInfo.versionName + "(" + bundleInfo.versionCode.toString() + ")");
  178. sandbox_save("last_app_versionCode.txt", bundleInfo.versionCode.toString());
  179. sandbox_save("last_app_versionName.txt", bundleInfo.versionName);
  180. })
  181. }
  182. onPageShow(): void {
  183. // Enable continue
  184. meowContext().setMissionContinueState(AbilityConstant.ContinueState.ACTIVE);
  185. }
  186. onBackPress(): boolean {
  187. return this.back();
  188. }
  189. build() {
  190. Column() {
  191. // I know this is stupid
  192. // Forgive me
  193. // O.o
  194. Row()// Keyboard shortcuts
  195. .keyboardShortcut(this.bunch_of_key_shortcuts.fullscreen.main_key, this.bunch_of_key_shortcuts.fullscreen.modifier, () => {
  196. this.fullscreen_mode = !this.fullscreen_mode;
  197. this.showing_more_options = false;
  198. })
  199. .keyboardShortcut(this.bunch_of_key_shortcuts.history.main_key, this.bunch_of_key_shortcuts.history.modifier, () => {
  200. this.woofHistory_control.open();
  201. })
  202. .keyboardShortcut(this.bunch_of_key_shortcuts.print.main_key, this.bunch_of_key_shortcuts.print.modifier, () => {
  203. print_web(this.bunch_of_tabs.workingMainTab().controller);
  204. })
  205. // .keyboardShortcut(FunctionKey.ESC, [], () => {
  206. // this.back();
  207. // })
  208. Row()// Top Bar Avoid
  209. .width("100%")
  210. .height(this.height_of_top_avoid())
  211. .backgroundColor(this.color_current_secondary)
  212. .animation(animation_default())
  213. // Scroll() {
  214. // Column() {
  215. RelativeContainer() {
  216. Row() {
  217. Scroll() {
  218. Row() {
  219. // 点击标签页展示的内容
  220. Scroll() {
  221. meowTabs()
  222. .width(this.width_of_Tabs())
  223. .padding(10)
  224. } // Tabs Panel
  225. .height("100%")
  226. .width(this.showing_tabs ? this.width_of_Tabs() : 0)
  227. .animation(animation_default())
  228. .scrollable(ScrollDirection.Horizontal)
  229. .scrollBar(BarState.Off)
  230. // 点击书签展示的内容
  231. Scroll() {
  232. meowBookmarks()
  233. .width(this.width_of_Bookmarks())
  234. .padding(10)
  235. } // Bookmarks Panel
  236. .height("100%")
  237. .width(this.showing_bookmarks ? this.width_of_Bookmarks() : 0)
  238. .animation(animation_default())
  239. .scrollable(ScrollDirection.Horizontal)
  240. .scrollBar(BarState.Off)
  241. }
  242. .width("100%")
  243. .height("100%")
  244. } // Bookmarks and Tabs
  245. .width(this.width_of_Bookmarks_and_Tabs())
  246. .margin(this.margin_of_Bookmarks_and_Tabs())
  247. .animation(animation_default())
  248. .scrollable(ScrollDirection.Horizontal)
  249. .scrollBar(BarState.Off)
  250. .height("100%")
  251. Row() {
  252. meowWebView()
  253. } // WebViews
  254. .width("100%")
  255. .backgroundColor(this.color_current_primary)
  256. .layoutWeight(this.tablet_mode ? 1 : 0)
  257. } // Main Web
  258. .direction(this.direction_of_web_and_side_panels())
  259. .alignRules(this.title_bar_alignRules)
  260. .layoutWeight(1)
  261. .width("100%")
  262. .backgroundColor(this.color_current_primary)
  263. .onAreaChange((o, n) => {
  264. this.on_main_area_change(o, n);
  265. })
  266. .margin(this.title_bar_position == "bottom"
  267. ? { bottom: this.fullscreen_mode ? 0 : this.title_bar_height }
  268. : { top: this.fullscreen_mode ? 0 : this.title_bar_height })
  269. .animation(animation_default())
  270. linysProgress({ percentage: this.current_loading_progress, is_loading: this.current_is_loading })
  271. .alignRules(this.title_bar_alignRules)
  272. .margin(this.title_bar_position == "bottom"
  273. ? { bottom: this.fullscreen_mode ? 0 : this.title_bar_height }
  274. : { top: this.fullscreen_mode ? 0 : this.title_bar_height })
  275. meowTitleBar({
  276. bar_height: this.title_bar_height,
  277. title_bar_alignRules: this.title_bar_alignRules,
  278. }) // Title Bar
  279. } // Web, progress, and Title bar // .height(this.screen_height - this.height_of_top_avoid())
  280. .layoutWeight(1)
  281. .animation(animation_default())
  282. Row()// Bottom Bar Avoid
  283. .width("100%")
  284. .height(this.height_of_bottom_avoid())
  285. .animation(animation_default())
  286. .backgroundColor(this.title_bar_position == "bottom" ? "transparent" : this.color_current_secondary)
  287. // }
  288. // }
  289. // .width('100%')
  290. // .layoutWeight(1)
  291. }
  292. .height("100%")
  293. .width("100%")
  294. .alignItems(HorizontalAlign.Start)
  295. .animation(animation_default())
  296. .backgroundColor(this.color_current_secondary)
  297. .onAreaChange((_o, n) => {
  298. this.full_screen_height = n.height as number;
  299. })
  300. .onAppear(() => {
  301. // console.log("[Meow][Index] Home Index READY")
  302. })
  303. }
  304. // @Watch or environment Reactions
  305. on_title_bar_position_change() {
  306. if (this.title_bar_position == "bottom") {
  307. this.title_bar_alignRules = {
  308. middle: { anchor: "__container__", align: HorizontalAlign.Center },
  309. bottom: { anchor: "__container__", align: VerticalAlign.Bottom }
  310. }
  311. } else {
  312. this.title_bar_alignRules = {
  313. middle: { anchor: "__container__", align: HorizontalAlign.Center },
  314. top: { anchor: "__container__", align: VerticalAlign.Top }
  315. }
  316. }
  317. }
  318. on_main_area_change(_old: Area, n: Area) {
  319. this.screen_width = n.width as number;
  320. this.screen_height = n.height as number;
  321. this.tablet_mode = this.screen_width > 600;
  322. if (!this.tablet_mode) {
  323. if (this.showing_tabs && this.showing_bookmarks) {
  324. // If showing both tabs and bookmarks,
  325. // then close tabs when switched to non-tablet mode
  326. if (this.tabs_style_non_tablet_mode == "vertical") {
  327. this.showing_tabs = false;
  328. }
  329. }
  330. }
  331. }
  332. on_showing_tabs_change() {
  333. this.bunch_of_settings.set('status_tabs_open', this.showing_tabs);
  334. }
  335. on_fail_prompt_gateway() {
  336. if (this.universal_fail_prompt_desc_gateway != "") {
  337. this.fail_prompt_desc = this.universal_fail_prompt_desc_gateway;
  338. this.moveFailPrompt_control.open();
  339. this.universal_fail_prompt_desc_gateway = "";
  340. }
  341. }
  342. on_color_mode_change() {
  343. if (this.current_color_mode == ConfigurationConstant.ColorMode.COLOR_MODE_DARK) {
  344. // Is dark mode
  345. this.color_current_primary = this.color_dark_primary;
  346. this.color_current_secondary = this.color_dark_secondary;
  347. this.color_current_font = this.color_dark_font;
  348. } else {
  349. this.color_current_primary = this.color_light_primary;
  350. this.color_current_secondary = this.color_light_secondary;
  351. this.color_current_font = this.color_light_font;
  352. }
  353. }
  354. on_color_change() {
  355. console.log('[Meow][Index] Color theme changed!');
  356. // Refresh current color
  357. if (this.current_color_mode == ConfigurationConstant.ColorMode.COLOR_MODE_DARK) {
  358. // Is dark mode
  359. this.color_current_primary = this.color_dark_primary;
  360. this.color_current_secondary = this.color_dark_secondary;
  361. this.color_current_font = this.color_dark_font;
  362. } else {
  363. this.color_current_primary = this.color_light_primary;
  364. this.color_current_secondary = this.color_light_secondary;
  365. this.color_current_font = this.color_light_font;
  366. }
  367. }
  368. on_fullscreen_switch() {
  369. window.getLastWindow(this.getUIContext().getHostContext()).then((win) => {
  370. if (this.fullscreen_mode) {
  371. win.setWindowSystemBarEnable([]);
  372. } else {
  373. win.setWindowSystemBarEnable(["status", "navigation"]);
  374. }
  375. })
  376. }
  377. on_bunch_of_key_shortcuts_change() {
  378. console.log('[Index] on_bunch_of_key_shortcuts_change!');
  379. }
  380. // kinda params
  381. width_of_Bookmarks_and_Tabs() {
  382. let result = 0;
  383. if (this.tablet_mode) {
  384. if (this.showing_tabs && this.tabs_style != 'horizontal') {
  385. result += 250;
  386. }
  387. if (this.showing_bookmarks) {
  388. result += 350;
  389. }
  390. } else {
  391. // non_tablet_mode
  392. if (this.showing_bookmarks) {
  393. result += 0.9 * this.screen_width;
  394. }
  395. if (this.showing_tabs && this.tabs_style_non_tablet_mode == 'vertical') {
  396. result += 0.9 * this.screen_width;
  397. }
  398. }
  399. return result;
  400. }
  401. margin_of_Bookmarks_and_Tabs(): Padding | number {
  402. if (this.width_of_Bookmarks_and_Tabs() == 0) {
  403. return 0;
  404. }
  405. let status = this.preferred_hand_left_or_right == 'right';
  406. if (this.preferred_hand_reverse_tabs_panel) {
  407. status = !status;
  408. }
  409. return status ? { right: this.rightAvoidWidth } : { left: this.leftAvoidWidth };
  410. }
  411. width_of_Bookmarks() {
  412. if (this.tablet_mode) {
  413. return 350;
  414. }
  415. return 0.9 * this.screen_width;
  416. }
  417. width_of_Tabs() {
  418. if (this.tablet_mode) {
  419. // Tablet mode
  420. if (this.tabs_style == 'horizontal') {
  421. return 0;
  422. } else {
  423. return 250;
  424. }
  425. } else {
  426. // non_tablet_mode
  427. if (this.tabs_style_non_tablet_mode == 'horizontal') {
  428. return 0;
  429. } else {
  430. return 0.9 * this.screen_width;
  431. }
  432. }
  433. }
  434. height_of_top_avoid() {
  435. if (this.fullscreen_mode) {
  436. return 0;
  437. }
  438. if (deviceInfo.deviceType == '2in1' && this.title_bar_position == 'top' && this.tabs_style == 'horizontal' && this.showing_tabs && this.tablet_mode) {
  439. return 10;
  440. }
  441. return this.topAvoidHeight;
  442. }
  443. height_of_bottom_avoid() {
  444. if (this.fullscreen_mode) {
  445. return 0;
  446. }
  447. if (deviceInfo.deviceType == '2in1') {
  448. return 0;
  449. }
  450. let target = this.bottomAvoidHeight;
  451. if (this.title_bar_position == "bottom") {
  452. target -= 20;
  453. }
  454. return Math.max(0, target);
  455. }
  456. direction_of_web_and_side_panels() {
  457. let status = this.preferred_hand_left_or_right == 'right';
  458. if (this.preferred_hand_reverse_tabs_panel) {
  459. status = !status;
  460. }
  461. return status ? Direction.Rtl : Direction.Ltr;
  462. }
  463. // Operations
  464. check_want() {
  465. if (this.want_uri.length == 0) {
  466. // console.log('[Index] Didn\'t load want for an empty want.');
  467. return;
  468. }
  469. console.log('[Meow][Index] Load want with action: ' + this.want_action + ', type: ' + this.want_type);
  470. if (this.want_uri.substring(0, 7) == 'file://') {
  471. this.want_file();
  472. } else {
  473. this.want_web();
  474. }
  475. // Respond to want
  476. this.want_uri = "";
  477. }
  478. want_file() {
  479. // TODO: Find a more elegant way to open things...
  480. console.log('[Meow][Index][Want] Want uri is file://. Copying file to sandbox root!');
  481. // Copy want file
  482. try {
  483. let file_content = uri_read_text_sync(this.want_uri);
  484. this.uni_new_tab_gateway = 'data:text/html, ' + encodeURIComponent(file_content);
  485. // let want_file_uri = copy_from_uri_to_sandbox(this.want_uri, '', 'want-cache.html');
  486. // this.uni_new_tab_gateway = want_file_uri;
  487. } catch (e) {
  488. console.error(e);
  489. }
  490. }
  491. want_web() {
  492. if (this.want_action == "ohos.want.action.viewData") {
  493. console.log('[Meow][Index] Load want uri: ' + this.want_uri);
  494. this.uni_new_tab_gateway = this.want_uri;
  495. }
  496. }
  497. /**
  498. * Universal Go back function
  499. * @returns true if successfully executed <Back> for some effects.
  500. * */
  501. back() {
  502. let stop_system_back = false;
  503. if (this.fullscreen_mode) {
  504. if (this.handler != null) {
  505. this.handler.exitFullScreen();
  506. }
  507. this.fullscreen_mode = false;
  508. return true;
  509. }
  510. let showing_ui_panels = this.showing_downloads || this.showing_more_options || this.showing_app_settings || this.showing_scratching_board;
  511. // I know this is stupid but ¯\_(ツ)_/¯ it just works
  512. // Prioritize closing UI panels
  513. if (this.tablet_mode) {
  514. if (showing_ui_panels) {
  515. this.showing_downloads = false;
  516. this.showing_more_options = false;
  517. this.showing_app_settings = false;
  518. this.showing_scratching_board = false;
  519. return true;
  520. }
  521. } else {
  522. // Non-tablet mode
  523. if (showing_ui_panels || this.showing_bookmarks || this.showing_tabs) {
  524. this.showing_downloads = false;
  525. this.showing_more_options = false;
  526. this.showing_app_settings = false;
  527. this.showing_scratching_board = false;
  528. // Specials
  529. if (this.tabs_style_non_tablet_mode == "vertical") {
  530. this.showing_tabs = false;
  531. }
  532. this.showing_bookmarks = false;
  533. return true;
  534. }
  535. }
  536. // Other returns
  537. // Only triggers if no closable UI panels are opened
  538. if (this.sys_back_to_access_backward) {
  539. if (this.go_back_tab()) {
  540. stop_system_back = true;
  541. } else if (this.bunch_of_tabs.get_tabs_count() > 1) {
  542. // Can close something
  543. this.uni_close_tab_gateway = this.current_main_tab_index;
  544. stop_system_back = true;
  545. }
  546. }
  547. return stop_system_back;
  548. }
  549. go_back_tab(): boolean {
  550. return this.bunch_of_tabs.goBackward_onWorkingTab();
  551. }
  552. }