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
|
// ?? IF left is null, use right
|
||||||
// left side is field, right side is parameter the new saved value
|
// left side is field, right side is parameter the new saved value
|
||||||
: lastAccessed = lastAccessed ?? DateTime.now();
|
: 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 logic before constructor, from json so we don't have to extract later.
|
||||||
factory TabData.fromJson(Map<String, dynamic> json) => TabData(
|
factory TabData.fromJson(Map<String, dynamic> json) => TabData(
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,20 @@ import '../models/tab_data.dart';
|
||||||
|
|
||||||
// communication with the browser API
|
// communication with the browser API
|
||||||
// list of TabData objects
|
// list of TabData objects
|
||||||
// results LATER
|
// result LATER
|
||||||
// API takes time so future
|
// API takes time so Future as a Type
|
||||||
// ASYNC WAIT
|
// ASYNC WAIT
|
||||||
// return empty if fail
|
// 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 {
|
class BrowserApiService {
|
||||||
Future<List<TabData>> getTabs() async {
|
Future<List<TabData>> getTabs() async {
|
||||||
|
|
@ -83,6 +90,24 @@ class BrowserApiService {
|
||||||
await _callBrowserAPI('togglePinTab', [tabId, pin]);
|
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 {
|
Future<String?> _callBrowserAPI(String method, [List<dynamic>? args]) async {
|
||||||
try {
|
try {
|
||||||
if (!js_util.hasProperty(html.window, 'BrowserAPI')) {
|
if (!js_util.hasProperty(html.window, 'BrowserAPI')) {
|
||||||
|
|
@ -109,7 +134,7 @@ class BrowserApiService {
|
||||||
//
|
//
|
||||||
// Methods fetching from browser, convert to TabData objects.
|
// 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.
|
// _callBrowserAPI low level JavaScript communication.
|
||||||
//
|
//
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue