mirror of
https://github.com/zulip/zulip-desktop.git
synced 2025-10-24 00:23:36 +00:00
And enable the import/unambiguous ESLint rule as a check on our
partition between scripts and modules. After this commit, if you add
a new file and get this error:
✖ 1:1 This module could be parsed as a valid script. import/unambiguous
* For a module, add an `import` or `export` declaration to make the
file unambiguously a module (the empty `export {};` declaration
suffices).
* For a script, add the file to the xo overrides section of
package.json that marks it "sourceType": "script", and add a 'use
strict' declaration.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import { JsonDB } from 'node-json-db';
|
|
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import electron from 'electron';
|
|
import Logger from './logger-util';
|
|
|
|
const remote =
|
|
process.type === 'renderer' ? electron.remote : electron;
|
|
|
|
const logger = new Logger({
|
|
file: 'linux-update-util.log',
|
|
timestamp: true
|
|
});
|
|
|
|
/* To make the util runnable in both main and renderer process */
|
|
const { dialog, app } = remote;
|
|
|
|
let db: JsonDB;
|
|
|
|
reloadDB();
|
|
|
|
export function getUpdateItem(key: string, defaultValue: any = null): any {
|
|
reloadDB();
|
|
const value = db.getData('/')[key];
|
|
if (value === undefined) {
|
|
setUpdateItem(key, defaultValue);
|
|
return defaultValue;
|
|
} else {
|
|
return value;
|
|
}
|
|
}
|
|
|
|
export function setUpdateItem(key: string, value: any): void {
|
|
db.push(`/${key}`, value, true);
|
|
reloadDB();
|
|
}
|
|
|
|
export function removeUpdateItem(key: string): void {
|
|
db.delete(`/${key}`);
|
|
reloadDB();
|
|
}
|
|
|
|
function reloadDB(): void {
|
|
const linuxUpdateJsonPath = path.join(app.getPath('userData'), '/config/updates.json');
|
|
try {
|
|
const file = fs.readFileSync(linuxUpdateJsonPath, 'utf8');
|
|
JSON.parse(file);
|
|
} catch (err) {
|
|
if (fs.existsSync(linuxUpdateJsonPath)) {
|
|
fs.unlinkSync(linuxUpdateJsonPath);
|
|
dialog.showErrorBox(
|
|
'Error saving update notifications.',
|
|
'We encountered an error while saving the update notifications.'
|
|
);
|
|
logger.error('Error while JSON parsing updates.json: ');
|
|
logger.error(err);
|
|
}
|
|
}
|
|
db = new JsonDB(linuxUpdateJsonPath, true, true);
|
|
}
|