From 0196144075499134a90457b79099daf33c41e6cd Mon Sep 17 00:00:00 2001 From: jsnk Date: Sat, 25 Oct 2025 12:56:41 +0200 Subject: [PATCH] cc --- lib/models/tab_data.dart | 2 ++ lib/services/browser_api_service.dart | 35 +++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lib/models/tab_data.dart b/lib/models/tab_data.dart index ca352b7..7914883 100644 --- a/lib/models/tab_data.dart +++ b/lib/models/tab_data.dart @@ -37,6 +37,8 @@ class TabData { // ?? IF left is null, use right // left side is field, right side is parameter the new saved value : lastAccessed = lastAccessed ?? DateTime.now(); + // + // USABLE Object we can call other places // factory logic before constructor, from json so we don't have to extract later. factory TabData.fromJson(Map json) => TabData( diff --git a/lib/services/browser_api_service.dart b/lib/services/browser_api_service.dart index a145a33..4073f45 100644 --- a/lib/services/browser_api_service.dart +++ b/lib/services/browser_api_service.dart @@ -6,13 +6,20 @@ import '../models/tab_data.dart'; // communication with the browser API // list of TabData objects -// results LATER -// API takes time so future +// result LATER +// API takes time so Future as a Type // ASYNC WAIT // return empty if fail -// final cannot be changed - +// try catch no crash +// final for security, assign once then locked, can't change main data. +// API string result +// dynamic list "ANY" Type +// decode to list of maps so its ready for use +// objects +// a map is EXPLAIN +// .map method DOES +// .toList adding to a list of objects that can be called for the data class BrowserApiService { Future> getTabs() async { @@ -83,6 +90,24 @@ class BrowserApiService { await _callBrowserAPI('togglePinTab', [tabId, pin]); } +// _callBrowserAPI bridging +// Future +// return string or ? null +// method what to call +// optional list args for history "100" +// a check for browser API +// js_util call JavaScript functions +// promiseToFuture convert +// html.window global scope +// extension is a top level javascript +// extension adds BrowserAPI to window as a global + +// final result check if args is null +// call function that fits +// Encode javascript object to drat object +// And that is why json format is fucking genius... + + Future _callBrowserAPI(String method, [List? args]) async { try { if (!js_util.hasProperty(html.window, 'BrowserAPI')) { @@ -109,7 +134,7 @@ class BrowserApiService { // // Methods fetching from browser, convert to TabData objects. // -// SwitchToTab, openTab, closeTab allow control of tabs programmatically. +// SwitchToTab, openTab, closeTab allow control of tabs. // // _callBrowserAPI low level JavaScript communication. //