mirror of
https://github.com/viktoruj/obsidian-cloud-kms.git
synced 2026-07-22 06:56:21 +00:00
fix: resolve safe TypeScript warnings (types, void, async)
This commit is contained in:
parent
ef91121005
commit
34f6475e9a
6 changed files with 18 additions and 17 deletions
|
|
@ -6,7 +6,7 @@
|
|||
* The file name does NOT change. The content is replaced with OCKE binary format.
|
||||
*/
|
||||
|
||||
import { Notice, Plugin, FuzzySuggestModal } from 'obsidian';
|
||||
import { App, Notice, Plugin, FuzzySuggestModal } from 'obsidian';
|
||||
import type { CryptoEngine, EncryptionContext, PluginSettings } from '../types';
|
||||
import { FORMAT_VERSION, KMS_FILE_TIMEOUT_MS, NOTICE_DURATION_MS } from '../constants';
|
||||
import { serialize } from '../format/serializer';
|
||||
|
|
@ -82,13 +82,13 @@ async function executeEncryptFile(
|
|||
await doEncrypt(plugin, cryptoEngine, file.path, contentBytes, arn);
|
||||
} else {
|
||||
// Multiple keys — show picker
|
||||
new KeyPickerModal(plugin.app, aliases, async (chosen) => {
|
||||
new KeyPickerModal(plugin.app, aliases, (chosen) => {
|
||||
const arn = resolveKeyArn(chosen, settings);
|
||||
if (!arn) {
|
||||
new Notice(`Key "${chosen}" has no valid ARN.`, NOTICE_DURATION_MS);
|
||||
return;
|
||||
}
|
||||
await doEncrypt(plugin, cryptoEngine, file.path, contentBytes, arn);
|
||||
void doEncrypt(plugin, cryptoEngine, file.path, contentBytes, arn);
|
||||
}).open();
|
||||
}
|
||||
}
|
||||
|
|
@ -141,7 +141,7 @@ class KeyPickerModal extends FuzzySuggestModal<string> {
|
|||
private readonly aliases: string[];
|
||||
private readonly onChoose: (alias: string) => void;
|
||||
|
||||
constructor(app: any, aliases: string[], onChoose: (alias: string) => void) {
|
||||
constructor(app: App, aliases: string[], onChoose: (alias: string) => void) {
|
||||
super(app);
|
||||
this.aliases = aliases;
|
||||
this.onChoose = onChoose;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
* The actual encryption happens transparently via the adapter patch on save.
|
||||
*/
|
||||
|
||||
import { Notice, Plugin, MarkdownView, FuzzySuggestModal } from 'obsidian';
|
||||
import { App, Editor, Notice, Plugin, MarkdownView, FuzzySuggestModal } from 'obsidian';
|
||||
import type { CryptoEngine, PluginSettings } from '../types';
|
||||
import { MAX_SELECTION_CHARS, NOTICE_DURATION_MS } from '../constants';
|
||||
import { getKeyAliases } from '../utils/key-resolver';
|
||||
|
|
@ -37,7 +37,7 @@ function executeWrapSelection(plugin: Plugin, getSettings: () => PluginSettings)
|
|||
return;
|
||||
}
|
||||
|
||||
const editor = markdownView.editor;
|
||||
const editor: Editor = markdownView.editor;
|
||||
const selection = editor.getSelection();
|
||||
|
||||
if (!selection || selection.length === 0) {
|
||||
|
|
@ -68,7 +68,7 @@ function executeWrapSelection(plugin: Plugin, getSettings: () => PluginSettings)
|
|||
}
|
||||
}
|
||||
|
||||
function wrapWithAlias(editor: any, selection: string, alias: string | undefined): void {
|
||||
function wrapWithAlias(editor: Editor, selection: string, alias: string | undefined): void {
|
||||
const startMarker = alias ? `%%secret-start:${alias}%%` : '%%secret-start%%';
|
||||
const secretBlock = `${startMarker}\n${selection}\n%%secret-end%%`;
|
||||
editor.replaceSelection(secretBlock);
|
||||
|
|
@ -81,7 +81,7 @@ class KeyPickerModal extends FuzzySuggestModal<string> {
|
|||
private readonly aliases: string[];
|
||||
private readonly onChoose: (alias: string) => void;
|
||||
|
||||
constructor(app: any, aliases: string[], onChoose: (alias: string) => void) {
|
||||
constructor(app: App, aliases: string[], onChoose: (alias: string) => void) {
|
||||
super(app);
|
||||
this.aliases = aliases;
|
||||
this.onChoose = onChoose;
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ export default class CloudKmsPlugin extends Plugin {
|
|||
registerAttachmentHook(this, this.cryptoEngine, () => this.settings, this.bufferRegistry);
|
||||
|
||||
// 9. File explorer badge for encrypted files
|
||||
this.uninstallBadge = installFileExplorerBadge(this, this.originalReadBinary!);
|
||||
this.uninstallBadge = installFileExplorerBadge(this, this.originalReadBinary);
|
||||
|
||||
// 10. Status bar KMS indicator
|
||||
this.uninstallStatusBar = installStatusBar(this, () => this.settings);
|
||||
|
|
@ -78,7 +78,7 @@ export default class CloudKmsPlugin extends Plugin {
|
|||
registerEncryptedFileView(this);
|
||||
}
|
||||
|
||||
async onunload(): Promise<void> {
|
||||
onunload(): void {
|
||||
// Restore original adapter methods
|
||||
if (this.uninstallAdapterPatch) {
|
||||
this.uninstallAdapterPatch();
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
* or ciphertext integrity verification fails.
|
||||
*/
|
||||
|
||||
import { ItemView, Plugin, WorkspaceLeaf } from 'obsidian';
|
||||
import { ItemView, Plugin, WorkspaceLeaf, ViewStateResult } from 'obsidian';
|
||||
|
||||
/** Unique view type identifier for the encrypted file read-only view. */
|
||||
export const ENCRYPTED_FILE_VIEW_TYPE = 'encrypted-file-view';
|
||||
|
|
@ -79,7 +79,7 @@ export class EncryptedFileView extends ItemView {
|
|||
};
|
||||
}
|
||||
|
||||
async setState(state: Partial<EncryptedFileViewState>, result: any): Promise<void> {
|
||||
async setState(state: Partial<EncryptedFileViewState>, result: ViewStateResult): Promise<void> {
|
||||
if (state.filePath !== undefined) this.filePath = state.filePath;
|
||||
if (state.errorMessage !== undefined) this.errorMessage = state.errorMessage;
|
||||
if (state.rawContentBase64 !== undefined) this.rawContentBase64 = state.rawContentBase64;
|
||||
|
|
@ -191,8 +191,8 @@ export async function showEncryptedFileError(
|
|||
): Promise<void> {
|
||||
// Build error message with category if available (PluginError)
|
||||
let errorMessage: string;
|
||||
if ('category' in error && typeof (error as any).category === 'string') {
|
||||
errorMessage = `[${(error as any).category}] ${error.message}`;
|
||||
if ('category' in error && typeof (error as Record<string, unknown>).category === 'string') {
|
||||
errorMessage = `[${(error as Record<string, unknown>).category}] ${error.message}`;
|
||||
} else {
|
||||
errorMessage = error.message || 'Decryption failed';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ const encryptedPaths = new Set<string>();
|
|||
|
||||
export function installFileExplorerBadge(
|
||||
plugin: Plugin,
|
||||
originalReadBinary: (path: string) => Promise<ArrayBuffer>
|
||||
originalReadBinary: ((path: string) => Promise<ArrayBuffer>) | undefined
|
||||
): () => void {
|
||||
// Scan vault on layout ready
|
||||
plugin.app.workspace.onLayoutReady(async () => {
|
||||
|
|
@ -40,8 +40,9 @@ export function markFileDecrypted(filePath: string): void {
|
|||
|
||||
async function scanVaultForEncryptedFiles(
|
||||
plugin: Plugin,
|
||||
originalReadBinary: (path: string) => Promise<ArrayBuffer>
|
||||
originalReadBinary: ((path: string) => Promise<ArrayBuffer>) | undefined
|
||||
): Promise<void> {
|
||||
if (!originalReadBinary) return;
|
||||
const files = plugin.app.vault.getFiles();
|
||||
for (const file of files) {
|
||||
if (file.path.endsWith('.md')) continue;
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ export function installStatusBar(
|
|||
|
||||
// Check on click only (no periodic background checks)
|
||||
statusBarEl.addEventListener('click', () => {
|
||||
checkStatus();
|
||||
void checkStatus();
|
||||
});
|
||||
|
||||
// Initial check after layout ready
|
||||
|
|
|
|||
Loading…
Reference in a new issue