Windows의 Eclipse RCP 응용 프로그램에서 사용할 때 swt 브라우저 클릭 소리를 비활성화하는 방법은 무엇입니까?

DorAga

Eclipse RCP 애플리케이션에 swt 브라우저를 내장했습니다. 내 문제는 Windows에서 브라우저 setUrl()dispose()방법으로 인해 (성가신) Internet Explorer 탐색 소리 ( '클릭')가 발생하여 바람직하지 않습니다.

클릭 소리를 성공적으로 비활성화하는이 코드를 찾았습니다.

OS.CoInternetSetFeatureEnabled(OS.FEATURE_DISABLE_NAVIGATION_SOUNDS, OS.SET_FEATURE_ON_PROCESS, true);

그러나 이것은 제한된 API이기 때문에 Maven / Tycho를 사용하여 애플리케이션을 빌드하는 데 문제가 있습니다.

[ERROR] OS.CoInternetSetFeatureEnabled(OS.FEATURE_DISABLE_NAVIGATION_SOUNDS, OS.SET_FEATURE_ON_PROCESS, true);
[ERROR] ^^
[ERROR] OS cannot be resolved to a variable
[ERROR] 4 problems (4 errors)
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:0.22.0:compile (default-compile) on project com.myapp: Compilation failure
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)...

이 제한된 API를 사용하는 동안 Maven / Tycho를 컴파일하는 방법이 있습니까?

아니면 Windows에서 IE 브라우저 탐색 소리를 비활성화하는 다른 방법이 있습니까?

DorAga

나는 결국 이것을 깨뜨릴 수 있었고 여기에 방법이 있습니다.

이 제한적인 API는 플랫폼 별 플러그인, 즉 SWT 32 비트 및 SWT 64 비트에 있기 때문에 코드를 보관하기 위해 두 개의 플랫폼 별 조각을 만들었습니다.

maven이 조각을 컴파일하도록하려면 build.properties 파일의 32 비트 조각에 다음 줄을 추가해야합니다.

extra.. = platform:/fragment/org.eclipse.swt.win32.win32.x86

64 비트 조각 build.properties의 경우 다음

extra.. = platform:/fragment/org.eclipse.swt.win32.win32.x86_64

maven pom 구성 파일은 32 비트 조각의 pom.xml에 다음 섹션을 추가하여 수행되는 플랫폼 별이어야합니다.

<build>
    <plugins>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>target-platform-configuration</artifactId>

            <configuration>
                <environments>
                    <environment>
                        <os>win32</os>
                        <ws>win32</ws>
                        <arch>x86</arch>
                    </environment>
                </environments>
            </configuration>
        </plugin>
    </plugins>
</build>

다음은 64 비트 버전입니다.

<build>
    <plugins>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>target-platform-configuration</artifactId>
            <configuration>
                <environments>
                    <environment>
                        <os>win32</os>
                        <ws>win32</ws>
                        <arch>x86_64</arch>
                    </environment>
                </environments>
            </configuration>
        </plugin>
    </plugins>
</build>

또한 여기에 표시된 것처럼 프래그먼트 매니페스트에서 각 플랫폼 필터를 설정하는 것을 잊지 마십시오.

Eclipse-PlatformFilter: (& (osgi.os=win32) (osgi.arch=x86))
Eclipse-PlatformFilter: (& (osgi.os=win32) (osgi.arch=x86_64))

그런 다음 각 조각의 클래스에 침묵 코드를 배치합니다. 이 클래스는 호스트 플러그인에서 인터페이스를 구현해야합니다. 호스트 플러그인은 호스트 플러그인에서 인터페이스를 구현하는 클래스를 취하는 확장 점을 정의합니다. 그런 다음 조각은 확장을 선언하고 조각에 클래스 이름을 제공합니다.

호스트 코드가 침묵 코드를 실행해야하는 경우 확장을 확인하고 침묵 코드를 인스턴스화하고 호출해야합니다.

예:

package com.mypackage;

import javax.inject.Inject;

import org.apache.log4j.Logger;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.e4.core.di.annotations.Creatable;

import com.mypackage.ISilencer;

@Creatable
public class BrowserSilencer {

    private static final Logger LOGGER = Logger.getLogger(BrowserSilencer.class);

    @Inject
    IExtensionRegistry exReg;

    public void silence=() {
        IConfigurationElement[] config = exReg.getConfigurationElementsFor("com.mypackage.silencer");
        try {
            for (IConfigurationElement e : config) {
                final Object o = e.createExecutableExtension("class");
                if (o instanceof ISilencer) {
                    executeExtension(o);
                }
            }
        } catch (CoreException ex) {
            LOGGER.error("Error finding the com.mypackage.silencer extension");
        }
    }

    private void executeExtension(final Object o) {
        ISafeRunnable runnable = new ISafeRunnable() {
            @Override
            public void handleException(Throwable e) {
                LOGGER.error("Exception while attempting to silence browser");
            }

            @Override
            public void run() throws Exception {
                ((ISilencer) o).silence();
            }
        };
        SafeRunner.run(runnable);
    }
}

호스트 플러그인의 인터페이스

package com.mypackage;
public interface ISilencer {
   public void silence();
}

및 64 비트 플러그인의 코드 예. 32 비트는 거의 동일합니다.

package com.mypackage.fragment.win64;

import org.apache.log4j.Logger;
import org.eclipse.swt.internal.win32.OS;   // yes i DO mean win32 here

import com.mypackage.ISilencer;

@SuppressWarnings("restriction")
public class Silencer implements ISilencer {

    private static final Logger LOGGER = Logger.getLogger(Silencer.class);

    @Override
    public void silence() {
        // removes the annoying browser clicking sound!
        try {
            OS.CoInternetSetFeatureEnabled(OS.FEATURE_DISABLE_NAVIGATION_SOUNDS, OS.SET_FEATURE_ON_PROCESS, true);
        } catch (Throwable e1) {
            // I am just catching any exceptions that may come off this one since it is using restricted API so that if in any case it fail well it will just click.
            LOGGER.error("Caught exception while setting FEATURE_DISABLE_NAVIGATION_SOUNDS.");
        }
    }
}

BrowserSilencer가 표시되어 있으므로 @Creatable클래스에 간단히 삽입하고 silence()메서드를 호출 할 수 있습니다.

만드는 방법과 확장 점이 명확하지 않은 경우 후속 게시물에서 보여줄 수 있습니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관