Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

Commit

Permalink
chore: @gkd-kit/api
Browse files Browse the repository at this point in the history
  • Loading branch information
AIsouler committed Mar 5, 2024
1 parent 31c13ed commit 46d3cc2
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 626 deletions.
2 changes: 1 addition & 1 deletion scripts/updateSubs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'node:fs/promises';
import url from 'node:url';
import type { RawApp } from '../src/types';
import type { RawApp } from '@gkd-kit/api';
import { tryRun } from '../src/utils';

// 使用命令更新内存订阅
Expand Down
2 changes: 1 addition & 1 deletion src/categories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RawCategory } from './types';
import type { RawCategory } from '@gkd-kit/api';

const categories: RawCategory[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import categories from './categories';
import globalGroups from './globalGroups';
import apps from './rawApps';
import type { RawSubscription } from './types';
import type { RawSubscription } from '@gkd-kit/api';

const subsConfig: RawSubscription = {
id: 666,
Expand Down
10 changes: 5 additions & 5 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import fs from 'node:fs/promises';
import path from 'node:path';
import type PkgT from '../package.json';
import { parseSelector } from './selector';
import type { RawAppAddProp } from './types';
import type {
RawApp,
RawAppGroup,
RawGlobalGroup,
IArray,
RawSubscription,
} from './types';
} from '@gkd-kit/api';
import JSON5 from 'json5';

// 定义一个将 IArray<T> 类型转换为 T[] 类型的函数
Expand Down Expand Up @@ -206,7 +206,7 @@ export const checkConfig = (newConfig: RawSubscription) => {

// 检查组和规则的重复键
const apps = newConfig.apps || [];
apps.forEach((app) => {
apps.forEach((app: RawAppAddProp) => {
const deprecatedKeys = app.deprecatedKeys || [];
const keys = new Set<number>();
const oldGroups = oldConfig.apps?.find((a) => a.id == app.id)?.groups || [];
Expand Down Expand Up @@ -377,7 +377,7 @@ export const checkAndDeleteFiles = async (): Promise<void> => {
};

// 导出一个异步函数,用于更新应用的 Markdown 文件
export const updateAppMd = async (app: RawApp) => {
export const updateAppMd = async (app: RawAppAddProp) => {
// 生成应用的 Markdown 文本内容
const appHeadMdText = [
`# ${app.name}`,
Expand Down Expand Up @@ -509,7 +509,7 @@ const getGlobalDiffLog = (

// 定义一个类型,表示应用的变更日志
type AppDiff = {
app: RawApp;
app: RawAppAddProp;
addGroups: RawAppGroup[];
changeGroups: RawAppGroup[];
removeGroups: RawAppGroup[];
Expand Down
10 changes: 9 additions & 1 deletion src/globalGroups.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import apps from './rawApps';
import type { RawGlobalGroup } from './types';
import type { RawGlobalGroup } from '@gkd-kit/api';
import { OPEN_AD_ORDER } from './utils';

const diabledAppIds = [
Expand All @@ -13,6 +13,14 @@ const diabledAppIds = [
'com.android.phone.recorder', // 录音
'com.android.soundrecorder', // 录音机
'com.android.server.telecom', // 来电拒接短信服务

// 排除软件包安装程序
'com.android.packageinstaller',
'com.google.android.packageinstaller', // Google Play
'com.miui.packageinstaller', // 小米系
'com.samsung.android.packageinstaller', // 三星系
'com.oplus.appdetail', // 一加系

// 在一些常见的应用中禁用
'com.tencent.mm', // 微信
'li.songe.gkd', // GKD
Expand Down
8 changes: 5 additions & 3 deletions src/rawApps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import url from 'node:url';
import picocolors from 'picocolors';
import { pinyin } from 'pinyin-pro';
import { walk } from './file';
import type { RawApp } from './types';
import type { RawAppAddProp } from './types';
import { OPEN_AD_ORDER } from './utils';

const rawApps: RawApp[] = [];
const rawApps: RawAppAddProp[] = [];
for await (const tsFp of walk(process.cwd() + '/src/apps')) {
if (!tsFp.endsWith('.ts')) {
throw new Error('invalid typescript app config file: ' + tsFp);
}
const mod: { default: RawApp } = await import(url.pathToFileURL(tsFp).href);
const mod: { default: RawAppAddProp } = await import(
url.pathToFileURL(tsFp).href
);
const appConfig = mod.default;
if (path.basename(tsFp, '.ts') != appConfig.id) {
throw new Error(
Expand Down
Loading

0 comments on commit 46d3cc2

Please sign in to comment.