Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:cables-gl/cables_electron into d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
pandrr committed Sep 11, 2024
2 parents 96bb8cd + e67bac7 commit 4b5303f
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 23 deletions.
2 changes: 1 addition & 1 deletion cables.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"env": "dev",
"minifyJs": true,
"communityUrl": "https://cables.gl/",
"communityUrl": "https://cables.gl",
"sourcePath": {
"libs": "../../shared/libs/",
"corelibs": "../../cables/build/libs/",
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<html lang="en-US">
<head>
<base href="./dist/ui/">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"/>
<script>
window.nodeRequire = require;
Expand Down
75 changes: 58 additions & 17 deletions src/electron/electron_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class ElectronApi

getOpInfo(data)
{
const name = opsUtil.getOpNameById(data.opName) || data.opName;
const opName = opsUtil.getOpNameById(data.opName) || data.opName;

let warns = [];
try
Expand All @@ -140,12 +140,30 @@ class ElectronApi
});
}

warns = warns.concat(opsUtil.getOpCodeWarnings(name));
warns = warns.concat(opsUtil.getOpCodeWarnings(opName));

if (opsUtil.isOpNameValid(name))
if (opsUtil.isOpNameValid(opName))
{
const result = { "warns": warns };
result.attachmentFiles = opsUtil.getAttachmentFiles(name);
result.attachmentFiles = opsUtil.getAttachmentFiles(opName);

const opDocs = doc.getDocForOp(opName);
let changelogEntries = [];
if (opDocs && opDocs.changelog)
{
// copy array to not modify reference
changelogEntries = changelogEntries.concat(opDocs.changelog);
if (data.sort === "asc")
{
changelogEntries.sort((a, b) => { return a.date - b.date; });
}
else
{
changelogEntries.sort((a, b) => { return b.date - a.date; });
}
const numChangelogEntries = data.cl || 5;
result.changelog = changelogEntries.slice(0, numChangelogEntries);
}
return this.success("OK", result, true);
}
else
Expand All @@ -157,7 +175,7 @@ class ElectronApi
}
catch (e)
{
this._log.warn("error when getting opinfo", name, e.message);
this._log.warn("error when getting opinfo", opName, e.message);
const result = { "warns": warns };
result.attachmentFiles = [];
return this.success("OK", result, true);
Expand Down Expand Up @@ -841,7 +859,8 @@ class ElectronApi

opUpdate(data)
{
const opName = data.opname;
let opName = data.opname;
if (opsUtil.isOpId(data.opname)) opName = opsUtil.getOpNameById(data.opname);
const currentUser = settings.getCurrentUser();
return this.success("OK", { "data": opsUtil.updateOp(currentUser, opName, data.update, { "formatCode": data.formatCode }) }, true);
}
Expand Down Expand Up @@ -1078,15 +1097,24 @@ class ElectronApi

async selectFile(data)
{
if (data && data.url)
if (data)
{
let assetUrl = helper.fileURLToPath(data.url, true);
let filter = ["*"];
if (data.filter)
let pickedFileUrl = null;
if (data.url)
{
filter = filesUtil.FILETYPES[data.filter] || ["*"];
let assetUrl = helper.fileURLToPath(data.url, true);
let filter = ["*"];
if (data.filter)
{
filter = filesUtil.FILETYPES[data.filter] || ["*"];
}
pickedFileUrl = await electronApp.pickFileDialog(assetUrl, true, filter);
}
else
{
let file = data.dir;
pickedFileUrl = await electronApp.pickFileDialog(file);
}
const pickedFileUrl = await electronApp.pickFileDialog(assetUrl, true, filter);
return this.success("OK", pickedFileUrl, true);
}
else
Expand All @@ -1095,6 +1123,12 @@ class ElectronApi
}
}

async selectDir(data)
{
const pickedFileUrl = await electronApp.pickDirDialog(data.dir);
return this.success("OK", pickedFileUrl, true);
}


checkNumAssetPatches()
{
Expand Down Expand Up @@ -1190,16 +1224,22 @@ class ElectronApi
{
const now = Date.now();
const project = settings.getCurrentProject();
let data = {};
if (project)
{
const projectFile = settings.getCurrentProjectFile();
project.updated = now;
const projectFile = settings.getCurrentProjectFile();
if (projectFile)
{
projectsUtil.writeProjectToFile(projectFile, project);
}
data = project;
}
else
{
data.updated = now;
}
return this.success("OK", project);
return this.success("OK", data);
}

getProjectOpDirs()
Expand Down Expand Up @@ -1489,9 +1529,10 @@ class ElectronApi

async createFile(data)
{
data.fileName = data.name;
data.content = "this is an empty file...";
return this.updateFile(data);
let file = data.name;
let pickedFileUrl = await electronApp.saveFileDialog(file);
if (pickedFileUrl && !fs.existsSync(pickedFileUrl)) fs.writeFileSync(pickedFileUrl, "");
return this.success("OK", pickedFileUrl, true);
}

async exportPatch()
Expand Down
37 changes: 34 additions & 3 deletions src/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,35 @@ class ElectronApp
return this._fileDialog(title, filePath, asUrl, filter, properties);
}

async saveFileDialog(defaultPath, title = null, properties = [], filters = [])
{
title = title || "select directory";
properties = properties || ["createDirectory"];
return dialog.showSaveDialog(this.editorWindow, {
"title": title,
"defaultPath": defaultPath,
"properties": properties,
"filters": filters
}).then((result) =>
{
if (!result.canceled)
{
return result.filePath;
}
else
{
return null;
}
});
}

async pickDirDialog(defaultPath = null)
{
let title = "select file";
let properties = ["openDirectory", "createDirectory"];
return this._dirDialog(title, properties, defaultPath);
}

async exportProjectFileDialog(exportName)
{
const extensions = [];
Expand Down Expand Up @@ -553,12 +582,14 @@ class ElectronApp
this.editorWindow.setTitle(title);
}

_dirDialog(title, properties)
_dirDialog(title, properties, defaultPath = null)
{
return dialog.showOpenDialog(this.editorWindow, {
const options = {
"title": title,
"properties": properties
}).then((result) =>
};
if (defaultPath) options.defaultPath = defaultPath;
return dialog.showOpenDialog(this.editorWindow, options).then((result) =>
{
if (!result.canceled)
{
Expand Down
4 changes: 2 additions & 2 deletions src/utils/ops_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class OpsUtil extends SharedOpsUtil

isCoreOp(opName)
{
const opsDir = this._cables.getOpsPath();
const opsDir = this._cables.getCoreOpsPath();
const opDir = this.getOpSourceDir(opName);
return opDir.includes(opsDir);
return opDir.startsWith(opsDir);
}

addPermissionsToOps(opDocs, user, teams = [], project = null)
Expand Down
1 change: 1 addition & 0 deletions src_client/electron_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export default class ElectronEditor
"openDir": {},
"createFile": {},
"selectFile": {},
"selectDir": {},
"setProjectName": { "needsProjectFile": true },
"collectAssets": { "needsProjectFile": true },
"collectOps": { "needsProjectFile": true },
Expand Down
1 change: 1 addition & 0 deletions src_client/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export default class CablesStandalone
"platformClass": "PlatformStandalone",
"urlCables": "cables://",
"urlSandbox": "cables://",
"communityUrl": this._config.communityUrl,
"user": this._settings.currentUser,
"usersettings": { "settings": this._usersettings },
"isDevEnv": !this._config.isPackaged,
Expand Down

0 comments on commit 4b5303f

Please sign in to comment.