如何从暂存器创建xpi文件

时间:2015-09-21 07:43:52

标签: firefox firefox-addon jsctypes xpi

我在暂存器环境中开发了我的附加组件,现在开发已完成,我想创建最终的xpi文件。

我只替换它:

//
//  AppDelegate.swift
//

import UIKit
import CoreData

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GGLInstanceIDDelegate, GCMReceiverDelegate {

    var window: UIWindow?

    var connectedToGCM = false
    var gcmSenderID: String?
    var gcmRegistrationToken: String?
    var gcmRegistrationOptions = [String: AnyObject]()
    let gcmRegistrationKey = "onRegistrationCompleted"
    var subscribedToTopic = false

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        print("bundleId=\(NSBundle.mainBundle().bundleIdentifier)")

        // Configure Google Analytics
        // Configure tracker from GoogleService-Info.plist.
        var configureError:NSError?
        GGLContext.sharedInstance().configureWithError(&configureError)
        assert(configureError == nil, "Error configuring Google services: \(configureError)")

        // Optional: configure GAI options.
        let gai = GAI.sharedInstance()
        gai.trackUncaughtExceptions = true  // report uncaught exceptions
        gai.logger.logLevel = GAILogLevel.Verbose  // remove before app release


        // Override point for customization after application launch.
        application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil))  // types are UIUserNotificationType members
        // Register for remotes notifications
        UIApplication.sharedApplication().registerForRemoteNotifications()

        // Get the gcm sender id
        gcmSenderID = GGLContext.sharedInstance().configuration.gcmSenderID

        var gcmConfig = GCMConfig.defaultConfig()
        gcmConfig.receiverDelegate = self
        GCMService.sharedInstance().startWithConfig(gcmConfig)

        return true
    }

    func applicationWillResignActive(application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
        GCMService.sharedInstance().disconnect()

        connectedToGCM = false
    }

    func applicationWillEnterForeground(application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

        // -->The app go through this point
        // Connect to the GCM server to receive non-APNS notifications
        GCMService.sharedInstance().connectWithHandler(gcmConnectionHandler)
        // -->The app go through this point
    }

    func gcmConnectionHandler(error: NSError?) {
        // -->The app never enter in this function
        if let error = error {
            print("Could not connect to GCM: \(error.localizedDescription)")
        } else {
            self.connectedToGCM = true
            print("Connected to GCM")
            // ...
        }
    }

    func applicationWillTerminate(application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
        self.saveContext()
    }

    func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {

        // Create a config and set a delegate that implements the GGLInstaceIDDelegate protocol.
        let instanceIDConfig = GGLInstanceIDConfig.defaultConfig()
        instanceIDConfig.delegate = self
        // Start the GGLInstanceID shared instance with that config and request a registration
        // token to enable reception of notifications
        GGLInstanceID.sharedInstance().startWithConfig(instanceIDConfig)
        gcmRegistrationOptions = [kGGLInstanceIDRegisterAPNSOption:deviceToken,
            kGGLInstanceIDAPNSServerTypeSandboxOption:true]
        GGLInstanceID.sharedInstance().tokenWithAuthorizedEntity(gcmSenderID,
            scope: kGGLInstanceIDScopeGCM, options: gcmRegistrationOptions, handler: gcmRegistrationHandler)

    }

    func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
        print("-- Failed to get deviceToken: \(error.localizedDescription)")
    }

    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
        application.applicationIconBadgeNumber += 1

        print(userInfo)
        let apsInfo = userInfo["aps"] as! NSDictionary

        var alertMessage = ""
        print("********************** Received Notif")

        if let alert = apsInfo["alert"] as? String{
            alertMessage = alert
            print(alertMessage)
        }
        else if let alert = apsInfo["alert"] as? NSDictionary, let body = alert["body"] as?  String {
            alertMessage = body
            print(alertMessage)
        }


        // If the application is currently on screen "Active" then we trigger a custom banner View for that notification to be shown
        // Else the system will handle that and put it in the notification center
        if application.applicationState == UIApplicationState.Active {
            AGPushNoteView.showWithNotificationMessage(alertMessage, autoClose: true, completion: { () -> Void in
                // Do nothing
            })
        }
    }


    func gcmRegistrationHandler(registrationToken: String!, error: NSError!) {
        if (registrationToken != nil) {
            self.gcmRegistrationToken = registrationToken
            print("GCM Registration Token: \(registrationToken)")
            let userInfo = ["registrationToken": registrationToken]
            NSNotificationCenter.defaultCenter().postNotificationName(
                self.gcmRegistrationKey, object: nil, userInfo: userInfo)
        } else {
          print("Registration to GCM failed with error: \(error.localizedDescription)")
            let userInfo = ["error": error.localizedDescription]
            NSNotificationCenter.defaultCenter().postNotificationName(self.gcmRegistrationKey, object: nil, userInfo: userInfo)
        }
    }

    // MARK: - GGLInstanceIDDelegate
    func onTokenRefresh() {
        // A rotation of the registration tokens is happening, so the app needs to request a new token.
        print("The GCM registration token needs to be changed.")
        GGLInstanceID.sharedInstance().tokenWithAuthorizedEntity(gcmSenderID,
            scope: kGGLInstanceIDScopeGCM, options: gcmRegistrationOptions, handler: gcmRegistrationHandler)
    }


    // MARK: - GCMReceiverDelegate
    func willSendDataMessageWithID(messageID: String!, error: NSError!) {
        if (error != nil) {
            // Failed to send the message.
        } else {
            // Will send message, you can save the messageID to track the message
        }
    }

    func didSendDataMessageWithID(messageID: String!) {
        // Did successfully send message identified by messageID
    }
    // [END upstream_callbacks]

    func didDeleteMessagesOnServer() {
        // Some messages sent to this device were deleted on the GCM server before reception, likely
        // because the TTL expired. The client should notify the app server of this, so that the app
        // server can resend those messages.
    }

    func subscribeToTopic() {
        // If the app has a registration token and is connected to GCM, proceed to subscribe to the
        // topic
        let subscriptionTopic = "/topics/test-global"
        if(gcmRegistrationToken != nil && connectedToGCM) {
            GCMPubSub.sharedInstance().subscribeWithToken(gcmRegistrationToken, topic: subscriptionTopic,
                options: nil, handler: {(NSError error) -> Void in
                    if (error != nil) {
                        // Treat the "already subscribed" error more gently
                        if error.code == 3001 {
                            print("Already subscribed to \(subscriptionTopic)")
                        } else {
                            print("Subscription failed: \(error.localizedDescription)");
                        }
                    } else {
                        subscribedToTopic = true;
                        NSLog("Subscribed to \(subscriptionTopic)");
                    }
            })
        }
    }


}

由此:

Cu.import('resource://gre/modules/ctypes.jsm');

然后使用nodejs(jpm init和jpm xpi命令)我创建了xpi文件但是这不能正常工作。

1 个答案:

答案 0 :(得分:1)

我们所做的是遵循jpm教程:https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Getting_Started_%28jpm%29https://developer.mozilla.org/en-US/Add-ons/SDK/Tools/jpm#Installation

我是在Windows系统上做到的:

  1. 我们下载了node.js
  2. npm随之而来
  3. 创建了一个目录,在这个目录中我从命令行执行了jpm-init
  4. 填写提示,然后填写插件的代码:
  5. 然后我们在这个演示插件中创建了一个类似的插件: https://github.com/Noitidart/jpm-chromeworker

    我无法分享实际插件,因为这对用户来说是个人的。但上述内容更简单,并说明了如何做到这一点。

    我们在chromeworker中完成了jsctypes,并通过消息传递与index.js进行通信