📄 updatemanager.as
字号:
package com.teknision.flex.air.autoupdate
{
import com.teknision.flex.air.autoupdate.events.*;
import com.teknision.flex.air.autoupdate.update.*;
import com.teknision.flex.air.autoupdate.window.*;
import com.teknision.flex.air.window.*;
import com.teknision.flex.air.window.events.*;
import flash.display.*;
import flash.events.Event;
import flash.filesystem.*;
import flash.geom.Point;
import flash.system.*;
import mx.core.WindowedApplication;
public class UpdateManager
{
private var __startupinfo:VersionChecker=new VersionChecker();
private var __app:WindowedApplication;
private var __pt:Point;
private var __updateScreen:Object;
public function UpdateManager(){
super();
}
public function run(app:WindowedApplication,updateURL:String,updateScreen:Object,pt:Point=null):void{
if(pt == null){
pt = new Point(400,200);
}
__app = app;
__updateScreen = updateScreen;
__pt = pt;
this.__startupinfo.addEventListener(Event.COMPLETE,handleStartupInfo);
this.__startupinfo.addEventListener(VersionChecker.UPDATENEEDED,handleUpdateNeeded);
// this.__startupinfo.run("http://www.preview.teknision.com/public/personal/Mike/updater/update_example.xml");
this.__startupinfo.run(updateURL);
}
private function handleStartupInfo(event:Event):void{
}
private function handleSubordinateWindowComplete(event:Event):void{
}
private function launchUpdateScreen():SubordinateWindow{
var options:SubordinateWindowOptions=new SubordinateWindowOptions("Finetune Desktop Update",__updateScreen,__pt);
// var options:SubordinateWindowOptions=new SubordinateWindowOptions("Finetune Desktop Update","com/teknision/air/controls/autoUpdate/screens/FinetuneDesktopUpdateScreen.swf",pt);
options.mainapp_visible=false;
options.closeevent=SubordinateWindowEvent.CLOSE;
var win:UpdateWindow=this.getSubordinateWindow(options,new UpdateWindow(options)) as UpdateWindow;
win.startupinfo=this.__startupinfo;
win.addEventListener(UpdateWindow.UPDATEBYPASSED,handleUpdateWindowBypass);
win.addEventListener(UpdateWindow.UPDATEEXECUTE,handleUpdateWindowExecute);
this.centerWindowOnScreen(win);
return win;
}
private function handleUpdateNeeded(event:Event):void{
this.launchUpdateScreen();
}
private function handleUpdateWindowExecute(event:Event):void{
var item:VersionNumber=this.__startupinfo.remoteversions[0];
if(item.location!=null){
var file:File=File.applicationStorageDirectory.resolvePath("updates/finetunedesktop.air");
var url:String=item.location;
TekUpdater.get().run(url,file,this.__startupinfo.latestversion.getVersionString());
}
}
private function centerWindowOnScreen(win:SubordinateWindow):void{
var max_w:Number=Capabilities.screenResolutionX;
var max_h:Number=Capabilities.screenResolutionY;
var win_w:Number=win.window.width;
var win_h:Number=win.window.height;
var pos_x:Number=(max_w/2)-(win_w/2);
var pos_y:Number=(max_h/2)-(win_h/2);
win.window.x=pos_x;
win.window.y=pos_y;
}
private function handleUpdateWindowBypass(event:Event):void{
// this.runInitBootstrapStep(InitSteps.STARTUPDATA);
}
private function getSubordinateWindow(i_options:SubordinateWindowOptions,i_win:SubordinateWindow=null):SubordinateWindow{
if(i_options.mainapp_enabled==false){
__app.enabled=false;
}
if(i_options.mainapp_visible==false){
this.showAppWindow(false);
}
var newWin:SubordinateWindow;
if(i_win==null){
newWin=new SubordinateWindow(i_options);
}else{
newWin=i_win;
}
newWin.addEventListener(SubordinateWindowEvent.APP,handleSubordinateWindowEvent);
newWin.addEventListener(SubordinateWindowEvent.CLOSE,handleSubordinateWindowEvent);
newWin.addEventListener(SubordinateWindowEvent.MANUAL,handleSubordinateWindowEvent);
newWin.addEventListener(Event.COMPLETE,handleSubordinateWindowComplete);
newWin.launch();
return newWin;
}
private function handleSubordinateWindowEvent(event:SubordinateWindowEvent):void{
var target:SubordinateWindow=event.target as SubordinateWindow;
var options:SubordinateWindowOptions=target.options;
if(event.type==SubordinateWindowEvent.APP){
target.removeEventListener(SubordinateWindowEvent.APP,handleSubordinateWindowEvent);
if(options.mainapp_enabled==false){
__app.enabled=true;
}
if(options.mainapp_visible==false){
this.showAppWindow(true);
}
if(options.centerapp_onclose==true){
try{
this.centerAppUnderWindow(target);
}catch(e:Error){
}
}
target.window.close();
}else if(event.type==SubordinateWindowEvent.CLOSE){
trace("Exiting App!");
target.removeEventListener(SubordinateWindowEvent.CLOSE,handleSubordinateWindowEvent);
target.window.close();
//Shell.shell.exit();
__app.exit();
}else if(event.type==SubordinateWindowEvent.MANUAL){
trace("EXIT MANUAL");
target.removeEventListener(SubordinateWindowEvent.MANUAL,handleSubordinateWindowEvent);
target.window.close();
__app.visible = true;
}
}
//centers a secondary popup window underneath the main app
private function centerAppUnderWindow(i_win:SubordinateWindow):void{
var a_win:NativeWindow=i_win.window;
var appx:Number=a_win.x;
var appy:Number=a_win.y;
var appw:Number=a_win.width;
var apph:Number=a_win.height;
var appcenterx:Number=appx+(appw/2);
var appcentery:Number=appy+(apph/2);
var i_win_x:Number=appcenterx-(__app.stage.nativeWindow.width/2);
var i_win_y:Number=appcentery-(__app.stage.nativeWindow.height/2);
__app.stage.nativeWindow.x=i_win_x;
__app.stage.nativeWindow.y=i_win_y;
}
public function showAppWindow(val:Boolean=true):void{
//if(val){
//Application.application.windowVisible=true;
//}
__app.stage.nativeWindow.visible=val;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -