Repository navigation
Expand file tree
/
Copy pathNativeApp.js
More file actions
116 lines (100 loc) · 3.66 KB
/
Copy pathNativeApp.js
File metadata and controls
116 lines (100 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* GNU AGPL-3.0 License
*
* Copyright (c) 2021 - present core.ai . All rights reserved.
* Original work Copyright (c) 2012 - 2021 Adobe Systems Incorporated. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
*
*/
define(function (require, exports, module) {
var Async = require("utils/Async"),
FileSystemError = require("filesystem/FileSystemError");
/**
* @private
* Map an fs error code to a FileError.
*/
function _browserErrToFileError(err) {
if (err === brackets.fs.ERR_NOT_FOUND) {
return FileSystemError.NOT_FOUND;
}
// All other errors are mapped to the generic "unknown" error
return FileSystemError.UNKNOWN;
}
var liveBrowserOpenedPIDs = [];
/** openLiveBrowser
* Open the given URL in the user's system browser, optionally enabling debugging.
* @param {string} url The URL to open.
* @param {boolean=} enableRemoteDebugging Whether to turn on remote debugging. Default false.
* @return {$.Promise}
*/
function openLiveBrowser(url, enableRemoteDebugging) {
var result = new $.Deferred();
brackets.app.openLiveBrowser(url, !!enableRemoteDebugging, function onRun(err, pid) {
if (!err) {
// Undefined ids never get removed from list, so don't push them on
if (pid !== undefined) {
liveBrowserOpenedPIDs.push(pid);
}
result.resolve(pid);
} else {
result.reject(_browserErrToFileError(err));
}
});
return result.promise();
}
/** closeLiveBrowser
*
* @return {$.Promise}
*/
function closeLiveBrowser(pid) {
var result = new $.Deferred();
if (isNaN(pid)) {
pid = 0;
}
brackets.app.closeLiveBrowser(function (err) {
if (!err) {
var i = liveBrowserOpenedPIDs.indexOf(pid);
if (i !== -1) {
liveBrowserOpenedPIDs.splice(i, 1);
}
result.resolve();
} else {
result.reject(_browserErrToFileError(err));
}
}, pid);
return result.promise();
}
/** closeAllLiveBrowsers
* Closes all the browsers that were tracked on open
* TODO: does not seem to work on Windows
* @return {$.Promise}
*/
function closeAllLiveBrowsers() {
//make a copy incase the array is edited as we iterate
var closeIDs = liveBrowserOpenedPIDs.concat();
return Async.doSequentially(closeIDs, closeLiveBrowser, false);
}
/**
* Opens a URL in the system default browser
*/
function openURLInDefaultBrowser(url) {
brackets.app.openURLInDefaultBrowser(url);
}
// Define public API
exports.openLiveBrowser = openLiveBrowser;
exports.closeLiveBrowser = closeLiveBrowser;
exports.closeAllLiveBrowsers = closeAllLiveBrowsers;
exports.openURLInDefaultBrowser = openURLInDefaultBrowser;
});