2018-03-10 23:22:59 +09:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								var electron = require("electron");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const fs = require("fs");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const os = require('os')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const shell = electron.shell;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const path = require('path')
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-19 16:39:30 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								function shot() {
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-10 23:22:59 +09:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    //screenshotMsg.textContent = 'Gathering screens...'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $(window).height
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-19 16:39:30 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let options = {
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-10 23:22:59 +09:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        types: ['screen'],
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        thumbnailSize: {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            width: window.parent.screen.width,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            height: window.parent.screen.height
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-19 16:39:30 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    const desktopCapturer = electron.desktopCapturer;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    desktopCapturer.getSources(options, function (error, sources) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        if (error) return console.log(error)
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-10 23:22:59 +09:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-19 16:39:30 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        sources.forEach(function (source) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            if (location.search) {
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-10 23:22:59 +09:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                var m = location.search.match(/\?id=([a-zA-Z-0-9]+)/);
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-19 16:39:30 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                var title = m[1];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            } else {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                var title = "screenshot";
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-10 23:22:59 +09:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-19 16:39:30 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (source.name === 'Screen 1' || source.name === 'TheDesk') {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                var durl = source.thumbnail.toDataURL();
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-10 23:22:59 +09:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                var b64 = durl.match(
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    /data:image\/png;base64,(.+)/
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                );
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                const screenshotPath = path.join(os.tmpdir(), 'screenshot.png');
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                const savePath = path.join(os.tmpdir(), 'screenshot.png');
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-19 16:39:30 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                var ipc = electron.ipcRenderer;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                var h = $(window).height() - 150;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                var w = $(window).width();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                ipc.send('shot', ['file://' + screenshotPath, w, h, b64[1], title]);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                if ($(".img-parsed").length > 0) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    for (i = 0; i < $(".img-parsed").length; i++) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        var url = $(".img-parsed").eq(i).attr("data-url");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                        ipc.send('shot-img-dl', [url, title + "_img" + i + ".png"]);
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-10 23:22:59 +09:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                    }
							 | 
						
					
						
							
								
									
										
										
										
											2019-05-19 16:39:30 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                window.close();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                return;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                const message = `Saved screenshot to: ${screenshotPath}`
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                //screenshotMsg.textContent = message
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    })
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |