From ba349d96cf228a6d1f07a1911f61e0c4fe7f52f1 Mon Sep 17 00:00:00 2001 From: projectmoon Date: Wed, 22 Mar 2023 15:55:35 +0100 Subject: [PATCH] Do not run leveldb on content script --- src/background/message-handler.ts | 6 +++++- src/state/level.ts | 4 +--- todo.org | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/background/message-handler.ts b/src/background/message-handler.ts index 84a489f..b3b8a75 100644 --- a/src/background/message-handler.ts +++ b/src/background/message-handler.ts @@ -1,10 +1,14 @@ import { isStatePopulated, isStateClear, PartialStateUpdate, ExporterState, isStateAbleToRequest } from "../state"; import { Status } from '../state'; -import { State } from '../state/level'; +import { LevelState } from '../state/level'; import * as landsbankinn from '../landsbankinn'; import { fetchAccounts } from "../landsbankinn"; import { Actions, EnsureStateMessage, EnsureStateReply, GetAccountsReply } from './messages'; +// State singleton (move to its own file if we eventually get more +// than 1 background script) +const State = new LevelState(); + async function ensureDataPopulated(state: ExporterState) { if (isStateAbleToRequest(state) && !isStatePopulated(state)) { const accounts = await fetchAccounts(state); diff --git a/src/state/level.ts b/src/state/level.ts index 7c14f24..ff0f1c5 100644 --- a/src/state/level.ts +++ b/src/state/level.ts @@ -7,7 +7,7 @@ type LevelError = Error | null | undefined; //@ts-ignore const errorNotFound = (err: LevelError) => err.code && err.code == 'LEVEL_NOT_FOUND'; -class LevelState { +export class LevelState { private _db = new Level('landsbankinn-exporter', { valueEncoding: 'json' }); private currentTTLHandle: number | undefined = -1; @@ -55,5 +55,3 @@ class LevelState { return this.current; } } - -export const State: LevelState = new LevelState(); diff --git a/todo.org b/todo.org index 8d56ee8..912cdfe 100644 --- a/todo.org +++ b/todo.org @@ -2,10 +2,10 @@ How to get it working: - [X] Landsbankinn API client for arbitrary transaction lists - [ ] Transform raw transactions into friendlier ones (i.e. date objects) - [X] Content script that can run all the time and puts a button somewhere (statements tab, and extension icon) - - [ ] Use config.ts to set TTL for state + - [X] Use config.ts to set TTL for state - [ ] Background page that downloads all the shit and combines into CSV, then 'downloads' file. - [X] Build up communication message passing to background page for downloads - - [ ] Don't run level on client. + - [X] Don't run level on client. - [-] Investigate persistent = false + setTimeout - [ ] Maybe can force clear state when page reloads itself? - [X] Change ready true/false to lock state, of not updated, updating, ready