Skip to content

Commit

Permalink
fix: disable surfing tab tree by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Quorafind committed May 23, 2024
1 parent 2bf1dbb commit 32e2991
Show file tree
Hide file tree
Showing 7 changed files with 1,034 additions and 6 deletions.
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.11",
"version": "0.9.12",
"minAppVersion": "1.4.0",
"description": "Surf the Net in Obsidian.",
"author": "Boninall & Windily-cloud",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "surfing",
"version": "0.9.11",
"version": "0.9.12",
"description": "Use surfing to surf the net in Obsidian.",
"main": "main.js",
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions src/surfingIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class SurfingPlugin extends Plugin {

this.registerView(WEB_BROWSER_VIEW_ID, (leaf) => new SurfingView(leaf, this));
this.registerView(WEB_BROWSER_FILE_VIEW_ID, (leaf) => new SurfingFileView(leaf));
this.registerView(WEB_BROWSER_TAB_TREE_ID, (leaf) => new TabTreeView(leaf, this));
this.settings.enableTreeView && this.registerView(WEB_BROWSER_TAB_TREE_ID, (leaf) => new TabTreeView(leaf, this));
if (this.settings.bookmarkManager.openBookMark) this.registerView(WEB_BROWSER_BOOKMARK_MANAGER_ID, (leaf) => new SurfingBookmarkManagerView(leaf, this));

try {
Expand Down Expand Up @@ -101,7 +101,7 @@ export default class SurfingPlugin extends Plugin {
onunload() {
this.app.workspace.detachLeavesOfType(WEB_BROWSER_VIEW_ID);
this.app.workspace.detachLeavesOfType(WEB_BROWSER_BOOKMARK_MANAGER_ID);
this.app.workspace.detachLeavesOfType(WEB_BROWSER_TAB_TREE_ID);
this.settings.enableTreeView && this.app.workspace.detachLeavesOfType(WEB_BROWSER_TAB_TREE_ID);
this.app.workspace.offref(this.onLayoutChangeEventRef);

// Clean up header bar added to "New tab" views when plugin is disabled.
Expand All @@ -119,6 +119,7 @@ export default class SurfingPlugin extends Plugin {
}

onLayoutReady(): void {
if (!this.settings.enableTreeView) return;
if (this.app.workspace.getLeavesOfType(WEB_BROWSER_TAB_TREE_ID).length) {
return;
}
Expand Down
22 changes: 22 additions & 0 deletions src/surfingPluginSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface SurfingSettings {
treeData: NodeModel<CustomData>[];
enableHtmlPreview: boolean;
supportLivePreviewInlineUrl: boolean;
enableTreeView: boolean;
}

export interface SearchEngine {
Expand Down Expand Up @@ -121,6 +122,7 @@ export const DEFAULT_SETTINGS: SurfingSettings = {
treeData: [],
enableHtmlPreview: true,
supportLivePreviewInlineUrl: false,
enableTreeView: false,
};
// Add search engines here for the future used.
export const SEARCH_ENGINES: SearchEngine[] = [
Expand Down Expand Up @@ -391,6 +393,7 @@ export class SurfingSettingTab extends PluginSettingTab {
this.addOpenInSameTab(tabName, wbContainerEl);
this.addHoverPopover(tabName, wbContainerEl);
this.addEnableHTMLPreview(tabName, wbContainerEl);
this.addTreeView(tabName, wbContainerEl);
this.addInlinePreview(tabName, wbContainerEl);
this.addRefreshButton(tabName, wbContainerEl);
this.addHighlightFormat(tabName, wbContainerEl);
Expand Down Expand Up @@ -758,6 +761,25 @@ export class SurfingSettingTab extends PluginSettingTab {
this.addSettingToMasterSettingsList(tabName, setting.settingEl, settingName, settingDesc);
}

private addTreeView(tabName: string, wbContainerEl: HTMLElement) {
const settingName = t('Enable Tree View');
const settingDesc = t('Enable Tree View in Surfing');
const setting = new Setting(wbContainerEl)
.setName(settingName)
.setDesc(settingDesc)
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.enableTreeView)
.onChange(async (value) => {
this.plugin.settings.enableTreeView = value;
this.applySettingsUpdate();
});
});

this.addSettingToMasterSettingsList(tabName, setting.settingEl, settingName, settingDesc);

}

private addInlinePreview(tabName: string, wbContainerEl: HTMLElement) {
const settingName = t('Enable Inline Preview');
const settingDesc = t('Enable inline preview with surfing. Currently only support Live preview');
Expand Down
2 changes: 2 additions & 0 deletions src/translations/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@ export default {
'Show original url': 'Show original url',
'Enable Inline Preview': 'Enable Inline Preview',
'Enable inline preview with surfing. Currently only support Live preview': 'Enable inline preview with surfing. Currently only support Live preview',
'Enable Tree View in Surfing': 'Enable Tree View in Surfing',
'Enable Tree View': 'Enable Tree View',
};
Loading

0 comments on commit 32e2991

Please sign in to comment.