Skip to content

Commit

Permalink
fix: 修复插件更新逻辑 & 右键保存小记修复
Browse files Browse the repository at this point in the history
  • Loading branch information
moshangqi committed Aug 8, 2023
1 parent 9f5bacf commit a0e7fb3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
12 changes: 5 additions & 7 deletions src/pages/sandbox/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const App = () => {
setCurrentType(SELECT_TYPE_SELECTION);
}
});
}, [ currentType ]);
}, []);

const isLogined = account?.id;

Expand All @@ -189,18 +189,16 @@ const App = () => {
value={{ editorValue, currentType, setEditorValue, setCurrentType }}
>
<div className={styles.wrapper}>
{
account?.id
? <div className={styles.header}>{__i18n('语雀剪藏')}</div>
: null
}
{account?.id ? (
<div className={styles.header}>{__i18n('语雀剪藏')}</div>
) : null}
<CloseOutlined className={styles.close} onClick={onClose} />
<div className={classnames(styles.items, {
[styles.unlogin]: !isLogined,
})}>
{isLogined ? (
<>
<Radio.Group value={tab} onChange={handleTabChange} style={{ marginBottom: 16 }}>
<Radio.Group value={tab} onChange={handleTabChange} style={{ marginBottom: 16 }}>
<Radio.Button value="save-to">{__i18n('剪藏')}</Radio.Button>
<Radio.Button value="other">{__i18n('其他')}</Radio.Button>
</Radio.Group>
Expand Down
37 changes: 25 additions & 12 deletions src/pages/sandbox/CheckVersion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,38 @@ async function fetchAndParseXML(updateUrl: string): Promise<string | undefined>
export function useCheckVersion(): string | undefined {
const [ version, setVersion ] = useState<string | undefined>();

const fetchVersion = async () => {
fetchAndParseXML('https://app.nlark.com/yuque-chrome-extension/updates.xml')
.then(res => {
setVersion(res);
})
.catch(err => {
console.log(err, 'retrive update_url failed');
});
};

useEffect(() => {
const manifest = Chrome.runtime.getManifest();
if (process.env.NODE_ENV !== 'production') {
console.log('update_url: %s', manifest?.update_url);
}

if (manifest?.update_url) {
// 官方商店的 update_url 跳过更新检查
// https://clients2.google.com/service/update2/crx
// https://edge.microsoft.com/extensionwebstorebase/v1/crx
if (/(google|microsoft)\.com/.test(manifest.update_url)) {
return;
}

fetchAndParseXML(manifest.update_url).then(res => {
setVersion(res);
}).catch(err => {
console.log(err, 'retrive update_url failed');
});
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), 3000);
// 3s 没有请求成功判定为不能访问外网,走插件内更新逻辑
fetch(manifest.update_url, { signal: controller.signal })
.then(res => {
if (res.status !== 200) {
fetchVersion();
}
})
.catch(() => {
fetchVersion();
})
.finally(() => {
clearTimeout(id);
});
}
}, []);

Expand Down

0 comments on commit a0e7fb3

Please sign in to comment.