preview.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // panel/index.js, this filename needs to match the one registered in package.json
  2. const version = Editor.remote.App.version.replace(/[.]/g,'')
  3. Editor.Panel.extend({
  4. // css style for panel
  5. style: `
  6. :host { margin: 5px; }
  7. h2 { color: #f90; }
  8. #games_view {width:100%; height:100%}
  9. `,
  10. // html template for panel
  11. template: `
  12. <webview id = "games_view" disablewebsecurity src=""> </webview>
  13. `,
  14. // element and variable binding
  15. $: {
  16. games_view: '#games_view',
  17. },
  18. // method executed when template and styles are successfully loaded and initialized
  19. ready () {
  20. setTimeout(()=>this.upPreview(),5000)
  21. },
  22. upPreview(){
  23. let url = 'http://localhost:7456/'
  24. if(document.getElementById("toolbar"))
  25. {
  26. url = 'http://'+document.getElementById("toolbar").__vue__.$data.url;
  27. }else if(document.getElementById("playButtons"))
  28. {
  29. url = 'http://'+document.getElementById("playButtons").dataHost.previewURL;
  30. }
  31. this.$games_view.src = url;
  32. window.preview = this.$games_view;
  33. // if(version>=200 && version<246){
  34. // return;
  35. // }
  36. // let id
  37. // id = setInterval(()=>{
  38. // if(preview.contentWindow && preview.contentWindow.cc){
  39. // clearInterval(id);
  40. // let log = preview.contentWindow.console.log
  41. // preview.contentWindow.console.log = (...args)=>{
  42. // Editor.log(...args);
  43. // }
  44. // let warn = preview.contentWindow.console.warn
  45. // preview.contentWindow.console.warn = (...args)=>{
  46. // Editor.warn(...args);
  47. // }
  48. // let error = preview.contentWindow.console.error
  49. // preview.contentWindow.console.error = (...args)=>{
  50. // Editor.error(...args);
  51. // }
  52. // preview.contentWindow.cc.log = preview.contentWindow.console.log
  53. // preview.contentWindow.cc.warn = preview.contentWindow.console.warn
  54. // preview.contentWindow.cc.error = preview.contentWindow.console.error
  55. // }
  56. // },500);
  57. // if(Editor.monaco){
  58. // Editor.monaco.preview = preview;
  59. // }
  60. },
  61. // register your ipc messages here
  62. messages: {
  63. 'refresh-preview' (event,msg) {
  64. this.upPreview()
  65. }
  66. }
  67. });