From 2005434aed54bba0e662d3711efcd332690a4533 Mon Sep 17 00:00:00 2001 From: wuyudi Date: Wed, 8 Feb 2023 00:20:45 +0900 Subject: [PATCH] more ts --- package-lock.json | 17 ++++++++++++++ package.json | 1 + src/client/{dispatcher.js => dispatcher.ts} | 0 ...retStorageKeys.js => secretStorageKeys.ts} | 3 ++- src/client/state/{settings.js => settings.ts} | 23 +++++++++++++++---- 5 files changed, 38 insertions(+), 6 deletions(-) rename src/client/{dispatcher.js => dispatcher.ts} (100%) rename src/client/state/{secretStorageKeys.js => secretStorageKeys.ts} (92%) rename src/client/state/{settings.js => settings.ts} (89%) diff --git a/package-lock.json b/package-lock.json index 6639aac8..6fae4364 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,6 +43,7 @@ "@esbuild-plugins/node-globals-polyfill": "0.2.3", "@rollup/plugin-inject": "5.0.3", "@rollup/plugin-wasm": "6.1.1", + "@types/flux": "3.1.11", "@types/node": "18.11.18", "@types/react": "18.0.26", "@types/react-dom": "18.0.9", @@ -1119,6 +1120,22 @@ "resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz", "integrity": "sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==" }, + "node_modules/@types/fbemitter": { + "version": "2.0.32", + "resolved": "https://registry.npmjs.org/@types/fbemitter/-/fbemitter-2.0.32.tgz", + "integrity": "sha512-Hwq28bBlbmfCgLnNJvjl5ssTrbZCTSblI4vqPpqZrbbEL8vn5l2UivxhlMYfUY7a4SR8UB6RKoLjOZfljqAa6g==", + "dev": true + }, + "node_modules/@types/flux": { + "version": "3.1.11", + "resolved": "https://registry.npmjs.org/@types/flux/-/flux-3.1.11.tgz", + "integrity": "sha512-Aq4UB1ZqAKcPbhB0GpgMw2sntvOh71he9tjz53TLKrI7rw3Y3LxCW5pTYY9IV455hQapm4pmxFjpqlWOs308Yg==", + "dev": true, + "dependencies": { + "@types/fbemitter": "*", + "@types/react": "*" + } + }, "node_modules/@types/json-schema": { "version": "7.0.11", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz", diff --git a/package.json b/package.json index 72ca6805..c86d2ecc 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "@esbuild-plugins/node-globals-polyfill": "0.2.3", "@rollup/plugin-inject": "5.0.3", "@rollup/plugin-wasm": "6.1.1", + "@types/flux": "3.1.11", "@types/node": "18.11.18", "@types/react": "18.0.26", "@types/react-dom": "18.0.9", diff --git a/src/client/dispatcher.js b/src/client/dispatcher.ts similarity index 100% rename from src/client/dispatcher.js rename to src/client/dispatcher.ts diff --git a/src/client/state/secretStorageKeys.js b/src/client/state/secretStorageKeys.ts similarity index 92% rename from src/client/state/secretStorageKeys.js rename to src/client/state/secretStorageKeys.ts index 7439e7a5..21fe4157 100644 --- a/src/client/state/secretStorageKeys.js +++ b/src/client/state/secretStorageKeys.ts @@ -1,6 +1,6 @@ const secretStorageKeys = new Map(); -export function storePrivateKey(keyId, privateKey) { +export function storePrivateKey(keyId, privateKey: Uint8Array) { if (privateKey instanceof Uint8Array === false) { throw new Error('Unable to store, privateKey is invalid.'); } @@ -16,6 +16,7 @@ export function getPrivateKey(keyId) { } export function deletePrivateKey(keyId) { + //@ts-ignore delete secretStorageKeys.delete(keyId); } diff --git a/src/client/state/settings.js b/src/client/state/settings.ts similarity index 89% rename from src/client/state/settings.js rename to src/client/state/settings.ts index 32f55fcc..7444cb3f 100644 --- a/src/client/state/settings.js +++ b/src/client/state/settings.ts @@ -3,20 +3,30 @@ import appDispatcher from '../dispatcher'; import cons from './cons'; -function getSettings() { +function getSettings(): Settings { const settings = localStorage.getItem('settings'); if (settings === null) return null; return JSON.parse(settings); } -function setSettings(key, value) { +function setSettings(key: string, value) { let settings = getSettings(); - if (settings === null) settings = {}; + if (settings === null) settings = new Settings(); settings[key] = value; localStorage.setItem('settings', JSON.stringify(settings)); } class Settings extends EventEmitter { + themes: string[]; + themeIndex: number; + useSystemTheme: boolean; + isMarkdown: boolean; + isPeopleDrawer: boolean; + hideMembershipEvents: boolean; + hideNickAvatarEvents: boolean; + _showNotifications: boolean; + isNotificationSounds: boolean; + isTouchScreenDevice: boolean; constructor() { super(); @@ -31,7 +41,10 @@ class Settings extends EventEmitter { this._showNotifications = this.getShowNotifications(); this.isNotificationSounds = this.getIsNotificationSounds(); - this.isTouchScreenDevice = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0); + this.isTouchScreenDevice = + // https://github.com/microsoft/vscode/issues/127822#issuecomment-874324028 + // msMaxTouchPoints is for IE 10 which we don't support anymore, we can remove that. + 'ontouchstart' in window || navigator.maxTouchPoints > 0; } getThemeIndex() { @@ -41,7 +54,7 @@ class Settings extends EventEmitter { if (settings === null) return 0; if (typeof settings.themeIndex === 'undefined') return 0; // eslint-disable-next-line radix - return parseInt(settings.themeIndex); + return Math.floor(settings.themeIndex); } getThemeName() {