SessionManagerを使ってセッションを保存・復元する

アドオンのSessionManagerの機能を使って、セッションの保存と復元をするコマンド。

SessionManagerのコードはさらっとしか読んでいないので、副作用があるかもしれませんが。

(function(){
    if(!gSessionManager) return;

    commands.addUserCommand(
        ["mks[eesion]"],
        "Save a session.",
        function(args){
            try{
                gSessionManager.save(args[0], args[0] + ".session");
                liberator.echo("Saved session: "+ args[0]);
            }catch(e){
                liberator.echoerr(e);
            }
        },
        {}, true);

    commands.addUserCommand(
        ["loads[ession]"],
        "Restore a session.",
        function(args){
            gSessionManager.load(args[0], "overwrite");
        },
        {
            completer: function(context, arg){
                context.title = ["Session file name", "Saved time"];
                var files = liberator.modules.io.readDirectory(gSessionManager.getSessionDir());
                compl = [];
                files.forEach(function(f){
                    compl.push([f.leafName, new Date(f.lastModifiedTime)]);
                });
                context.completions = compl;
            }
        }, true);
})();