Chrome Packaged app, Always on top window

喜你入骨 提交于 2019-12-18 12:09:20

问题


i am writing a text editor, i need the app window be always on top when switching to browser or e-book reader software. as i know ,for windows users, chrome doesn't provide any solution. is there any parameter to send when creating window to make window always on top?

or can i provide any button in app to turn this feature on or off?

Code i use to create window in bg.js:

var launch = function () {
chrome.app.window.create('index.html', {
  type: 'shell',
  width: 440,
  height: 680,
  minWidth: 440,
  maxHeight: 680,
  id: 'paat-start'
});
};
chrome.app.runtime.onLaunched.addListener(launch);
chrome.commands.onCommand.addListener(launch);

thank for any suggestion.


回答1:


As Ben Wells mentioned above, this feature is now available in the stable release (either v33 or v34) via the alwaysOnTop option in chrome.app.windows.create. Note that special permissions are required in the manifest.json file. Example:

background.js
chrome.app.window.create('window.html', {
  alwaysOnTop: true,
}, function (appWindow) {
  // Window created and will remain on top of others.

  // Change the property programmatically via:
  //appWindow.setAlwaysOnTop();
});
manifest.json
"permissions": [
  "alwaysOnTopWindows"
]

This seems to have been added in issue 26427002, gone stable in issue 159523002 and issue 48113024 thanks to the community!


I had looked into this a while back and wanted to catalog my findings since historically there were some discrepancies in the documentation which previously stated the name of the required permission was alwaysOnTop, but using this caused a "permission is unknown" error.

Reading through the original proposal for this feature lead me to issue 326361 which mentions the permission setting is actually called alwaysOnTopWindows. Using this one back then, however, yielded a "requires Google Chrome dev channel or newer" error (probably since the feature wasn't yet stable).

I did find it peculiar from browsing the source code, these two permissions might be aliases of each other, but that might be because I don't fully understand the Chromium codebase.




回答2:


chrome.app.window.create does support a boolean alwaysOnTop option in more recent versions of Chrome. The feature is currently in beta channel on most platforms and at least dev channel on the rest.



来源:https://stackoverflow.com/questions/19960076/chrome-packaged-app-always-on-top-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!