mirror of
https://github.com/alberti42/obsidian-import-attachments-plus.git
synced 2026-07-22 10:10:24 +00:00
Extended plugin with revealing files.
This commit is contained in:
parent
e623f12aa0
commit
0bc8fd56b2
11 changed files with 1399 additions and 15 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -10,7 +10,7 @@ node_modules
|
|||
|
||||
# Don't include the compiled main.js file in the repo.
|
||||
# They should be uploaded to GitHub releases instead.
|
||||
main.js
|
||||
dist
|
||||
|
||||
# Exclude sourcemaps
|
||||
*.map
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import esbuild from "esbuild";
|
||||
import process from "process";
|
||||
import os from "os";
|
||||
import fs from "fs/promises";
|
||||
import builtins from "builtin-modules";
|
||||
import copy from 'esbuild-plugin-copy';
|
||||
|
||||
|
|
@ -30,9 +31,26 @@ const getOutDir = () => {
|
|||
}
|
||||
};
|
||||
|
||||
// Ensure the output directory exists
|
||||
const ensureOutDirExists = async (outdir) => {
|
||||
try {
|
||||
await fs.mkdir(outdir, { recursive: true });
|
||||
console.log(`Output directory created: ${outdir}`);
|
||||
} catch (err) {
|
||||
console.error(`Error creating output directory: ${err.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
// Determine whether to build for production or development
|
||||
const prod = (process.argv[2] === "production");
|
||||
|
||||
// Get the output directory
|
||||
const outdir = getOutDir();
|
||||
|
||||
// Create the output directory if it doesn't exist
|
||||
await ensureOutDirExists(outdir);
|
||||
|
||||
const context = await esbuild.context({
|
||||
banner: {
|
||||
js: banner,
|
||||
|
|
@ -60,7 +78,7 @@ const context = await esbuild.context({
|
|||
logLevel: "info",
|
||||
sourcemap: prod ? false : "inline",
|
||||
treeShaking: true,
|
||||
outdir: getOutDir(),
|
||||
outdir,
|
||||
plugins: [
|
||||
copy({
|
||||
assets: {
|
||||
|
|
|
|||
1357
src/main.js
Normal file
1357
src/main.js
Normal file
File diff suppressed because it is too large
Load diff
3
src/types.d.ts → src/obsidian-augment.d.ts
vendored
3
src/types.d.ts → src/obsidian-augment.d.ts
vendored
|
|
@ -1,6 +1,5 @@
|
|||
// types.d.ts
|
||||
// obsidian-augment.d.ts
|
||||
|
||||
// Extend the App interface to include openWithDefaultApp
|
||||
// declare module 'obsidian' {
|
||||
// interface App {
|
||||
// openWithDefaultApp(filePath: string): Promise<void>;
|
||||
|
|
@ -74,17 +74,12 @@ function patchOpenFile(plugin: ImportAttachments) {
|
|||
|
||||
// Monkey patch the openFile method
|
||||
WorkspaceLeaf.prototype.openFile = async function patchedOpenFile(this: WorkspaceLeaf, file: TFile, openState?: OpenViewState): Promise<void> {
|
||||
|
||||
|
||||
// console.log(`Meta key is pressed: ${metaKeyPressed}`);
|
||||
// console.log(`Alt key is pressed: ${altKeyPressed}`);
|
||||
|
||||
const newEmptyLeave = this.getViewState()?.type == 'empty';
|
||||
|
||||
if (newEmptyLeave) {
|
||||
// close prepared empty tab
|
||||
this.detach();
|
||||
}
|
||||
|
||||
if(metaKeyPressed){
|
||||
if(altKeyPressed){
|
||||
window.require('electron').remote.shell.showItemInFolder(path.join(plugin.vaultPath,file.path));
|
||||
|
|
@ -92,17 +87,18 @@ function patchOpenFile(plugin: ImportAttachments) {
|
|||
else {
|
||||
plugin.app.openWithDefaultApp(file.path);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(originalOpenFile) {
|
||||
return originalOpenFile.call(this, file, openState);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
if (newEmptyLeave) {
|
||||
// close prepared empty tab
|
||||
this.detach();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,6 +78,10 @@ export enum OverwriteChoiceOptions {
|
|||
SKIP,
|
||||
}
|
||||
|
||||
export interface App {
|
||||
openWithDefaultApp(filepath: string): Promise<void>;
|
||||
}
|
||||
|
||||
// Define a type for what resolveChoice will accept
|
||||
export type OverwriteChoiceResult = OverwriteChoiceOptions | null;
|
||||
|
||||
|
|
|
|||
0
src/global.d.ts → src/types/global.d.ts
vendored
0
src/global.d.ts → src/types/global.d.ts
vendored
9
src/types/obsidian-augment.d.ts
vendored
Normal file
9
src/types/obsidian-augment.d.ts
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// obsidian-augment.d.ts
|
||||
|
||||
import 'obsidian'
|
||||
|
||||
declare module 'obsidian' {
|
||||
interface App {
|
||||
openWithDefaultApp(filepath: string): Promise<void>;
|
||||
}
|
||||
}
|
||||
|
|
@ -19,7 +19,8 @@
|
|||
],
|
||||
//"jsx": "react-jsx", // Required by React
|
||||
},
|
||||
"typeRoots": ["./src/global"],
|
||||
|
||||
"typeRoots": ["./src/types","./node_modules/@types"],
|
||||
"include": [
|
||||
"./src/**/*.ts"
|
||||
]
|
||||
|
|
|
|||
Loading…
Reference in a new issue