cc
This commit is contained in:
parent
f0354e706e
commit
0196144075
2 changed files with 32 additions and 5 deletions
|
|
@ -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<String, dynamic> json) => TabData(
|
||||
|
|
|
|||
|
|
@ -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<List<TabData>> 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<String?> _callBrowserAPI(String method, [List<dynamic>? 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.
|
||||
//
|
||||
|
|
|
|||
Loading…
Reference in a new issue