-
-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathNativeApp.js
More file actions
137 lines (118 loc) · 4.31 KB
/
NativeApp.js
File metadata and controls
137 lines (118 loc) · 4.31 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* 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.
*
*/
// @INCLUDE_IN_API_DOCS
/**
* Virtualized NativeApp apis that works cross-platform, and in the browser.
*/
define(function (require, exports, module) {
var Async = require("utils/Async"),
FileSystemError = require("filesystem/FileSystemError");
/**
* Map an fs error code to a FileError.
*
* @private
*/
function _browserErrToFileError(err) {
if (err === brackets.fs.ERR_CODES.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.
*
* @param {string} url
* @param {string?} tabIdentifier - An optional tab identifier can be set to group the tabs. Maps to target option
* in browser. Doesn't do anything in tauri.
*/
function openURLInDefaultBrowser(url, tabIdentifier) {
return brackets.app.openURLInDefaultBrowser(url, tabIdentifier);
}
/**
* Gets the path to the application's support directory
*/
function getApplicationSupportDirectory() {
return brackets.app.getApplicationSupportDirectory();
}
// Define public API
exports.openLiveBrowser = openLiveBrowser;
exports.closeLiveBrowser = closeLiveBrowser;
exports.closeAllLiveBrowsers = closeAllLiveBrowsers;
exports.getApplicationSupportDirectory = getApplicationSupportDirectory;
exports.openURLInDefaultBrowser = openURLInDefaultBrowser;
});