import win.reg;
import web.json;

import web.nativeMessaging;
namespace web.nativeMessaging;

class install{
	ctor( param){
		if(!param.name) error("参数中必须用name字段指定应用名称",2);
		param.type = "stdio";
		
		allowed_origins = param.allowed_origins;
		for(k,v in allowed_origins){
			 if(!..string.startWith(v,"chrome-extension://",true) )
			 	allowed_origins[k] = ..string.format("chrome-extension://%s/",v)
		}
		
		
		if(!param.path) param.path = ..io._exepath; 
		var json = ..web.json.stringify(param,true,true);
		var jsonPath = ..io.getSpecial(0x1a /*_CSIDL_APPDATA*/,"/aardio/chrome/nativeMessaging/" +param.name +"-manifest.json")
		..string.save(jsonPath,json)
		
		var reg = ..win.reg("HKEY_CURRENT_USER\SOFTWARE\Google\Chrome\NativeMessagingHosts\" + param.name);
		reg.setSzValue("",..io.fullpath(jsonPath))
		
		return json;
	}; 
}

/**intellisense()
web.nativeMessaging.install = @.install(\n	name = "com.my_company.my_application";\n	path = "不写这个属性会自动设置为当前EXE文件路径";\n	description = "应用描述";\n	allowed_origins = {\n		  "__/*授权与本地消息主机进行通信的Chrome浏览器扩展ID\n可用不用写chrome-extension:只要写ID就可以*/";\n	}\n)
end intellisense**/
