Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/fix zxp extension 1.0.13 #708

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified openpype/hosts/photoshop/api/extension.zxp
Binary file not shown.
2 changes: 1 addition & 1 deletion openpype/hosts/photoshop/api/extension/CSXS/manifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<ExtensionManifest ExtensionBundleId="com.openpype.PS.panel" ExtensionBundleVersion="1.0.12" Version="7.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ExtensionManifest ExtensionBundleId="com.openpype.PS.panel" ExtensionBundleVersion="1.0.13" Version="7.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ExtensionList>
<Extension Id="com.openpype.PS.panel" Version="1.0.1" />
</ExtensionList>
Expand Down
122 changes: 70 additions & 52 deletions openpype/hosts/photoshop/api/extension/client/client.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
// client facing part of extension, creates WSRPC client (jsx cannot
// client facing part of extension, creates WSRPC client (jsx cannot
// do that)
// consumes RPC calls from server (OpenPype) calls ./host/index.jsx and
// returns values back (in json format)

var logReturn = function(result){ log.warn('Result: ' + result);};

var csInterface = new CSInterface();

log.warn("script start");

WSRPC.DEBUG = false;
WSRPC.TRACE = false;

function myCallBack(){
log.warn("Triggered index.jsx");
}
// importing through manifest.xml isn't working because relative paths
// possibly TODO
jsx.evalFile('./host/index.jsx', myCallBack);

function runEvalScript(script) {
// because of asynchronous nature of functions in jsx
// this waits for response
return new Promise(function(resolve, reject){
csInterface.evalScript(script, resolve);
});
}

/** main entry point **/
startUp("WEBSOCKET_URL");

// get websocket server url from environment value
async function startUp(url){
log.warn("url", url);
log.warn("url", url);
promis = runEvalScript("getEnv('" + url + "')");
var res = await promis;

var res = await promis;
// run rest only after resolved promise
main(res);
}
Expand All @@ -45,15 +45,15 @@
log.debug("get_extension_version")
var path = csInterface.getSystemPath(SystemPath.EXTENSION);
log.debug("extension path " + path);

var result = window.cep.fs.readFile(path + "/CSXS/manifest.xml");
var version = undefined;
if(result.err === 0){
if (window.DOMParser) {
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(result.data.toString(), 'text/xml');
const children = xmlDoc.children;

for (let i = 0; i <= children.length; i++) {
if (children[i] && children[i].getAttribute('ExtensionBundleVersion')) {
version = children[i].getAttribute('ExtensionBundleVersion');
Expand All @@ -63,22 +63,22 @@
}
return version
}

function main(websocket_url){
// creates connection to 'websocket_url', registers routes
log.warn("websocket_url", websocket_url);
// creates connection to 'websocket_url', registers routes
log.warn("websocket_url", websocket_url);
var default_url = 'ws://localhost:8099/ws/';

if (websocket_url == ''){
websocket_url = default_url;
}
log.warn("connecting to:", websocket_url);
log.warn("connecting to:", websocket_url);
RPC = new WSRPC(websocket_url, 5000); // spin connection

RPC.connect();
log.warn("connected");

log.warn("connected");

function EscapeStringForJSX(str){
// Replaces:
// \ with \\
Expand All @@ -87,7 +87,7 @@
// See: https://stackoverflow.com/a/3967927/5285364
return str.replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/"/g, '\\"');
}

RPC.addRoute('Photoshop.open', function (data) {
log.warn('Server called client route "open":', data);
var escapedPath = EscapeStringForJSX(data.path);
Expand All @@ -97,7 +97,7 @@
return result;
});
});

RPC.addRoute('Photoshop.read', function (data) {
log.warn('Server called client route "read":', data);
return runEvalScript("getHeadline()")
Expand All @@ -106,7 +106,7 @@
return result;
});
});

RPC.addRoute('Photoshop.get_layers', function (data) {
log.warn('Server called client route "get_layers":', data);
return runEvalScript("getLayers()")
Expand All @@ -115,7 +115,16 @@
return result;
});
});


RPC.addRoute('Photoshop.set_blendmode', function (data) {
log.warn('Server called client route "set_blendmode":', data);
return runEvalScript("setBlendmode(" + "'" + data.layer_name + "', " + "'" +data.blendMode_name + "')")
.then(function(result){
log.warn("setBlendmode: " + result);
return result;
});
});

RPC.addRoute('Photoshop.set_visible', function (data) {
log.warn('Server called client route "set_visible":', data);
return runEvalScript("setVisible(" + data.layer_id + ", " +
Expand All @@ -125,17 +134,17 @@
return result;
});
});

RPC.addRoute('Photoshop.get_active_document_name', function (data) {
log.warn('Server called client route "get_active_document_name":',
log.warn('Server called client route "get_active_document_name":',
data);
return runEvalScript("getActiveDocumentName()")
.then(function(result){
log.warn("save: " + result);
return result;
});
});

RPC.addRoute('Photoshop.get_active_document_full_name', function (data) {
log.warn('Server called client route ' +
'"get_active_document_full_name":', data);
Expand All @@ -145,49 +154,49 @@
return result;
});
});

RPC.addRoute('Photoshop.save', function (data) {
log.warn('Server called client route "save":', data);

return runEvalScript("save()")
.then(function(result){
log.warn("save: " + result);
return result;
});
});

RPC.addRoute('Photoshop.get_selected_layers', function (data) {
log.warn('Server called client route "get_selected_layers":', data);

return runEvalScript("getSelectedLayers()")
.then(function(result){
log.warn("get_selected_layers: " + result);
return result;
});
});

RPC.addRoute('Photoshop.create_group', function (data) {
log.warn('Server called client route "create_group":', data);

return runEvalScript("createGroup('" + data.name + "')")
.then(function(result){
log.warn("createGroup: " + result);
return result;
});
});

RPC.addRoute('Photoshop.group_selected_layers', function (data) {
log.warn('Server called client route "group_selected_layers":',
log.warn('Server called client route "group_selected_layers":',
data);

return runEvalScript("groupSelectedLayers(null, "+
"'" + data.name +"')")
.then(function(result){
log.warn("group_selected_layers: " + result);
return result;
});
});

RPC.addRoute('Photoshop.import_smart_object', function (data) {
log.warn('Server called client "import_smart_object":', data);
var escapedPath = EscapeStringForJSX(data.path);
Expand All @@ -199,7 +208,7 @@
return result;
});
});

RPC.addRoute('Photoshop.replace_smart_object', function (data) {
log.warn('Server called route "replace_smart_object":', data);
var escapedPath = EscapeStringForJSX(data.path);
Expand All @@ -211,7 +220,7 @@
return result;
});
});

RPC.addRoute('Photoshop.delete_layer', function (data) {
log.warn('Server called route "delete_layer":', data);
return runEvalScript("deleteLayer("+data.layer_id+")")
Expand All @@ -221,6 +230,15 @@
});
});

RPC.addRoute('Photoshop.rename_layers', function (data) {
log.warn('Server called route "rename_layers":', data);
return runEvalScript("renameLayers('"+data.layers+"')")
.then(function(result){
log.warn("rename_layers: " + result);
return result;
});
});

RPC.addRoute('Photoshop.rename_layer', function (data) {
log.warn('Server called route "rename_layer":', data);
return runEvalScript("renameLayer("+data.layer_id+", " +
Expand All @@ -229,40 +247,40 @@
log.warn("rename_layer: " + result);
return result;
});
});
});

RPC.addRoute('Photoshop.select_layers', function (data) {
log.warn('Server called client route "select_layers":', data);

return runEvalScript("selectLayers('" + data.layers +"')")
.then(function(result){
log.warn("select_layers: " + result);
return result;
});
});

RPC.addRoute('Photoshop.is_saved', function (data) {
log.warn('Server called client route "is_saved":', data);

return runEvalScript("isSaved()")
.then(function(result){
log.warn("is_saved: " + result);
return result;
});
});

RPC.addRoute('Photoshop.saveAs', function (data) {
log.warn('Server called client route "saveAsJPEG":', data);
var escapedPath = EscapeStringForJSX(data.image_path);
return runEvalScript("saveAs('" + escapedPath + "', " +
"'" + data.ext + "', " +
"'" + data.ext + "', " +
data.as_copy + ")")
.then(function(result){
log.warn("save: " + result);
return result;
});
});

RPC.addRoute('Photoshop.imprint', function (data) {
log.warn('Server called client route "imprint":', data);
var escaped = data.payload.replace(/\n/g, "\\n");
Expand All @@ -282,19 +300,19 @@
log.warn('Server called client route "close":', data);
return runEvalScript("close()");
});

RPC.call('Photoshop.ping').then(function (data) {
log.warn('Result for calling server route "ping": ', data);
return runEvalScript("ping()")
.then(function(result){
log.warn("ping: " + result);
return result;
});

}, function (error) {
log.warn(error);
});

}

log.warn("end script");
Binary file removed openpype/hosts/photoshop/api/extension/extension.zxp
Binary file not shown.
Loading