mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 11:02:28 +08:00
chore(client/ts): port services/file_watcher
This commit is contained in:
parent
45a652828e
commit
6e8fa6d757
@ -50,6 +50,12 @@ export type TriggerData = {
|
|||||||
branchIdsToDelete: string[];
|
branchIdsToDelete: string[];
|
||||||
callback: (value: ResolveOptions) => void;
|
callback: (value: ResolveOptions) => void;
|
||||||
forceDeleteAllClones: boolean;
|
forceDeleteAllClones: boolean;
|
||||||
|
} | {
|
||||||
|
// For "openedFileUpdated"
|
||||||
|
entityType: string;
|
||||||
|
entityId: string;
|
||||||
|
lastModifiedMs: number;
|
||||||
|
filePath: string;
|
||||||
}
|
}
|
||||||
| PromptDialogOptions // For "showPromptDialog"
|
| PromptDialogOptions // For "showPromptDialog"
|
||||||
| ConfirmWithMessageOptions // For "showConfirmDialog"
|
| ConfirmWithMessageOptions // For "showConfirmDialog"
|
||||||
|
@ -1,36 +1,45 @@
|
|||||||
import ws from "./ws.js";
|
import ws from "./ws.js";
|
||||||
import appContext from "../components/app_context.js";
|
import appContext from "../components/app_context.js";
|
||||||
|
|
||||||
const fileModificationStatus = {
|
// TODO: Deduplicate
|
||||||
|
interface Message {
|
||||||
|
type: string;
|
||||||
|
entityType: string;
|
||||||
|
entityId: string;
|
||||||
|
lastModifiedMs: number;
|
||||||
|
filePath: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileModificationStatus: Record<string, Record<string, Message>> = {
|
||||||
notes: {},
|
notes: {},
|
||||||
attachments: {}
|
attachments: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
function checkType(type) {
|
function checkType(type: string) {
|
||||||
if (type !== 'notes' && type !== 'attachments') {
|
if (type !== 'notes' && type !== 'attachments') {
|
||||||
throw new Error(`Unrecognized type '${type}', should be 'notes' or 'attachments'`);
|
throw new Error(`Unrecognized type '${type}', should be 'notes' or 'attachments'`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFileModificationStatus(entityType, entityId) {
|
function getFileModificationStatus(entityType: string, entityId: string) {
|
||||||
checkType(entityType);
|
checkType(entityType);
|
||||||
|
|
||||||
return fileModificationStatus[entityType][entityId];
|
return fileModificationStatus[entityType][entityId];
|
||||||
}
|
}
|
||||||
|
|
||||||
function fileModificationUploaded(entityType, entityId) {
|
function fileModificationUploaded(entityType: string, entityId: string) {
|
||||||
checkType(entityType);
|
checkType(entityType);
|
||||||
|
|
||||||
delete fileModificationStatus[entityType][entityId];
|
delete fileModificationStatus[entityType][entityId];
|
||||||
}
|
}
|
||||||
|
|
||||||
function ignoreModification(entityType, entityId) {
|
function ignoreModification(entityType: string, entityId: string) {
|
||||||
checkType(entityType);
|
checkType(entityType);
|
||||||
|
|
||||||
delete fileModificationStatus[entityType][entityId];
|
delete fileModificationStatus[entityType][entityId];
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.subscribeToMessages(async message => {
|
ws.subscribeToMessages(async (message: Message) => {
|
||||||
if (message.type !== 'openedFileUpdated') {
|
if (message.type !== 'openedFileUpdated') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user