Skip to content

Commit

Permalink
feat: support custom image subtype
Browse files Browse the repository at this point in the history
  • Loading branch information
pk5ls20 committed Nov 15, 2024
1 parent 68d8665 commit 4343c46
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 44 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ Thanks to the following projects. LiteLoaderQQNT-NekoImage could not have been r
- https://github.com/xiyuesaves/LiteLoaderQQNT-lite_tools
- https://github.com/Night-stars-1/LiteLoaderQQNT-Plugin-LLAPI
- https://github.com/LLOneBot/LLOneBot
- https://github.com/NapNeko/NapCatQQ
- https://github.com/darkreader/darkreader
- (more repo mentioned in the code comments)
1 change: 1 addition & 0 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ cp -r LiteLoaderQQNT-NekoImage /path/to/your/LiteloaderQQNT/plugin-path
- https://github.com/xiyuesaves/LiteLoaderQQNT-lite_tools
- https://github.com/Night-stars-1/LiteLoaderQQNT-Plugin-LLAPI
- https://github.com/LLOneBot/LLOneBot
- https://github.com/NapNeko/NapCatQQ
- https://github.com/darkreader/darkreader
- (代码注释中提到的更多项目)
6 changes: 3 additions & 3 deletions src/app/components/search/searchResult.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ const handleConfirmDelete = async (confirmed: boolean) => {
const handleImageClick = async (img: Image, id: string) => {
img.url = await getUrlBase64(img.url);
const editorImg = new EditorImageMsg(img, 0); // TODO: let user choose picSubType
const editorImg = new EditorImageMsg(img, store.pluginSettingData.nekoimage_pic_subtype);
const editorMsg = new NTQQEditorImageMsg(editorImg);
EnvAdapter.log('Adding editor', JSON.stringify(editorMsg));
EnvAdapter.log(`Image ID: ${id}`);
// EnvAdapter.log('Adding editor', JSON.stringify(editorMsg));
// EnvAdapter.log(`Image ID: ${id}`);
EnvAdapter.addNTQQEditor([editorMsg]);
await EnvAdapter.adjustVisible(false);
};
Expand Down
6 changes: 3 additions & 3 deletions src/app/states/searchWindowState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const useSearchStore = defineStore('search', {
isFetchError: false as boolean,
fetchErrorMsg: '' as string,
tabActiveItem: searchType.TEXT as searchType,
searchResults: (<SearchResult[]>[]) as SearchResult[],
searchResults: <SearchResult[]>[],
queryBasicInput: '' as string,
queryImageInput: null as string | null,
queryAdvanceChipsSelectVal: promptType.POSITIVE as string,
Expand All @@ -39,8 +39,8 @@ export const useSearchStore = defineStore('search', {
serverStatusColor: 'grey' as string,
serverCheckResult: null as HomeApiResponse | null,
advanceSelectEquivalentClickCount: 0 as number,
pluginSettingData: new sharedAdapter.PluginSettingsModel('', '', '') as sharedAdapter.PluginSettingsModelType,
filterOptions: new SearchFilterOptions() as SearchFilterOptions,
pluginSettingData: new sharedAdapter.PluginSettingsModel('', '', ''),
filterOptions: new SearchFilterOptions(),
isFilterOptionsDialogOpen: false as boolean,
filterAspectRatioEnabled: false as boolean,
minSizeEnabled: false as boolean,
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/searchWindow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</template>

<script lang="ts" setup>
import { onMounted, watch, defineComponent, ref } from 'vue';
import { defineComponent, onMounted, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { EnvAdapter } from '../adapter/EnvAdapter';
import SearchWindowDialog from '../components/search/searchWindowStatusDialog.vue';
Expand Down
10 changes: 9 additions & 1 deletion src/common/share/PluginSettingsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ export class pluginSettingsModel {
public nekoimage_access_token: string;
public nekoimage_admin_token: string;
public nekoimage_lang: 'en-US' | 'zh-CN';
public nekoimage_pic_subtype: 0 | 1;

constructor(api: string, accessToken: string, adminToken: string, lang: 'en-US' | 'zh-CN' = 'en-US') {
constructor(
api: string,
accessToken: string,
adminToken: string,
lang: 'en-US' | 'zh-CN' = 'en-US',
picSubtype: 0 | 1 = 0
) {
this.nekoimage_api = api;
this.nekoimage_access_token = accessToken;
this.nekoimage_admin_token = adminToken;
this.nekoimage_lang = lang;
this.nekoimage_pic_subtype = picSubtype;
}
}
2 changes: 1 addition & 1 deletion src/main/callNative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const getForwardMsgContent = async (msgData: forwardMsgData): Promise<RawMessage
parentMsgId: msgData.parentMsgId ?? msgData.rootMsgId
}
];
// log.debug('await invokeNative in args: ', JSON.stringify(args));
// log.debug(`await invokeNative in args: ${JSON.stringify(args)}`);
const res = await invokeNative<unknown[], GeneralCallResult, { msgList: RawMessage[] }>(
'nodeIKernelMsgService/getMultiMsg',
IPC_EVENT,
Expand Down
6 changes: 3 additions & 3 deletions src/main/native/sora/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export const cleanFCListeners = (callbackId: UUID) => {

// stage2 extend stage1
export class SCListener<CB1, CB2> {
private checkMap: Map<UUID, (stageTwoData: CB1 & CB2) => boolean>;
private promiseResolvers: Map<UUID, () => void>;
private readonly checkMap: Map<UUID, (stageTwoData: CB1 & CB2) => boolean>;
private readonly promiseResolvers: Map<UUID, () => void>;

constructor(private eventEmitter: EventEmitter) {
constructor(private readonly eventEmitter: EventEmitter) {
this.checkMap = new Map();
this.promiseResolvers = new Map();
}
Expand Down
1 change: 0 additions & 1 deletion src/main/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ipcMain handle
import * as fs from 'node:fs';
import path from 'node:path';
import { BrowserWindow, ipcMain } from 'electron';
Expand Down
35 changes: 8 additions & 27 deletions src/preload/callNative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,31 @@ import { nekoMsgData } from '../common/NTQQMsgModel';
import { ipcRenderer } from 'electron';
import { log } from '../common/share/logs';

export const downloadMsgContent = async <
DT extends nekoMsgData | nekoMsgData[],
SDT1 extends unknown,
SDT2 extends unknown,
EDT1 extends unknown
>(
export const downloadMsgContent = async <DT extends nekoMsgData | nekoMsgData[], SDT1, SDT2, EDT1>(
msgData: DT,
startDownloadChannel: string,
finishDownloadChannel: string
): Promise<{
startDownload: Promise<Awaited<{ onDiskMsgContentList: SDT1[]; notOnDiskMsgContentList: SDT2[] }>>;
endDownload: Promise<EDT1[]>;
startDownload: { onDiskMsgContentList: SDT1[]; notOnDiskMsgContentList: SDT2[] };
endDownload: EDT1[];
}> => {
try {
const downloadHandle = async () => {
// log.debug('Downloading forward message content:', msgData);
const result: { onDiskMsgContentList: SDT1[]; notOnDiskMsgContentList: SDT2[] } = await ipcRenderer.invoke(
startDownloadChannel,
msgData
);
// log.debug('Downloaded forward message content:', result);
const onDiskMsgContentList: SDT1[] = result.onDiskMsgContentList;
const notOnDiskMsgContentList: SDT2[] = result.notOnDiskMsgContentList;
const startDownload: Promise<Awaited<{ onDiskMsgContentList: SDT1[]; notOnDiskMsgContentList: SDT2[] }>> =
Promise.resolve({
onDiskMsgContentList,
notOnDiskMsgContentList
});
// log.debug(
// 'Downloaded forward message content:',
// 'on disk:',
// onDiskMsgContentList,
// 'not on disk',
// notOnDiskMsgContentList
// );
const endDownload: Promise<EDT1[]> = ipcRenderer.invoke(finishDownloadChannel, notOnDiskMsgContentList);
const { onDiskMsgContentList, notOnDiskMsgContentList } = result;
const startDownload = { onDiskMsgContentList, notOnDiskMsgContentList };
const endDownload = await ipcRenderer.invoke(finishDownloadChannel, notOnDiskMsgContentList);
return { startDownload, endDownload };
};
return downloadHandle();
} catch (error) {
log.error('Error retrieving forward message content:', error);
return {
startDownload: Promise.reject(error),
endDownload: Promise.reject([])
startDownload: { onDiskMsgContentList: [], notOnDiskMsgContentList: [] },
endDownload: []
};
}
};
8 changes: 4 additions & 4 deletions src/renderer/inject/injectRightMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const addQContextMenu = (
const injectLogic = async (msgData: forwardMsgData) => {
(async () => {
const ps = await window.imageSearch.downloadMsgContent<forwardMsgData, ImgObject, picMsgData, ImgObject>(
msgData!,
msgData,
channel.GET_FORWARD_MSG_PIC,
channel.DOWNLOAD_MULTI_MSG_IMAGE
);
Expand Down Expand Up @@ -113,11 +113,11 @@ export const addQContextMenuMain = async () => {
imageObject = null;
isRightClick = true;
if (event.target instanceof HTMLElement) {
el = event.target as HTMLElement;
el = event.target;
const elParent = el.closest('.ml-item');
if (!elParent) return;
// hook vue app to get forward msg data
const forwardMsgVueElement = (app as any)?.__vue_app__?.config?.globalProperties?.$store?.state?.aio_chatMsgArea
const forwardMsgVueElement = app?.__vue_app__?.config?.globalProperties?.$store?.state?.aio_chatMsgArea
?.msgListRef?.curMsgs as vueMsgElement[] | null;
const forwardMsgElement = forwardMsgVueElement?.find((msg: vueMsgElement) => msg.id === elParent.id);
// log.debug('Forward Msg Element', forwardMsgElement);
Expand Down Expand Up @@ -150,7 +150,7 @@ export const addQContextMenuMain = async () => {
}
if (event.target instanceof HTMLImageElement) {
if (haveImgContent()) {
imageObject = new imageContainer((event.target as HTMLImageElement).src?.toString());
imageObject = new imageContainer(event.target.src?.toString());
log.debug(
'Got Image',
imageObject.src.length > 200 ? `${imageObject.src.slice(0, 200)}...` : imageObject.src
Expand Down
19 changes: 19 additions & 0 deletions src/renderer/setting/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,25 @@
</div>
</setting-item>

<setting-item data-direction="column">
<div>
<setting-text>设置发送图片类型</setting-text>
<setting-text data-type="secondary" style="-webkit-line-clamp: initial">
应用后立即生效
</setting-text>
<div class="input-group">
<select class="neko-pic-subtype">
<option value="0">0(图片)</option>
<option value="1">1(收藏表情)</option>
</select>
<div class="ops-btns">
<setting-button class="neko-pic-subtype-reset" data-type="secondary">恢复默认</setting-button>
<setting-button class="neko-pic-subtype-apply" data-type="secondary">立即应用</setting-button>
</div>
</div>
</div>
</setting-item>

</setting-list>
</setting-panel>
</setting-section>
14 changes: 14 additions & 0 deletions src/renderer/setting/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export const settings = async (view: any) => {
const nekoimage_lang = view.querySelector('.image_search .neko-lang');
const nekoimage_lang_apply = view.querySelector('.image_search .neko-lang-apply');
const nekoimage_lang_reset = view.querySelector('.image_search .neko-lang-reset');
const nekoimage_pic_subtype = view.querySelector('.image_search .neko-pic-subtype');
const nekoimage_pic_subtype_apply = view.querySelector('.image_search .neko-pic-subtype-apply');
const nekoimage_pic_subtype_reset = view.querySelector('.image_search .neko-pic-subtype-reset');

// console.log(JSON.stringify(settings));
nekoimage_access_token.value = settings.nekoimage_admin_token ?? '';
Expand Down Expand Up @@ -82,6 +85,17 @@ export const settings = async (view: any) => {
await window.imageSearch.setSettings(settings);
alert('Language Reset');
});
nekoimage_pic_subtype_apply.addEventListener('click', async () => {
settings.nekoimage_pic_subtype = parseInt(nekoimage_pic_subtype.value) as 0 | 1;
await window.imageSearch.setSettings(settings);
alert('Pic Subtype Applied');
});
nekoimage_pic_subtype_reset.addEventListener('click', async () => {
nekoimage_pic_subtype.value = '0';
settings.nekoimage_pic_subtype = 0;
await window.imageSearch.setSettings(settings);
alert('Pic Subtype Reset');
});
} catch (error) {
log.error('[Error in setting]', error);
}
Expand Down

0 comments on commit 4343c46

Please sign in to comment.