const { dialog } = require('electron');
exports.showOpenDialogSync = (data) => {
    try {
		let PathRet = dialog.showOpenDialogSync({
			properties: ["openDirectory"],
			title: data["名称"],
			defaultPath: data["路径"],
			buttonLabel: '确认选择'
		});
		return PathRet;
	} catch (err) {
		return "";
	}
}
exports.showOpenDialogSyncFile = (data) => {
    try {
		let type = data["类型"];
		if(type==2){
			let PathRet = dialog.showOpenDialogSync({
				properties: ["openDirectory"],
				title: data["标题"],
				defaultPath: data["路径"],
				buttonLabel: data["按钮标题"]
			});
			return PathRet;
		}else{
			let filters = [];
			for (let index = 0; index < data["过滤器"].length; index++) {
				filters[filters.length] = { name: data["过滤器"][index]["名称"], extensions: data["过滤器"][index]["类型"] }
			}
			if (filters.length >= 1) {
				type = ["openFile"]
				let PathRet = dialog.showOpenDialogSync({
					properties: type,
					defaultPath: data["路径"],
					title: data["标题"],
					buttonLabel: data["按钮标题"],
					filters: filters
				})
				return PathRet;
			} else {
				return [];
			}
		}
	} catch (err) {
		return [];
	}
}