[소스 코드] 유용한 링크 관리자

2025 단어 Palm
var ConnectMgr = Class.create({
    initialize:function() {
        this.connected = 0;
        this._checkConnection();
    },

    _checkConnection : function() {
        try {
            var controller = Mojo.Controller.stageController.activeScene();
            controller.serviceRequest('palm://com.palm.connectionmanager/',
              {
                  method: 'getstatus',
                  parameters:
                    {
                        subscribe: true
                    },
                  onSuccess: this._checkSuccess.bind(this),
                  onFailure: this._checkFailure.bind(this)
              });
        }
        catch (e) {
            Mojo.Log.error('ConnectMgr -', e);
        }
    },

    _checkSuccess:function(response) {
        Mojo.Log.info('ConnectMgr - _checkSuccess', response.isInternetConnectionAvailable);
        this.connected = response.isInternetConnectionAvailable;
    },

    _checkFailure:function(response) {
        Mojo.Log.error('ConnectMgr - Connection Check Error:', response.errorText, '(Code', response.code, ')');
    }
});

 
사용 방법:
activate : function(event) {
    // Check connection status
    connmgr = new ConnectMgr();
}
 
if (!connmgr.connected) {
    Mojo.Controller.errorDialog('Request cannot be processed without a network connection.');
    return;
} 

좋은 웹페이지 즐겨찾기