Skip to content

Commit

Permalink
Refactor webtag webviewcontents (#288)
Browse files Browse the repository at this point in the history
* fix: all app issues related new version api

* chore: bump version
  • Loading branch information
Quorafind authored Nov 9, 2024
1 parent 32e2991 commit 714c106
Show file tree
Hide file tree
Showing 36 changed files with 2,726 additions and 2,341 deletions.
8 changes: 6 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"no-prototype-builtins": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"no-useless-escape": "off"
"no-useless-escape": "off",
"no-unexpected-multiline": "off",
"no-mixed-spaces-and-tabs": "off",

"@typescript-eslint/no-this-alias": "off"
}
}
}
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
. "$(dirname -- "$0")/_/husky.sh"

npm run lint:fix
tsc -noEmit -skipLibCheck
npm run type-check
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ the current browser URL within Obsidain.

## Installation

- Not ready for market yet
- Search `Surfing` in the Obsidian Community Plugin marketplace.
- Can be installed via the [Brat](https://github.com/TfTHacker/obsidian42-brat) plugin
- Manual installation

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "surfing",
"name": "Surfing",
"version": "0.9.12",
"version": "0.9.13",
"minAppVersion": "1.4.0",
"description": "Surf the Net in Obsidian.",
"author": "Boninall & Windily-cloud",
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "surfing",
"version": "0.9.12",
"version": "0.9.13",
"description": "Use surfing to surf the net in Obsidian.",
"main": "main.js",
"scripts": {
Expand All @@ -10,7 +10,8 @@
"build": "vite build",
"version": "node version-bump.mjs && git add manifest.json versions.json",
"lint:fix": "eslint --fix . --ext .ts",
"prepare": "husky install"
"prepare": "husky install",
"type-check": "tsc -noEmit -skipLibCheck"
},
"keywords": [],
"author": "Boninall & Windily-cloud",
Expand All @@ -35,12 +36,12 @@
"@vitejs/plugin-react": "^4.2.1",
"antd": "^5.0.5",
"builtin-modules": "3.3.0",
"electron": "^21.0.1",
"electron": "^32.2.0",
"eslint": "^8.28.0",
"eslint-plugin-import": "^2.26.0",
"husky": "^8.0.0",
"husky": "^9.1.6",
"monkey-around": "^2.3.0",
"obsidian": "1.4.11",
"obsidian": "latest",
"react": "^18.2.0",
"react-dnd": "^16.0.1",
"react-dom": "^18.2.0",
Expand Down
16 changes: 8 additions & 8 deletions src/component/BookMarkBar/BookMarkBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ export class BookMarkBar {
this.renderIcon();

try {
const { bookmarks, categories } = await loadJson();
const { bookmarks, categories } = await loadJson(this.plugin);
this.bookmarkData = bookmarks;
this.categoryData = categories;
} catch (e) {
if (this.bookmarkData?.length === 0 || !this.bookmarkData) {
await initializeJson();
const { bookmarks, categories } = await loadJson();
await initializeJson(this.plugin);
const { bookmarks, categories } = await loadJson(this.plugin);
this.bookmarkData = bookmarks;
this.categoryData = categories;
}
Expand All @@ -52,7 +52,7 @@ export class BookMarkBar {
})

bookmarkManagerEl.onclick = async () => {
const workspace = app.workspace;
const workspace = this.plugin.app.workspace;
workspace.detachLeavesOfType(WEB_BROWSER_BOOKMARK_MANAGER_ID);
await workspace.getLeaf(false).setViewState({ type: WEB_BROWSER_BOOKMARK_MANAGER_ID });
workspace.revealLeaf(workspace.getLeavesOfType(WEB_BROWSER_BOOKMARK_MANAGER_ID)[0]);
Expand All @@ -79,22 +79,22 @@ export class BookMarkBar {
}
}

export const updateBookmarkBar = (bookmarks: Bookmark[], categories: CategoryType[], refreshBookmarkManager: boolean) => {
export const updateBookmarkBar = (plugin: SurfingPlugin, bookmarks: Bookmark[], categories: CategoryType[], refreshBookmarkManager: boolean) => {
if (refreshBookmarkManager) {
const currentBookmarkLeaves = app.workspace.getLeavesOfType("surfing-bookmark-manager");
const currentBookmarkLeaves = plugin.app.workspace.getLeavesOfType("surfing-bookmark-manager");
if (currentBookmarkLeaves.length > 0) {
currentBookmarkLeaves[0].rebuildView();
}
}

const emptyLeaves = app.workspace.getLeavesOfType("empty");
const emptyLeaves = plugin.app.workspace.getLeavesOfType("empty");
if (emptyLeaves.length > 0) {
emptyLeaves.forEach((leaf) => {
leaf.rebuildView();
})
}

const surfingLeaves = app.workspace.getLeavesOfType("surfing-view");
const surfingLeaves = plugin.app.workspace.getLeavesOfType("surfing-view");
if (surfingLeaves.length > 0) {
surfingLeaves.forEach((leaf) => {
// @ts-ignore
Expand Down
12 changes: 6 additions & 6 deletions src/component/BookMarkBar/BookMarkItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export class BookMarkItem {
window.open(bookmarkItem.url, "_blank", "external");
return;
}
if (!e.ctrlKey && !e.metaKey) SurfingView.spawnWebBrowserView(false, { url: bookmarkItem.url });
else SurfingView.spawnWebBrowserView(true, { url: bookmarkItem.url });
if (!e.ctrlKey && !e.metaKey) SurfingView.spawnWebBrowserView(this.plugin, false, { url: bookmarkItem.url });
else SurfingView.spawnWebBrowserView(this.plugin, true, { url: bookmarkItem.url });
})
});
});
Expand All @@ -113,8 +113,8 @@ export class BookMarkItem {
window.open(bookmarkItem.url, "_blank", "external");
return;
}
if (!e.ctrlKey && !e.metaKey) SurfingView.spawnWebBrowserView(false, { url: bookmarkItem.url });
else SurfingView.spawnWebBrowserView(true, { url: bookmarkItem.url });
if (!e.ctrlKey && !e.metaKey) SurfingView.spawnWebBrowserView(this.plugin, false, { url: bookmarkItem.url });
else SurfingView.spawnWebBrowserView(this.plugin, true, { url: bookmarkItem.url });
})
});
});
Expand Down Expand Up @@ -145,8 +145,8 @@ export class BookMarkItem {
window.open(bookmarkItem.url, "", "external");
return;
}
if (!e.ctrlKey && !e.metaKey) SurfingView.spawnWebBrowserView(false, { url: bookmarkItem.url });
else SurfingView.spawnWebBrowserView(true, { url: bookmarkItem.url });
if (!e.ctrlKey && !e.metaKey) SurfingView.spawnWebBrowserView(this.plugin, false, { url: bookmarkItem.url });
else SurfingView.spawnWebBrowserView(this.plugin, true, { url: bookmarkItem.url });
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/component/BookmarkManager/BookmarkImporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const BookmarkImporter: any = (Props: Props): any => {
const regex = /<DT><A HREF="(.*?)"\s*ADD_DATE="(.*?)".*?>(.*)<\/A>/gm;
let bookmarkData;

const {bookmarks, categories} = await loadJson();
const {bookmarks, categories} = await loadJson(this.plugin);

while ((bookmarkData = regex.exec(result)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
Expand Down Expand Up @@ -80,7 +80,7 @@ const BookmarkImporter: any = (Props: Props): any => {
}
}

await saveJson({
await saveJson(this.plugin, {
bookmarks,
categories,
});
Expand Down
16 changes: 8 additions & 8 deletions src/component/BookmarkManager/BookmarkManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default function BookmarkManager(props: Props) {
window.open(record.url, "_blank", "external");
return;
}
SurfingView.spawnWebBrowserView(true, {
SurfingView.spawnWebBrowserView(props.plugin, true, {
url: record.url,
});
}}
Expand Down Expand Up @@ -284,7 +284,7 @@ export default function BookmarkManager(props: Props) {
setCategories(tempCategories);

if (tempCategories) {
saveJson({
saveJson(props.plugin, {
bookmarks: bookmarks,
categories: tempCategories,
});
Expand Down Expand Up @@ -331,12 +331,12 @@ export default function BookmarkManager(props: Props) {

setBookmarks(newBookmarks.filter((bookmark) => bookmark.id !== oldBookmark.id));

await saveJson({
await saveJson(props.plugin, {
bookmarks: bookmarksRef.current,
categories: props.categories,
});

updateBookmarkBar(bookmarksRef.current, props.categories, false);
updateBookmarkBar(props.plugin, bookmarksRef.current, props.categories, false);
};

const handleImportFinished = async (importedBookmarks: Bookmark[]): Promise<void> => {
Expand Down Expand Up @@ -377,12 +377,12 @@ export default function BookmarkManager(props: Props) {
setModalVisible(false);
}

await saveJson({
await saveJson(props.plugin, {
bookmarks: bookmarks,
categories: props.categories,
});

updateBookmarkBar(bookmarks, props.categories, false);
updateBookmarkBar(props.plugin, bookmarks, props.categories, false);
};

const importProps = {
Expand All @@ -391,10 +391,10 @@ export default function BookmarkManager(props: Props) {

return (
<div className="surfing-bookmark-manager">
<ConfigProvider
<ConfigProvider
theme={{
algorithm:
app.getTheme() === "obsidian"
props.plugin.app.getTheme() === "obsidian"
? theme.darkAlgorithm
: theme.defaultAlgorithm,
}}
Expand Down
Loading

0 comments on commit 714c106

Please sign in to comment.