mirror of
https://github.com/philips/supernote-obsidian-plugin.git
synced 2026-07-22 09:50:25 +00:00
Squashed commit of the following:
commitaa38adaa89Author: The Phrench Frog <phrog123@icloud.com> Date: Sun Jan 26 01:10:43 2025 -0500 Delete src directory commit8277107e6fAuthor: The Phrench Frog <phrog123@icloud.com> Date: Sun Jan 26 00:49:15 2025 -0500 2.6.1 fixed commit06751f1ca1Author: The Phrench Frog <phrog123@icloud.com> Date: Sat Jan 25 23:33:56 2025 -0500 Add files via upload commita8fea95e68Author: The Phrench Frog <phrog123@icloud.com> Date: Sat Jan 25 23:28:30 2025 -0500 renamed .ts to .js why is brat now allowing for .ts files? commit9b71655e47Author: The Phrench Frog <phrog123@icloud.com> Date: Sat Jan 25 23:17:49 2025 -0500 Update Main.ts take 2 wrong character for ' commita0ca62c2aeAuthor: The Phrench Frog <phrog123@icloud.com> Date: Sat Jan 25 23:07:34 2025 -0500 Fix UI for 2.6.0 2.6.0 no longer uses Screen Mirroring but 'Browse and Access'.
This commit is contained in:
parent
5fc4afbf56
commit
e42b85d28e
3 changed files with 0 additions and 171 deletions
|
|
@ -1,122 +0,0 @@
|
|||
import { App, SuggestModal, Notice, MarkdownView } from 'obsidian';
|
||||
import { SupernotePluginSettings } from './main';
|
||||
|
||||
interface SupernoteFile {
|
||||
name: string;
|
||||
size: number;
|
||||
date: string;
|
||||
uri: string;
|
||||
extension: string;
|
||||
isDirectory: boolean;
|
||||
}
|
||||
|
||||
interface SupernoteResponse {
|
||||
deviceName: string;
|
||||
fileList: SupernoteFile[];
|
||||
routeList: { name: string; path: string; }[];
|
||||
totalByteSize: number;
|
||||
totalMemory: number;
|
||||
usedMemory: number;
|
||||
}
|
||||
|
||||
export class FileListModal extends SuggestModal<SupernoteFile> {
|
||||
settings: SupernotePluginSettings;
|
||||
files: SupernoteFile[] = [];
|
||||
currentPath: string = '/';
|
||||
|
||||
constructor(app: App, settings: SupernotePluginSettings) {
|
||||
super(app);
|
||||
this.settings = settings;
|
||||
this.setPlaceholder("Select a file to download or directory to open");
|
||||
}
|
||||
|
||||
private async loadFiles() {
|
||||
try {
|
||||
const response = await fetch(`http://${this.settings.mirrorIP}:8089${this.currentPath}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch file list: ${response.statusText}`);
|
||||
}
|
||||
const html = await response.text();
|
||||
|
||||
// Extract the JSON data from the script tag
|
||||
const match = html.match(/const json = '(.+?)'/);
|
||||
if (!match) {
|
||||
throw new Error("Could not find file list data");
|
||||
}
|
||||
|
||||
const data: SupernoteResponse = JSON.parse(match[1]);
|
||||
this.files = data.fileList;
|
||||
} catch (err) {
|
||||
new Notice(`Failed to load files: ${err.message}`);
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
||||
async getSuggestions(query: string): Promise<SupernoteFile[]> {
|
||||
if (this.files.length === 0) {
|
||||
await this.loadFiles();
|
||||
}
|
||||
return this.files.filter(file =>
|
||||
file.name.toLowerCase().includes(query.toLowerCase())
|
||||
);
|
||||
}
|
||||
|
||||
renderSuggestion(file: SupernoteFile, el: HTMLElement) {
|
||||
const container = el.createDiv({ cls: "suggestion-item" });
|
||||
|
||||
// Add directory icon or file icon
|
||||
const iconEl = container.createSpan({ cls: "suggestion-icon" });
|
||||
iconEl.textContent = file.isDirectory ? "📁" : "📄";
|
||||
|
||||
const contentEl = container.createDiv({ cls: "suggestion-content" });
|
||||
contentEl.createDiv({ text: file.name, cls: "suggestion-title" });
|
||||
|
||||
if (!file.isDirectory) {
|
||||
contentEl.createDiv({
|
||||
text: `${this.formatSize(file.size)} - ${file.date}`,
|
||||
cls: "suggestion-note"
|
||||
});
|
||||
} else {
|
||||
contentEl.createDiv({
|
||||
text: file.date,
|
||||
cls: "suggestion-note"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private formatSize(bytes: number): string {
|
||||
if (bytes < 1024) return bytes + ' B';
|
||||
if (bytes < 1048576) return (bytes / 1024).toFixed(2) + ' KB';
|
||||
if (bytes < 1073741824) return (bytes / 1048576).toFixed(2) + ' MB';
|
||||
return (bytes / 1073741824).toFixed(2) + ' GB';
|
||||
}
|
||||
|
||||
async onChooseSuggestion(file: SupernoteFile) {
|
||||
if (file.isDirectory) {
|
||||
// Navigate into directory
|
||||
this.currentPath = file.uri;
|
||||
await this.loadFiles();
|
||||
// Reopen the modal to show new directory contents
|
||||
this.open();
|
||||
} else {
|
||||
try {
|
||||
const fileResponse = await fetch(`http://${this.settings.mirrorIP}:8089${file.uri}`);
|
||||
if (!fileResponse.ok) {
|
||||
throw new Error(`Failed to download file: ${fileResponse.statusText}`);
|
||||
}
|
||||
|
||||
const buffer = await fileResponse.arrayBuffer();
|
||||
const filename = await this.app.fileManager.getAvailablePathForAttachment(file.name);
|
||||
const tfile = await this.app.vault.createBinary(filename, buffer);
|
||||
new Notice(`Downloaded ${file.name}`);
|
||||
const view = this.app.workspace.getActiveViewOfType(MarkdownView);
|
||||
if (view) {
|
||||
const link = this.app.fileManager.generateMarkdownLink(tfile, filename);
|
||||
view.editor.replaceSelection(link);
|
||||
}
|
||||
} catch (err) {
|
||||
new Notice(`Failed to download file: ${err.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
import { SupernoteX, toImage } from 'supernote-typescript';
|
||||
import { Image } from 'image-js'
|
||||
|
||||
export {};
|
||||
|
||||
export type SupernoteWorkerMessage = {
|
||||
type: 'convert';
|
||||
note: SupernoteX;
|
||||
pageNumbers?: number[];
|
||||
}
|
||||
|
||||
export type SupernoteWorkerResponse = {
|
||||
type: 'result';
|
||||
images: string[];
|
||||
error?: string;
|
||||
}
|
||||
|
||||
self.onmessage = async (e: MessageEvent<SupernoteWorkerMessage>) => {
|
||||
try {
|
||||
const { type, note, pageNumbers } = e.data;
|
||||
|
||||
if (type === 'convert') {
|
||||
const results = await toImage(note, pageNumbers);
|
||||
// Convert canvas/images to data URLs before sending
|
||||
const dataUrls = results.map(result => {
|
||||
if (result && typeof result.toDataURL === 'function') {
|
||||
return result.toDataURL();
|
||||
}
|
||||
console.error('Result is not a canvas or does not support toDataURL');
|
||||
return null;
|
||||
});
|
||||
|
||||
self.postMessage({
|
||||
type: 'result',
|
||||
images: dataUrls
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
self.postMessage({
|
||||
type: 'result',
|
||||
images: [],
|
||||
error: error instanceof Error ? error.message : 'Unknown error occurred'
|
||||
});
|
||||
}
|
||||
};
|
||||
4
src/worker.d.ts
vendored
4
src/worker.d.ts
vendored
|
|
@ -1,4 +0,0 @@
|
|||
declare module 'myworker.worker' {
|
||||
const WorkerFactory: new () => Worker;
|
||||
export default WorkerFactory;
|
||||
}
|
||||
Loading…
Reference in a new issue