Skip to content

Commit

Permalink
Add Arc installation check
Browse files Browse the repository at this point in the history
A function "isArcInstalled" has been introduced which checks if Arc is installed before attempting to fetch and display tabs. This prevents potential errors and mishandling when Arc isn't installed.
  • Loading branch information
qianlifeng committed May 21, 2024
1 parent 67a29c9 commit e15618b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wox.plugin.arc",
"version": "0.0.2",
"version": "0.0.3",
"scripts": {
"build": "pnpm clean && ncc build src/index.ts -o dist && babel dist --out-dir dist && cp -r images dist && cp -r plugin.json dist",
"package": "pnpm build && cd dist && zip -r ../wox.plugin.arc.wox *.js *.json images",
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Name": "Arc",
"Description": "Search arc tabs and spaces",
"Author": "Wox-team",
"Version": "0.0.2",
"Version": "0.0.3",
"MinWoxVersion": "2.0.0",
"Runtime": "nodejs",
"Website": "https://github.com/Wox-launcher/Wox.Plugin.Arc",
Expand Down
9 changes: 9 additions & 0 deletions src/arc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,12 @@ export async function getVersion() {

return response
}

export async function isArcInstalled() {
try {
await getVersion()
return true
} catch (error) {
return false
}
}
16 changes: 10 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Context, Plugin, PluginInitParams, PublicAPI, Query, Result } from "@wox-launcher/wox-plugin"
import { getTabs, selectTab } from "./arc"
import { getTabs, isArcInstalled, selectTab } from "./arc"
import { Tab } from "./types"

let api: PublicAPI
Expand All @@ -10,12 +10,16 @@ export const plugin: Plugin = {
api = initParams.API

setInterval(async () => {
const openTabs = await getTabs()
if (openTabs == undefined) {
return
}
if (await isArcInstalled()) {
const openTabs = await getTabs()
if (openTabs == undefined) {
return
}

tabs = openTabs
tabs = openTabs
} else {
tabs = []
}
}, 2000)
},

Expand Down

0 comments on commit e15618b

Please sign in to comment.