-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #218 from yuque/fix/update-for-reload
feat: 修复插件后台服务刷新问题
- Loading branch information
Showing
12 changed files
with
127 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* 后续所有环境判断的方法都迁移到这里来 | ||
*/ | ||
class Env { | ||
static get isBackground(): boolean { | ||
return typeof window === 'undefined'; | ||
} | ||
|
||
// 是否是插件的页面,插件的页面和 background 相类似,可以调用 chrome 系统的 api | ||
static get isExtensionPage() { | ||
if (!Env.isBackground) { | ||
const url = window.location.href; | ||
if (url.startsWith('chrome-extension://')) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
return true; | ||
} | ||
} | ||
|
||
export default Env; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { backgroundBridge } from '@/core/bridge/background'; | ||
import Env from './env'; | ||
|
||
class Storage { | ||
async update(key: string, data: any) { | ||
if (Env.isBackground) { | ||
const res = await chrome.storage.local.set({ | ||
[key]: data, | ||
}); | ||
return res; | ||
} | ||
const res = await backgroundBridge.storage.update(key, data); | ||
return res; | ||
} | ||
|
||
async remove(key: string) { | ||
if (Env.isBackground) { | ||
const res = await chrome.storage.local.remove(key); | ||
return res; | ||
} | ||
const res = await backgroundBridge.storage.remove(key); | ||
return res; | ||
} | ||
|
||
async get(key: string) { | ||
if (Env.isBackground) { | ||
const valueMap = await chrome.storage.local.get(key); | ||
return valueMap[key]; | ||
} | ||
const res = await backgroundBridge.storage.get(key); | ||
return res; | ||
} | ||
} | ||
|
||
export const storage = new Storage(); |