mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-08-15 03:42:50 +00:00
Receivers: Moved Store module to common components
This commit is contained in:
parent
dd813cd0ea
commit
6b16af4b7d
6 changed files with 112 additions and 120 deletions
|
@ -9,6 +9,7 @@ import { ConnectionMonitor } from 'common/ConnectionMonitor';
|
|||
import { Logger, LoggerType } from 'common/Logger';
|
||||
import { fetchJSON } from 'common/UtilityBackend';
|
||||
import { MediaCache } from 'common/MediaCache';
|
||||
import { Store } from 'common/Store';
|
||||
import { Updater } from './Updater';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
|
@ -475,6 +476,11 @@ export class Main {
|
|||
})
|
||||
.parseSync();
|
||||
|
||||
// Using singleton classes for better compatibility running on webOS
|
||||
const jsonPath = path.join(app.getPath('userData'), 'UserSettings.json');
|
||||
new Store(jsonPath);
|
||||
|
||||
new Updater();
|
||||
const isUpdating = Updater.isUpdating();
|
||||
const fileLogType = isUpdating ? 'fileSync' : 'file';
|
||||
Logger.initialize({
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import storage from 'electron-json-storage';
|
||||
import { app } from 'electron';
|
||||
import { Logger, LoggerType } from 'common/Logger';
|
||||
const logger = new Logger('Store', LoggerType.BACKEND);
|
||||
|
||||
export class Store {
|
||||
private static storeVersion = 1;
|
||||
private static userSettings = 'UserSettings';
|
||||
private static settingsCache: any = null;
|
||||
|
||||
static {
|
||||
storage.setDataPath(app.getPath('userData'));
|
||||
Store.settingsCache = storage.getSync(Store.userSettings);
|
||||
|
||||
if (Store.get('storeVersion') === null) {
|
||||
Store.set('storeVersion', Store.storeVersion);
|
||||
}
|
||||
}
|
||||
|
||||
public static get(key: string): any {
|
||||
return Store.settingsCache[key] ?? null;
|
||||
}
|
||||
|
||||
public static set(key: string, value: any) {
|
||||
Store.settingsCache[key] = value;
|
||||
|
||||
logger.info(`Writing settings file: key '${key}', value ${JSON.stringify(value)}`);
|
||||
storage.set(Store.userSettings, Store.settingsCache, (err) => {
|
||||
if (err) {
|
||||
logger.error(`Error writing user settings: ${err}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -2,8 +2,8 @@ import * as fs from 'fs';
|
|||
import * as path from 'path';
|
||||
import * as crypto from 'crypto';
|
||||
import { app } from 'electron';
|
||||
import { Store } from './Store';
|
||||
import sudo from 'sudo-prompt';
|
||||
import { Store } from 'common/Store';
|
||||
import { Logger, LoggerType } from 'common/Logger';
|
||||
import { fetchJSON, downloadFile } from 'common/UtilityBackend';
|
||||
|
||||
|
@ -50,6 +50,7 @@ interface UpdateConditions {
|
|||
}
|
||||
|
||||
export class Updater {
|
||||
private static instance: Store = null;
|
||||
private static readonly supportedReleasesJsonVersion = '1';
|
||||
|
||||
private static appPath: string = app.getAppPath();
|
||||
|
@ -73,22 +74,27 @@ export class Updater {
|
|||
public static releaseChannel = 'stable';
|
||||
public static updateChannel = 'stable';
|
||||
|
||||
static {
|
||||
Updater.localPackageJson = JSON.parse(fs.readFileSync(path.join(Updater.appPath, './package.json'), 'utf8'));
|
||||
constructor() {
|
||||
if (!Updater.instance) {
|
||||
Updater.localPackageJson = JSON.parse(fs.readFileSync(path.join(Updater.appPath, './package.json'), 'utf8'));
|
||||
|
||||
let updaterSettings = Store.get('updater');
|
||||
if (updaterSettings !== null) {
|
||||
Updater.updateChannel = updaterSettings.channel === undefined ? Updater.localPackageJson.channel : updaterSettings.channel;
|
||||
Updater.checkForUpdatesOnStart = updaterSettings.checkForUpdatesOnStart === undefined ? true : updaterSettings.checkForUpdatesOnStart;
|
||||
let updaterSettings = Store.settings.updater;
|
||||
if (updaterSettings !== null) {
|
||||
Updater.updateChannel = updaterSettings.channel === undefined ? Updater.localPackageJson.channel : updaterSettings.channel;
|
||||
Updater.checkForUpdatesOnStart = updaterSettings.checkForUpdatesOnStart === undefined ? true : updaterSettings.checkForUpdatesOnStart;
|
||||
}
|
||||
|
||||
updaterSettings = {
|
||||
'channel': Updater.updateChannel,
|
||||
'checkForUpdatesOnStart': Updater.checkForUpdatesOnStart,
|
||||
}
|
||||
|
||||
Updater.releaseChannel = Updater.localPackageJson.channel;
|
||||
Store.settings.updater = updaterSettings;
|
||||
Store.saveSettings();
|
||||
|
||||
Updater.instance = this;
|
||||
}
|
||||
|
||||
updaterSettings = {
|
||||
'channel': Updater.updateChannel,
|
||||
'checkForUpdatesOnStart': Updater.checkForUpdatesOnStart,
|
||||
}
|
||||
|
||||
Updater.releaseChannel = Updater.localPackageJson.channel;
|
||||
Store.set('updater', updaterSettings);
|
||||
}
|
||||
|
||||
private static async applyUpdate(src: string, dst: string) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue