Skip to content

Commit

Permalink
add t3 worker stop logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiram committed Mar 23, 2024
1 parent 5fcaf84 commit a74fe15
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/renderer/src/pages/Film.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ import { onMounted, reactive, ref } from 'vue';
import { usePlayStore } from '@/store';
import { fetchSiteActive } from '@/api/site';
import { fetchClassify, fetchList, fetchSearch, fetchDetail, t3RuleInit, catvodRuleInit } from '@/utils/cms';
import { fetchClassify, fetchList, fetchSearch, fetchDetail, t3RuleInit, t3RuleTerminate, catvodRuleInit } from '@/utils/cms';
import { getConfig } from '@/utils/tool';
import DetailView from './film/Detail.vue';
Expand Down Expand Up @@ -557,6 +557,7 @@ const changeSitesEvent = async (key: string) => {
isVisible.infiniteLoading = true;
isVisible.loadClass = false;
isVisible.t3Work = false;
if (siteConfig.value.default.type === 8) await t3RuleTerminate();
isVisible.catvod = false;
infiniteCompleteTip.value = '没有更多内容了!';
searchTxt.value = '';
Expand Down Expand Up @@ -621,6 +622,7 @@ filmSearcheventBus.on((kw: string)=>{
filmReloadeventBus.on(async () => {
isVisible.loadClass = false;
isVisible.t3Work = false;
if (siteConfig.value.default.type === 8) await t3RuleTerminate();
isVisible.catvod = false;
infiniteCompleteTip.value = '没有更多内容了!';
searchTxt.value = '';
Expand Down
9 changes: 8 additions & 1 deletion src/renderer/src/utils/cms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Base64 from 'crypto-js/enc-base64';
import xpath from 'xpath';
import { DOMParser } from '@xmldom/xmldom';

import t3Work from './drpy';
import { doWork as t3Work, terminateWork as t3WorkTerminate } from './drpy';
import CLASS_FILTER_CONFIG from '@/config/appFilter';


Expand Down Expand Up @@ -96,6 +96,12 @@ const t3RuleInit = async(rule: string) => {
return res.data;
}

const t3RuleTerminate = async() => {
const res = await t3WorkTerminate();
if (res.code === 200) return 'sucess'
else return 'fail';
}

const catvodRuleInit = async(api, rule: string) => {
const url = buildUrl(api, `/init`);
const res = await axios({
Expand Down Expand Up @@ -1001,6 +1007,7 @@ const fetchDoubanRecommend = async(id, name, year) => {

export {
t3RuleInit,
t3RuleTerminate,
catvodRuleInit,
checkValid,
fetchClassify,
Expand Down
19 changes: 18 additions & 1 deletion src/renderer/src/utils/drpy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,21 @@ const doWork = (data) => {
});
}

export default doWork;
const terminateWork = () => {
return new Promise((resolve, reject) => {
if (typeof worker !== 'undefined' && worker !== null) {
worker.terminate();
resolve({
msg: 'Worker terminated successfully.',
code: 200
});
} else {
reject({
msg: new Error('Worker is not defined or already terminated.'),
code: 200
});
}
});
};

export { doWork, terminateWork };

0 comments on commit a74fe15

Please sign in to comment.