当应用程序是代理时,如何在Mac OS X中取消关机? [英] How to cancel shutdown in Mac OS X when application is an agent?

查看:99
本文介绍了当应用程序是代理时,如何在Mac OS X中取消关机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java应用程序,需要对Dock隐藏,并且还需要能够中断。这是我处理关机的方式:

I have a Java application that I need to hide from Dock and I also need to be able to interrupt. This is how I handle shutdown:

import com.apple.eawt.AppEvent.QuitEvent;
import com.apple.eawt.QuitHandler;
import com.apple.eawt.QuitResponse;
import com.apple.eawt.Application;

public class MacOSXCustomizer {
    public void init() {
        Application application = Application.getApplication();
        application.setQuitHandler(new QuitHandler() {
            public void handleQuitRequestWith(QuitEvent qe, QuitResponse qr) {
                if(Main.prepareForExit()) {
                    qr.performQuit();
                } else {
                    qr.cancelQuit();
                }
            }
        });
    }
}

我使用自己的Java启动器,并且使用应用程序捆绑了我自己的Java启动器二进制文件。我将LSUIElement设置为YES,这用Dock图标解决了我的问题,但是关闭钩子停止了工作。我的方法在关机期间被调用(我可以记录它),但是即使调用qr.cancelQuit(),应用程序也会终止。似乎系统没有在等待响应。即使正在运行某些操作(2秒长),它也不会结束。这会导致数据丢失。

I use my own launcher for Java and I use and Application bundle with my own Java launcher binary. I set LSUIElement to YES which solved my problem with a Dock icon, but then shutdown hook stopped working. My method is called during shutdown (I can log it) but application is terminated even if qr.cancelQuit() is called. It seems like a system is not waiting for response. Even if there is running some operations (2 seconds long) it is not finished. It causes data loss.

我试图将LSUIElement设置回NO,然后在调用qr.cancelQuit()时系统取消关闭。没有其他更改。

I tried to set LSUIElement back to NO and then system cancels shutdown when qr.cancelQuit() is called. No other change was done.

我还尝试创建仅实现一种方法的简单Cocoa应用程序:

I also tried to create simple Cocoa application which implements only one method:

- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
    return NSTerminateCancel;
}

它显示对话框应用程序ShutdownTest已取消注销。但是用户会话仍然注销。

it displays dialog "The application ShutdownTest canceled logout." but user session is logged out anyway.

我的问题是我该如何解决在Dock和菜单栏中没有图标以及能够取消/中断关机顺序的问题?

My question is how can I solve to not have icon in Dock and Menu bar and to be able to cancel/interrupt shutdown sequence?

编辑:是否是Java应用程序无关紧要。本机应用程序具有相同的行为。

It is not relevant whether it is a Java application. Native applications have same behavior.

推荐答案

我与Apple技术支持部门进行了讨论,但无法实现我要求的行为。设计为代理的应用程序(例如,通过将LSUIElement设置为YES)不允许中断关机或注销序列。系统只是不等待响应,也不费心读取和尊重返回值。

I disscussed it with Apple Tech Support and my requested behavior is not possible. The application designed as an Agent (for instance by setting LSUIElement to YES) is not allowed to interrupt shutdown or logout sequence. System simply doesn't wait for response and don't bother to read and respect return value.

背景应用程序(没有Dock图标和菜单栏)不是

Background application (that does not have Dock icon and Menu bar) is not allowed to interact with user nor cancel his shutdown sequence.

Apple Tech Support表示无法隐藏Dock图标和菜单栏并成为前台应用程序。

Apple Tech Support says that there is no possibility to hide Dock icon and Menu bar and be foreground application.

这篇关于当应用程序是代理时,如何在Mac OS X中取消关机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆