Advertisement
SpeakeazyYT

Untitled

Aug 12th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var windows = [];
  2.  
  3. /**
  4.  * Resets the windows and removes
  5.  * any interval that is running
  6.  */
  7. function reset() {
  8.  
  9.   windows.forEach( function (w) {
  10.     w.contentWindow.close();
  11.   } );
  12.  
  13.   windows.length = 0;
  14. }
  15.  
  16. /**
  17.  * Initialise and launch the windows
  18.  * @see http://developer.chrome.com/apps/app.window.html
  19.  */
  20. function launch() {
  21.  
  22.   // reset everything
  23.   reset();
  24.  
  25.   // create the original window
  26.   chrome.app.window.create('original.html', {
  27.       id: "mainwin",
  28.       innerBounds: {
  29.         top: 128,
  30.         left: 128,
  31.         width: 300,
  32.         height: 300,
  33.         minHeight: 300,
  34.         maxWidth: 500,
  35.         minWidth: 300
  36.       },
  37.       frame: 'none'
  38.     },
  39.  
  40.     // when that is created store it
  41.     // and create the copycat window
  42.     function(originalWindow) {
  43.  
  44.       windows.push(originalWindow);
  45.  
  46.       chrome.app.window.create('copycat.html', {
  47.         id: "copywin",
  48.         innerBounds: {
  49.           top: 128,
  50.           left: 428 + 5,
  51.           width: 300,
  52.           height: 300,
  53.           minHeight: 300,
  54.           maxWidth: 500,
  55.           minWidth: 300
  56.         },
  57.         frame: 'none'
  58.       },
  59.  
  60.       function(copycatWindow) {
  61.  
  62.         // store the copycat
  63.         windows.push(copycatWindow);
  64.  
  65.         // now have the copycat watch the
  66.         // original window for changes
  67.         originalWindow.onClosed.addListener(reset);
  68.         copycatWindow.onClosed.addListener(reset);
  69.  
  70.         originalWindow.onBoundsChanged.addListener(function() {
  71.           var bounds = originalWindow.outerBounds;
  72.           copycatWindow.outerBounds.left = bounds.left + bounds.width + 5;
  73.         });
  74.  
  75.         copycatWindow.onRestored.addListener(function() {
  76.           console.log('copy restored');
  77.           if (originalWindow.isMinimized())
  78.             originalWindow.restore();
  79.         })
  80.  
  81.         originalWindow.onRestored.addListener(function() {
  82.           console.log('copy restored');
  83.           if (copycatWindow.isMinimized())
  84.             copycatWindow.restore();
  85.         })
  86.  
  87.         originalWindow.focus();
  88.       });
  89.   });
  90. }
  91.  
  92. /**
  93.  * Minimises both the original and copycat windows
  94.  * @see http://developer.chrome.com/apps/app.window.html
  95.  */
  96. function minimizeAll() {
  97.  
  98.   windows.forEach( function (w) {
  99.     w.minimize();
  100.   });
  101. }
  102.  
  103. // @see http://developer.chrome.com/apps/app.runtime.html
  104. chrome.app.runtime.onLaunched.addListener(launch);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement