Skip to content

Commit

Permalink
feat: info
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Jun 10, 2024
1 parent d5c1ca9 commit bdac16d
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 73 deletions.
4 changes: 2 additions & 2 deletions src/components/SearchCard.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { message } from '@/utils/discrete';
import { errorTry, errorWrap } from '@/utils/error';
import { getNodeLabel } from '@/utils/node';
import { getAppInfo, getNodeLabel } from '@/utils/node';
import { buildEmptyFn, copy } from '@/utils/others';
import type { Selector } from '@/utils/selector';
import { parseSelector, wasmLoadTask } from '@/utils/selector';
Expand Down Expand Up @@ -177,7 +177,7 @@ const generateRules = errorTry(
].some(Boolean);
const rule = {
id: props.snapshot.appId,
name: props.snapshot.appName,
name: getAppInfo(props.snapshot).name,
groups: [
{
key: 1,
Expand Down
35 changes: 25 additions & 10 deletions src/components/WindowCard.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<script setup lang="tsx">
import { getDevice, getNodeLabel } from '@/utils/node';
import {
getAppInfo,
getDevice,
getGkdAppInfo,
getNodeLabel,
} from '@/utils/node';
import { buildEmptyFn, copy, delay } from '@/utils/others';
import type { RawNode, Snapshot } from '@/utils/types';
import {
Expand Down Expand Up @@ -93,8 +98,8 @@ const renderLabel = (info: {
striped
:singleLine="false"
:themeOverrides="{
thPaddingSmall: '2px 4px',
tdPaddingSmall: '2px 4px',
thPaddingSmall: '2px 6px',
tdPaddingSmall: '2px 6px',
}"
>
<NThead>
Expand All @@ -104,6 +109,7 @@ const renderLabel = (info: {
<NTh> 应用名称 </NTh>
<NTh> 版本名称 </NTh>
<NTh> 版本代码 </NTh>
<NTh> 系统应用 </NTh>
<NTh> 应用ID </NTh>
<NTh> 界面ID </NTh>
<NTh> 操作 </NTh>
Expand All @@ -119,26 +125,35 @@ const renderLabel = (info: {
}}
</NTd>
<NTd class="whitespace-nowrap">
{{ getDevice(snapshot).gkdVersionName || '1.6.4' }}
{{ getGkdAppInfo(snapshot).versionName }}
</NTd>
<NTd class="whitespace-nowrap" @click="copy(snapshot.appName)">
<NTd
class="whitespace-nowrap"
@click="copy(getAppInfo(snapshot).name)"
>
<NEllipsis>
{{ snapshot.appName }}
{{ getAppInfo(snapshot).name }}
</NEllipsis>
</NTd>
<NTd class="whitespace-nowrap" @click="copy(snapshot.appVersionName)">
<NTd
class="whitespace-nowrap"
@click="copy(getAppInfo(snapshot).versionName)"
>
<NEllipsis>
{{ snapshot.appVersionName }}
{{ getAppInfo(snapshot).versionName }}
</NEllipsis>
</NTd>
<NTd
class="whitespace-nowrap"
@click="copy(snapshot.appVersionCode.toString())"
@click="copy(getAppInfo(snapshot).versionCode.toString())"
>
<NEllipsis>
{{ snapshot.appVersionCode }}
{{ getAppInfo(snapshot).versionCode }}
</NEllipsis>
</NTd>
<NTd class="whitespace-nowrap">
{{ getAppInfo(snapshot).isSystem ? `是` : `否` }}
</NTd>
<NTd
class="whitespace-nowrap max-w-[max(12vw,180px)]"
@click="copy(snapshot.appId)"
Expand Down
33 changes: 31 additions & 2 deletions src/utils/node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Device, RawNode, SizeExt, Snapshot } from './types';
import type { AppInfo, Device, RawNode, SizeExt, Snapshot } from './types';

export const listToTree = (nodes: RawNode[]) => {
// nodes = structuredClone(nodes);
Expand Down Expand Up @@ -177,9 +177,38 @@ export const getLimitLabel = (node: RawNode, limit = 15): string => {
return label;
};

export const getDevice = (snapshot: Snapshot) => {
export const getDevice = (snapshot: Snapshot): Device => {
if (typeof snapshot.device == 'object' && snapshot.device) {
return snapshot.device;
}
return snapshot as unknown as Device;
};

export const getAppInfo = (snapshot: Snapshot): AppInfo => {
return (
snapshot.appInInfo || {
id: snapshot.appId,
name: snapshot.appName,
versionCode: snapshot.appVersionCode,
versionName: snapshot.appVersionName,
hidden: false,
isSystem: false,
mtime: Date.now(),
}
);
};

export const getGkdAppInfo = (snapshot: Snapshot): AppInfo => {
const device = getDevice(snapshot);
return (
snapshot.gkdAppInfo || {
id: 'li.songe.gkd',
name: 'GKD',
versionCode: device.gkdVersionCode,
versionName: device.gkdVersionName,
hidden: false,
isSystem: false,
mtime: Date.now(),
}
);
};
3 changes: 2 additions & 1 deletion src/utils/others.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export const delay = async (n = 0) => {

export const copy = (() => {
let lastText: string | void = void 0;
return async (text: string) => {
return async (text?: string) => {
if (!text) return;
if (lastText === text) return;
lastText = text;
delay(10_000).then(() => {
Expand Down
12 changes: 6 additions & 6 deletions src/utils/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NEllipsis } from 'naive-ui';
import type { TableBaseColumn } from 'naive-ui/es/data-table/src/interface';
import { shallowReactive, withDirectives } from 'vue';
import { rect } from './directives';
import { getDevice } from './node';
import { getAppInfo, getDevice } from './node';
import { copy } from './others';
import { importTimeStorage } from './storage';
import type { Snapshot } from './types';
Expand Down Expand Up @@ -90,17 +90,17 @@ export const useSnapshotColumns = () => {
title: `应用名称`,
filterMultiple: true,
filter(value, row) {
return value.toString() == row.appName;
return value.toString() == getAppInfo(row).name;
},
cellProps(row) {
return {
onClick() {
copy(row.appName);
copy(getAppInfo(row).name);
},
};
},
render(row) {
return row.appName;
return getAppInfo(row).name;
},
});
const appIdCol = useAutoWrapWidthColumn<Snapshot>({
Expand All @@ -123,15 +123,15 @@ export const useSnapshotColumns = () => {
title: `版本代码`,
minWidth: 150,
render(row) {
return row.appVersionCode;
return getAppInfo(row).versionCode;
},
});
const appVersionNameCol = useAutoWrapWidthColumn<Snapshot>({
key: `appVersionName`,
title: `版本号`,
minWidth: 150,
render(row) {
return <NEllipsis>{row.appVersionName}</NEllipsis>;
return <NEllipsis>{getAppInfo(row).versionName}</NEllipsis>;
},
});

Expand Down
58 changes: 38 additions & 20 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ export type Device = {
brand: string;
sdkInt: number;
release: string;
gkdVersionCode: number;
gkdVersionName: string;

/**
* @deprecated use gkdAppInfo instead
*/
gkdVersionCode?: number;
/**
* @deprecated use gkdAppInfo instead
*/
gkdVersionName?: string;
};

export type RawNode = {
Expand Down Expand Up @@ -53,34 +60,45 @@ export type RawAttr = {

export type Overview = {
id: number;
screenWidth: number;
screenHeight: number;

appId: string;
appName: string;
appVersionName: string;
appVersionCode: number;
activityId: string;

screenWidth: number;
screenHeight: number;
isLandscape: boolean;

appInInfo: AppInfo;
gkdAppInfo: AppInfo;

/**
* @deprecated use appInfo instead
*/
appName?: string;
/**
* @deprecated use appInfo instead
*/
appVersionName?: string;
/**
* @deprecated use appInfo instead
*/
appVersionCode?: number;
};

export type Snapshot = Overview & {
device: Device;
nodes: RawNode[];
};

// export type SnapshotExt = Snapshot & {
// node: NaiveNode;
// };

// export type NaiveNode = {
// value: RawNode;
// children: NaiveNode[];
// parent?: NaiveNode;
// key: number;
// label: string;
// isLeaf?: boolean;
// prefix?: () => VNode;
// };
export type AppInfo = {
id: string;
name: string;
versionCode: number;
versionName?: string;
isSystem: boolean;
mtime: number;
hidden: boolean;
};

export type RectX = {
bottom: number;
Expand Down
44 changes: 20 additions & 24 deletions src/views/DevicePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,31 +191,27 @@ const subsText = shallowRef(``);
const updateSubs = useTask(async () => {
const data = errorWrap(() => JSON5.parse(subsText.value.trim()));
if (!data) return;
if (device.value?.gkdVersionCode) {
if (data.categories || data.globalGroups || data.apps) {
await api.updateSubscription(data);
} else if (typeof data.id == 'string') {
await api.updateSubscription({
apps: [data],
});
} else if (Array.isArray(data) && typeof data[0].id == 'string') {
await api.updateSubscription({
apps: data,
});
} else if (typeof data.key == 'number') {
await api.updateSubscription({
globalGroups: [data],
});
} else if (Array.isArray(data) && typeof data[0].key == 'number') {
await api.updateSubscription({
globalGroups: data,
});
} else {
message.error(`无法识别的订阅文本`);
return;
}
if (data.categories || data.globalGroups || data.apps) {
await api.updateSubscription(data);
} else if (typeof data.id == 'string') {
await api.updateSubscription({
apps: [data],
});
} else if (Array.isArray(data) && typeof data[0].id == 'string') {
await api.updateSubscription({
apps: data,
});
} else if (typeof data.key == 'number') {
await api.updateSubscription({
globalGroups: [data],
});
} else if (Array.isArray(data) && typeof data[0].key == 'number') {
await api.updateSubscription({
globalGroups: data,
});
} else {
await api.updateSubsApps([].concat(data));
message.error(`无法识别的订阅文本`);
return;
}
message.success(`修改成功`);
});
Expand Down
11 changes: 5 additions & 6 deletions src/views/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
batchZipDownloadZip,
} from '@/utils/export';
import { importFromLocal, importFromNetwork } from '@/utils/import';
import { getAppInfo } from '@/utils/node';
import {
settingsStorage,
shallowSnapshotStorage,
Expand Down Expand Up @@ -70,7 +71,7 @@ const filterSnapshots = computed(() => {
if (!actualQuery) return snapshots.value;
return snapshots.value.filter((s) => {
return (
(s.appName || ``).includes(actualQuery) ||
(getAppInfo(s).name || ``).includes(actualQuery) ||
(s.appId || ``).includes(actualQuery) ||
(s.activityId || ``).includes(actualQuery)
);
Expand Down Expand Up @@ -111,7 +112,7 @@ watchEffect(() => {
watchEffect(() => {
const set = filterSnapshots.value.reduce(
(p, c) => (p.add(c.appName), p),
(p, c) => (p.add(getAppInfo(c).name), p),
new Set<string>(),
);
if (set.size <= 1) {
Expand Down Expand Up @@ -240,16 +241,14 @@ const batchShareJpgUrl = useTask(async () => {
await waitShareAgree();
const pngUrls = await batchCreateJpgUrl(await checkedSnapshots());
showTextDLg({
content:
pngUrls.map((s) => githubUrlToSelfUrl(router, s)).join(`\n`) + `\n`,
content: pngUrls.map((s) => githubUrlToSelfUrl(s)).join(`\n`) + `\n`,
});
});
const batchShareZipUrl = useTask(async () => {
await waitShareAgree();
const zipUrls = await batchCreateZipUrl(await checkedSnapshots());
showTextDLg({
content:
zipUrls.map((s) => githubUrlToSelfUrl(router, s)).join(`\n`) + `\n`,
content: zipUrls.map((s) => location.origin + '/i/' + s).join(`\n`) + `\n`,
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/views/SnapshotPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import AttrCard from '@/components/AttrCard.vue';
import ScreenshotCard from '@/components/ScreenshotCard.vue';
import SearchCard from '@/components/SearchCard.vue';
import WindowCard from '@/components/WindowCard.vue';
import { listToTree } from '@/utils/node';
import { getAppInfo, listToTree } from '@/utils/node';
import { loadingBar, message } from '@/utils/discrete';
import { delay } from '@/utils/others';
import {
Expand Down Expand Up @@ -112,7 +112,7 @@ onMounted(async () => {
);
snapshot.value = localSnapshot;
rootNode.value = listToTree(localSnapshot.nodes);
title.value = '快照-' + localSnapshot.appName || localSnapshot.appId;
title.value = '快照-' + getAppInfo(localSnapshot).name || localSnapshot.appId;
if (!focusNode.value) {
focusNode.value = rootNode.value;
}
Expand Down

0 comments on commit bdac16d

Please sign in to comment.