Skip to content

Commit

Permalink
修复每次启动都自动打开市场的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cumany committed Apr 1, 2024
1 parent 7da1559 commit 7c7d238
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 40 deletions.
27 changes: 14 additions & 13 deletions src/components/plugin/PluginMarket.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,20 @@ const extractCategoryFromHash = () => {
}
}
const pkmerSize = ref()
const ele = ref<HTMLElement | null>(null)
onMounted(async () => {
isClose.value = false
extractCategoryFromHash() // 初始化时提取分类名称
await loadAllPlugins()
sortBy.value = "pkmerDownloadCount"
sortOrder.value = "asc"
ele.value = document.querySelector(
'.workspace-leaf-content[data-type="pkmer-downloader"]'
) as HTMLElement
ele.value && resizeObserver.observe(ele.value)
window.addEventListener("resize", handleWindowResize)
handleWindowResize()
// ele.value = document.querySelector(
// '.workspace-leaf-content[data-type="pkmer-downloader"]'
// ) as HTMLElement
app.workspace.on("resize", handleWindowResize)
pkmerSize.value = props.app.workspace.activeLeaf.view.leaf.width

Check failure on line 208 in src/components/plugin/PluginMarket.vue

View workflow job for this annotation

GitHub Actions / build

'props.app.workspace.activeLeaf' is possibly 'null'.

Check failure on line 208 in src/components/plugin/PluginMarket.vue

View workflow job for this annotation

GitHub Actions / build

Property 'width' does not exist on type 'WorkspaceLeaf'.
// ele.value && resizeObserver.observe(ele.value)
// window.addEventListener("resize", handleWindowResize)
// handleWindowResize()
// 解析 JSON 字符串为 JavaScript 对象
if (props.tab) {
const parsedData = JSON.parse(props.tab)
Expand All @@ -217,17 +218,17 @@ onMounted(async () => {
})
const handleWindowResize = () => {
pkmerSize.value = ele.value && ele.value?.offsetWidth
pkmerSize.value = props.app.workspace.activeLeaf.view.leaf.width

Check failure on line 221 in src/components/plugin/PluginMarket.vue

View workflow job for this annotation

GitHub Actions / build

'props.app.workspace.activeLeaf' is possibly 'null'.

Check failure on line 221 in src/components/plugin/PluginMarket.vue

View workflow job for this annotation

GitHub Actions / build

Property 'width' does not exist on type 'WorkspaceLeaf'.
}
onUnmounted(() => {
ele.value && resizeObserver.unobserve(ele.value)
window.removeEventListener("resize", handleWindowResize)
// ele.value && resizeObserver.unobserve(ele.value)
// window.removeEventListener("resize", handleWindowResize)
localStorage.removeItem("pkmer-update-tab")
})
const resizeObserver = new ResizeObserver(() => {
handleWindowResize()
})
// const resizeObserver = new ResizeObserver(() => {
// handleWindowResize()
// })
const handleSetSearchText = (event: any) => {
debounce(() => {
Expand Down
20 changes: 8 additions & 12 deletions src/components/theme/ThemeMarket.vue
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,18 @@ const extractCategoryFromHash = () => {
}
}
const pkmerSize = ref()
const ele = ref<HTMLElement | null>(null)
onMounted(async () => {
extractCategoryFromHash() // 初始化时提取分类名称
await loadAllThemes()
sortBy.value = "pkmerDownloadCount"
sortOrder.value = "asc"
ele.value = document.querySelector(
'.workspace-leaf-content[data-type="pkmer-downloader"]'
) as HTMLElement
ele.value && resizeObserver.observe(ele.value)
window.addEventListener("resize", handleWindowResize)
handleWindowResize()
// ele.value = document.querySelector(
// '.workspace-leaf-content[data-type="pkmer-downloader"]'
// ) as HTMLElement
app.workspace.on("resize", handleWindowResize)
pkmerSize.value = props.app.workspace.activeLeaf.view.leaf.width

Check failure on line 219 in src/components/theme/ThemeMarket.vue

View workflow job for this annotation

GitHub Actions / build

'props.app.workspace.activeLeaf' is possibly 'null'.

Check failure on line 219 in src/components/theme/ThemeMarket.vue

View workflow job for this annotation

GitHub Actions / build

Property 'width' does not exist on type 'WorkspaceLeaf'.
if (isUserLogin) downloadCount.value = await api.getDownloadCount()
if (props.tab) {
Expand All @@ -227,16 +227,12 @@ onMounted(async () => {
}
})
const handleWindowResize = () => {
pkmerSize.value = ele.value && ele.value?.offsetWidth
pkmerSize.value = props.app.workspace.activeLeaf.view.leaf.width

Check failure on line 230 in src/components/theme/ThemeMarket.vue

View workflow job for this annotation

GitHub Actions / build

'props.app.workspace.activeLeaf' is possibly 'null'.

Check failure on line 230 in src/components/theme/ThemeMarket.vue

View workflow job for this annotation

GitHub Actions / build

Property 'width' does not exist on type 'WorkspaceLeaf'.
}
onUnmounted(() => {
ele.value && resizeObserver.unobserve(ele.value)
window.removeEventListener("resize", handleWindowResize)
})
const resizeObserver = new ResizeObserver(() => {
handleWindowResize()
})
const filteredList = computed<ThemeInfo[]>(() => {
const searchText = searchTextRef.value.toLowerCase().trim() // 将搜索关键字转为小写
Expand Down
25 changes: 15 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: cumany [email protected]
* @Date: 2023-07-26 16:57:16
* @LastEditors: cumany [email protected]
* @LastEditTime: 2024-03-27 14:27:56
* @LastEditTime: 2024-04-01 18:22:30
* @Description:
*/
import { Notice, Plugin, } from "obsidian"
Expand All @@ -13,7 +13,7 @@ import PluginProcessor from "@/utils/downloader"
import ThemeProcessor from "@/utils/tdownloader"
import PluginStatistics from "@/utils/pluginstatistics"
import ThemeStatistics from "@/utils/themestatistics"

export interface PkmerSettings {
token: string
}
Expand All @@ -40,7 +40,7 @@ export default class PkmerPlugin extends Plugin {
)
// 监听自定义事件
addEventListener("reload-statusbar", async () => {
this.reloadStatusBarHandler();
this.reloadStatusBarHandler();
})
}
reloadStatusBarHandler = async () => {
Expand Down Expand Up @@ -119,13 +119,16 @@ export default class PkmerPlugin extends Plugin {
id: "open-pkmer-market-view",
name: "Open Pkmer Market View",
callback: () => {


this.openView('')
}
})
}

private registerCustomRibbon() {
this.addRibbonIcon("download", "Open Pkmer Market", () => {

this.openView('');
})
}
Expand All @@ -138,6 +141,7 @@ export default class PkmerPlugin extends Plugin {
// 注册点击事件,并使用防抖函数作为处理程序
this.registerDomEvent(this.statusBarIconEl, "click", () => {


this.updateStatusBar("statusbar")
})
}
Expand All @@ -162,6 +166,7 @@ export default class PkmerPlugin extends Plugin {
type: "updated",
count: updatedCount
};

this.openView(JSON.stringify(data))
}

Expand All @@ -170,21 +175,21 @@ export default class PkmerPlugin extends Plugin {
type: "tupdated",
count: tupdatedCount
};

this.openView(JSON.stringify(data))

}
} else
this.openView('');
} else
{
}
} else {
this.statusBarIconEl.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-rocket"><path d="M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z"/><path d="m12 15-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z"/><path d="M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"/><path d="M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"/></svg>`
this.statusBarIconEl.setAttribute("aria-label", "Updated Info: Plugins: " + updatedCount + "/" + installedCount + ", Themes: " + tupdatedCount + "/" + tinstalledCount);
this.openView('')
if (event === "statusbar")
this.openView('');
}


}
private openView(state: string) {
openView(state: string) {
let pkmerDownloaderFound = false;

app.workspace.iterateAllLeaves((leaf) => {
Expand Down
6 changes: 3 additions & 3 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
* @Author: cumany [email protected]
* @Date: 2023-07-24 16:35:56
* @LastEditors: cumany [email protected]
* @LastEditTime: 2023-12-06 11:12:00
* @LastEditTime: 2024-04-01 18:17:35
* @Description:
*/
import PkmerLoginModal from "./components/login/PkmerLoginModal";
import PkmerPlugin from "./main";
import { App, PluginSettingTab, Setting, Platform } from "obsidian";
import { DEFAULT_VIEW_TYPE } from "./views/PluginMarket";
export class PkmerSettingTab extends PluginSettingTab {
plugin: PkmerPlugin;

Expand Down Expand Up @@ -74,7 +73,8 @@ export class PkmerSettingTab extends PluginSettingTab {
.onClick(() => {
app.setting.close();
setTimeout(() => {
this.app.workspace.getLeaf().setViewState({ active: true, type: DEFAULT_VIEW_TYPE });

this.plugin.openView("");
}, 100);
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/views/PluginMarket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: cumany [email protected]
* @Date: 2023-07-23 17:35:33
* @LastEditors: cumany [email protected]
* @LastEditTime: 2024-03-26 12:21:11
* @LastEditTime: 2024-04-01 11:34:47
* @Description:
*/
import { ItemView, WorkspaceLeaf } from "obsidian"
Expand Down Expand Up @@ -43,7 +43,7 @@ export class PkmderDownloaderView extends ItemView {

async onOpen() {
const { contentEl } = this

console.log("welcome Pkmer Market")
const pluginMarketApp = createApp(PluginMarketView, {
settings: this.settings,
app: this.app,
Expand Down

0 comments on commit 7c7d238

Please sign in to comment.