2013年3月17日日曜日

Firefox OS Simulator の画面サイズを変える

変えられますが、、、現状では使い物になりませぬ。

ABC 2013 Spring で @dynamis さんにコマンド引数で指定できるはず、ということを聞いたので調べてみた。

手元の Mac だと

/Users/[username]/Library/Application Support/Firefox/Profiles/vr2npksq.default/extensions/r2d2b2g@mozilla.org/resources/r2d2b2g/data/content/js/main.js

が Firefox OS Simulator のダッシュボードの js で、window の postMessage() でフックしてます。

  1. toggle: function() {  
  2.   $(this.toggler).prop('indeterminate'true);  
  3.   window.postMessage({ name: "toggle" }, "*");  
  4. },  


実際に Simulator のプロセス(b2g-bin)を起動してるのが

/Users/[username]/Library/Application Support/Firefox/Profiles/vr2npksq.default/extensions/r2d2b2g@mozilla.org/resources/r2d2b2g/lib/remote-simulator-client.js

です。

  1. ...  
  2.   // compute current b2g file handle  
  3.   get b2gExecutable() {  
  4.     if (this._executable) return this._executable;  
  5.   
  6.     let executables = {  
  7.       WINNT: "win32/b2g/b2g-bin.exe",  
  8.       Darwin: "mac64/B2G.app/Contents/MacOS/b2g-bin",  
  9.       Linux: (Runtime.XPCOMABI.indexOf("x86_64") == 0 ? "linux64" : "linux") +  
  10.         "/b2g/b2g-bin",  
  11.     };  
  12.   
  13.     let url = Self.data.url(executables[Runtime.OS]);  
  14.     let path = URL.toFilename(url);  
  15.   
  16.     let executable = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);      
  17.     executable.initWithPath(path);  
  18.     let executableFilename = executables[Runtime.OS];  
  19.   
  20.     // Support B2G binaries built without GAIADIR.  
  21.     if (!executable.exists()) {  
  22.       let executables = {  
  23.         WINNT: "win32/b2g/b2g.exe",  
  24.         Darwin: "mac64/B2G.app/Contents/MacOS/b2g",  
  25.         Linux: (Runtime.XPCOMABI.indexOf("x86_64") == 0 ? "linux64" : "linux") +  
  26.           "/b2g/b2g",  
  27.       };  
  28.       let url = Self.data.url(executables[Runtime.OS]);  
  29.       let path = URL.toFilename(url);  
  30.       executable.initWithPath(path);  
  31.       executableFilename = executables[Runtime.OS];  
  32.     }  
  33.   
  34.     this._executable = executable;  
  35.     this._executableFilename = executableFilename;  
  36.   
  37.     return executable;  
  38.   },  
  39.   
  40.   // compute b2g CLI arguments  
  41.   get b2gArguments() {  
  42.     let args = [];  
  43.   
  44.     let profile = URL.toFilename(profileURL);  
  45.     args.push("-profile", profile);  
  46.   
  47.     // NOTE: push dbgport option on the b2g-desktop commandline  
  48.     args.push("-dbgport"""+this.remoteDebuggerPort);  
  49.     args.push("-pbport"""+this.pingbackServerPort);  
  50.       
  51.     if (this.jsConsoleEnabled) {  
  52.       args.push("-jsconsole");  
  53.     }  
  54.   
  55.     //args.push("--screen=320x480@160");  
  56.     //args.push("--screen=480x800@240");  
  57.     //args.push("--screen=iphone");  
  58.     //args.push("--screen=tattoo");  
  59.     args.push("--screen=galaxy_nexus");  
  60.   
  61.   
  62.     if (this._defaultApp != null) {  
  63.       args.push("--runapp"this._defaultApp);  
  64.     }  
  65.   
  66.   
  67.     return args;  
  68.   },  
  69.   
  70. ...  
b2gArguments() がコマンドライン引数を設定しているところなので、 ここに
  1. args.push("--screen=320x480@160");  
とか追加すれば画面サイズを変えることができます。

注意:remote-simulator-client.js を変更したあと、Firefox を再起動する必要があります。

指定方法は

--screen=[width]x[height]@[resolution]

です。@[resolution]部分は省略できます。

ほかにもデバイス名で指定できるものもあって、https://developer.mozilla.org/ja/docs/Mozilla/Boot_to_Gecko/Using_the_B2G_desktop_client によると
  • iphone
  • ipad
  • nexus_s
  • galaxy_nexus
  • galaxy_tab
  • wildfire
  • tattoo
  • salsa
  • chacha
が指定できるそうです。いくつか(tattoo, iphone, nexus_s, galaxy_nexus)試してみましたがちゃんと画面サイズが変わりました。

HTC tattoo 持ってます。懐かしい。どこいったかな。。。



--screen=tattoo

レイアウト崩れます。。。





--screen=iphone

画面サイズを指定しない場合と同じっぽい





--screen=nexus_s

ホームボタンの部分が画面の途中にでて、ロック解除できません。。。





--screen=galaxy_nexus

nexus_s と同じような状態に。。。



ということで最初に指摘したとおり、全然使える状態ではありませんでした。。。



0 件のコメント:

コメントを投稿