nostrenz / hatate-iqdb-tagger

Search and tag images using IQDB or SauceNAO to be imported into Hydrus.
84 stars 2 forks source link

Hatate interrupts window/input focus after each lookup #18

Closed terrehbyte closed 2 years ago

terrehbyte commented 2 years ago

After each lookup, successful or not, Hatate appears to steal window and input focus from whatever application I'm working with. This happens pretty frequently when the delay between each search is set to something small like 5 seconds. This started after upgrading to Release 10.

My workflow for Hatate is as follows:

  1. Query Hydrus for a list of files to search
  2. Start the search, sending the file to Saucenao (and IQDB if that fails)
  3. Sending tags and URL to Hydrus

In hindsight, I probably don't need to send tags if Hydrus is going to handle it anyway, but I wouldn't imagine that would cause an issue.

If it's useful, my full config (w/ keys removed) is as follows:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="Hatate.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <userSettings>
        <Hatate.Properties.Settings>
            <setting name="SearchedParenthesisValue" serializeAs="String">
                <value>1</value>
            </setting>
            <setting name="HydrusApiPort" serializeAs="String">
                <value />
            </setting>
            <setting name="HydrusApiHost" serializeAs="String">
                <value>REMOVED</value>
            </setting>
            <setting name="DeleteImported" serializeAs="String">
                <value>False</value>
            </setting>
            <setting name="HydrusApiAccessKey" serializeAs="String">
                <value>REMOVED</value>
            </setting>
            <setting name="SendUrlWithTags" serializeAs="String">
                <value>True</value>
            </setting>
            <setting name="AddImagesToHydrusPage" serializeAs="String">
                <value>True</value>
            </setting>
            <setting name="HydrusPageName" serializeAs="String">
                <value>hatate</value>
            </setting>
            <setting name="AutoSend" serializeAs="String">
                <value>True</value>
            </setting>
            <setting name="AssociateUrl" serializeAs="String">
                <value>True</value>
            </setting>
            <setting name="HydrusTagServiceKey" serializeAs="String">
                <value>REMOVED</value>
            </setting>
            <setting name="HydrusTagService" serializeAs="String">
                <value>lookup tags</value>
            </setting>
            <setting name="SauceNaoApiKey" serializeAs="String">
                <value>REMOVED</value>
            </setting>
            <setting name="HydrusQuery_ArchiveOnly" serializeAs="String">
                <value>False</value>
            </setting>
            <setting name="HydrusQuery_InboxOnly" serializeAs="String">
                <value>False</value>
            </setting>
            <setting name="HydrusQuery_WarnBeforeImport" serializeAs="String">
                <value>False</value>
            </setting>
            <setting name="HydrusQuery_Limit" serializeAs="String">
                <value>4000</value>
            </setting>
            <setting name="MatchType" serializeAs="String">
                <value>Additional</value>
            </setting>
            <setting name="NotfoundTag" serializeAs="String">
                <value>hatate:not found</value>
            </setting>
            <setting name="Similarity" serializeAs="String">
                <value>80</value>
            </setting>
            <setting name="LogMatchedUrls" serializeAs="String">
                <value>False</value>
            </setting>
            <setting name="ParseTags" serializeAs="String">
                <value>True</value>
            </setting>
            <setting name="AddNotfoundTag" serializeAs="String">
                <value>True</value>
            </setting>
            <setting name="SimilarityThreshold" serializeAs="String">
                <value>15</value>
            </setting>
            <setting name="StartupReleaseCheck" serializeAs="String">
                <value>True</value>
            </setting>
            <setting name="RemoveResultAfter" serializeAs="String">
                <value>True</value>
            </setting>
            <setting name="Delay" serializeAs="String">
                <value>2</value>
            </setting>
            <setting name="AddRating" serializeAs="String">
                <value>True</value>
            </setting>
            <setting name="CheckMatchType" serializeAs="String">
                <value>True</value>
            </setting>
            <setting name="ResizeImage" serializeAs="String">
                <value>False</value>
            </setting>
            <setting name="Sources" serializeAs="String">
                <value>[{"Value":0,"Ordering":1,"Enabled":false,"GetTags":true},{"Value":3,"Ordering":2,"Enabled":true,"GetTags":true},{"Value":1,"Ordering":3,"Enabled":false,"GetTags":true},{"Value":2,"Ordering":4,"Enabled":false,"GetTags":true},{"Value":7,"Ordering":5,"Enabled":false,"GetTags":true},{"Value":5,"Ordering":6,"Enabled":false,"GetTags":true},{"Value":10,"Ordering":7,"Enabled":true,"GetTags":true},{"Value":8,"Ordering":8,"Enabled":false,"GetTags":true},{"Value":6,"Ordering":9,"Enabled":false,"GetTags":true},{"Value":4,"Ordering":10,"Enabled":true,"GetTags":true},{"Value":11,"Ordering":11,"Enabled":false,"GetTags":true},{"Value":13,"Ordering":12,"Enabled":true,"GetTags":true},{"Value":15,"Ordering":13,"Enabled":false,"GetTags":true},{"Value":12,"Ordering":14,"Enabled":true,"GetTags":true},{"Value":14,"Ordering":15,"Enabled":false,"GetTags":true},{"Value":16,"Ordering":16,"Enabled":false,"GetTags":true},{"Value":9,"Ordering":17,"Enabled":false,"GetTags":true}]</value>
            </setting>
            <setting name="ThumbWidth" serializeAs="String">
                <value>300</value>
            </setting>
            <setting name="Randomize" serializeAs="String">
                <value>False</value>
            </setting>
            <setting name="TaggedTag" serializeAs="String">
                <value>hatate:tagged</value>
            </setting>
            <setting name="RetryMethod" serializeAs="String">
                <value>2</value>
            </setting>
            <setting name="AddTaggedTag" serializeAs="String">
                <value>True</value>
            </setting>
            <setting name="SearchEngine" serializeAs="String">
                <value>1</value>
            </setting>
            <setting name="FoundTag" serializeAs="String">
                <value>hatate:found</value>
            </setting>
            <setting name="AskTags" serializeAs="String">
                <value>False</value>
            </setting>
            <setting name="TagsCount" serializeAs="String">
                <value>0</value>
            </setting>
            <setting name="AddFoundTag" serializeAs="String">
                <value>True</value>
            </setting>
        </Hatate.Properties.Settings>
    </userSettings>
</configuration>

Is this intentional behavior or did I miss a setting somewhere?

nostrenz commented 2 years ago

Hi and sorry for the late reply,

This problem is actually due to the "Display imported images in a Hydrus page named..." option in the "Settings" > "Hydrus API" window. When this option is checked (which is the case here as it corresponds to the "AddImagesToHydrusPage" option being True in the setting file you've provided) imported images will be added to a page in the Hydrus client, and when that happens the client focuses itself. So here it's actually Hydrus stealing the focus (which might not be obvious as it happens even if the Hydrus window is minimized in the taskbar or the system tray).

I've tried various things but it seems there's no way to prevent the Hydrus client from focusing itself when a file is added to a page using the API. I've also noticed that it only happens like 80% of the time, which explains why it happens frequently (but not always) as you said and why it's worse when the delay between searches in Hatate is smaller.

It's not ideal but the best you can do to avoid this problem for now is either to disable that option, or to disable the "Automatically send search files to Hydrus" option, and manually selecting the files in the list then right-clicking and selecting "Hydrus" > "Import files with tags" in the context menu.

terrehbyte commented 2 years ago

Gotcha, you're totally right there. I kept it on to review the files that got tagged and rate them, but I'll just have to settle for them coming up in other queries in the future instead.

I'll go ahead and close this out then~ ✨ Thank you for creating and maintaining Hatate!