Skip to content

Commit 93737bb

Browse files
committed
fix(types,e2e): adapt to obsidian 1.13 typings and 1.12.7 protocol registry
- Plugin.settings is now declared on the base class: mark ours override - DataAdapter.appendBinary is public in API 1.13, but minAppVersion predates it, so BinaryAppendAdapter re-declares it optional via Omit and keeps the runtime guard - Obsidian 1.12.7 replaced app.workspace.protocolHandlers (Map) with app.workspace.protocolHandler.handlers: e2e harness and tests now accept both shapes
1 parent dabebd5 commit 93737bb

4 files changed

Lines changed: 12 additions & 13 deletions

File tree

src/download/streaming.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ function tooLargeError(maxSize: number): Error {
4343
);
4444
}
4545

46-
// Obsidian's DataAdapter — writeBinary/rename/remove/list, all used below — is
47-
// fully typed and public. Only `appendBinary` exists at runtime on the desktop and
48-
// mobile Capacitor adapters without appearing in the public typings, so we extend
49-
// the real interface with that single bolt-on and keep one cast (appendableAdapter).
50-
export interface BinaryAppendAdapter extends DataAdapter {
46+
// Obsidian's DataAdapter typings declare `appendBinary` as always present
47+
// (public since API 1.13), but our minAppVersion predates its availability,
48+
// so we re-declare it as optional and runtime-guard every call site.
49+
export interface BinaryAppendAdapter
50+
extends Omit<DataAdapter, "appendBinary"> {
5151
appendBinary?(path: string, data: ArrayBuffer): Promise<void>;
5252
}
5353

@@ -58,10 +58,9 @@ export interface RangeProbe {
5858
totalSize: number | null;
5959
}
6060

61-
// `appendBinary` exists at runtime on the mobile CapacitorAdapter (and the
62-
// desktop adapter) but isn't in Obsidian's public DataAdapter typings. Keep the
63-
// single unsafe cast here so the "where we step outside the types" boundary is
64-
// greppable in one place.
61+
// Keep the single unsafe cast here so the "where we step outside the types"
62+
// boundary is greppable in one place: the cast widens `appendBinary` back to
63+
// optional for Obsidian runtimes older than API 1.13.
6564
export function appendableAdapter(): BinaryAppendAdapter {
6665
return get(plugin).app.vault.adapter as unknown as BinaryAppendAdapter;
6766
}

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type MediaSessionActionName =
6565

6666
export default class PodNotes extends Plugin implements IPodNotes {
6767
public api!: IAPI;
68-
public settings!: IPodNotesSettings;
68+
public override settings!: IPodNotesSettings;
6969
public override app!: PartialAppExtension;
7070

7171
private views = new Set<MainView>();

tests/e2e/harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export async function waitForPodNotesReady(
211211
return await obsidian.dev.evalJson<boolean>(`
212212
Boolean(
213213
app.plugins.plugins.${PLUGIN_ID}?.api &&
214-
app.workspace.protocolHandlers?.has(${JSON.stringify(PLUGIN_ID)})
214+
(app.workspace.protocolHandlers ?? app.workspace.protocolHandler?.handlers)?.has(${JSON.stringify(PLUGIN_ID)})
215215
)
216216
`);
217217
},

tests/e2e/podnotes-runtime.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe("PodNotes runtime", () => {
5050
typeof app.commands?.commands?.[${JSON.stringify(`${PLUGIN_ID}:capture-timestamp`)}]?.editorCheckCallback === "function",
5151
hasCaptureSegment10Command: Boolean(app.commands?.commands?.[${JSON.stringify(`${PLUGIN_ID}:capture-segment-10s`)}]),
5252
hasCaptureSegment20Command: Boolean(app.commands?.commands?.[${JSON.stringify(`${PLUGIN_ID}:capture-segment-20s`)}]),
53-
hasProtocolHandler: app.workspace.protocolHandlers?.has(${JSON.stringify(PLUGIN_ID)}) ?? false,
53+
hasProtocolHandler: (app.workspace.protocolHandlers ?? app.workspace.protocolHandler?.handlers)?.has(${JSON.stringify(PLUGIN_ID)}) ?? false,
5454
hasRateCommands: [
5555
${JSON.stringify(`${PLUGIN_ID}:increase-playback-rate`)},
5656
${JSON.stringify(`${PLUGIN_ID}:decrease-playback-rate`)},
@@ -623,7 +623,7 @@ async function invokePodNotesUri(
623623
obsidian,
624624
`
625625
(async () => {
626-
const handler = app.workspace.protocolHandlers.get(${JSON.stringify(PLUGIN_ID)});
626+
const handler = (app.workspace.protocolHandlers ?? app.workspace.protocolHandler?.handlers).get(${JSON.stringify(PLUGIN_ID)});
627627
if (!handler) {
628628
return { ok: false, error: "PodNotes protocol handler is not registered." };
629629
}

0 commit comments

Comments
 (0)