From 93289969f399a50540b06fe731a489d4b1128ae7 Mon Sep 17 00:00:00 2001 From: neauoire Date: Sun, 3 Nov 2019 21:22:27 -0500 Subject: [PATCH] * --- desktop/package.json | 21 +++++++++------------ desktop/sources/scripts/dotgrid.js | 8 ++++---- desktop/sources/scripts/lib/source.js | 15 ++++++++++----- desktop/sources/scripts/tool.js | 6 +++--- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/desktop/package.json b/desktop/package.json index 29fc71e..1241723 100644 --- a/desktop/package.json +++ b/desktop/package.json @@ -1,23 +1,20 @@ { "name": "Dotgrid", - "productName": "Dotgrid", "version": "0.1.0", "main": "main.js", "scripts": { "start": "electron .", - "lint": "eslint --ignore-path ../.gitignore .", "fix": "standard --fix", - "clean": "rm -r ~/Desktop/Dotgrid-darwin-x64/ ; rm -r ~/Desktop/Dotgrid-linux-x64/ ; rm -r ~/Desktop/Dotgrid-win32-x64/ ; rm -r ~/Desktop/Dotgrid-linux-armv7l/ ; echo 'cleaned build location'", - "build_osx": "electron-packager . Dotgrid --platform=darwin --arch=x64 --out ~/Desktop/ --overwrite --icon=icon.icns ; echo 'Built for OSX'", - "build_linux": "electron-packager . Dotgrid --platform=linux --arch=x64 --out ~/Desktop/ --overwrite --icon=icon.ico ; echo 'Built for LINUX'", - "build_win": "electron-packager . Dotgrid --platform=win32 --arch=x64 --out ~/Desktop/ --overwrite --icon=icon.ico ; echo 'Built for WIN'", + "clean": "rm -r ~/Documents/Dotgrid-darwin-x64/ ; rm -r ~/Documents/Dotgrid-linux-x64/ ; rm -r ~/Documents/Dotgrid-win32-x64/ ; echo 'cleaned build location'", + "build_osx": "electron-packager . Dotgrid --platform=darwin --arch=x64 --out ~/Documents/ --overwrite --icon=icon.icns ; echo 'Built for OSX'", + "build_linux": "electron-packager . Dotgrid --platform=linux --arch=x64 --out ~/Documents/ --overwrite --icon=icon.ico ; echo 'Built for LINUX'", + "build_win": "electron-packager . Dotgrid --platform=win32 --arch=x64 --out ~/Documents/ --overwrite --icon=icon.ico ; echo 'Built for WIN'", "build": "npm run clean ; npm run build_osx ; npm run build_linux ; npm run build_win", - "push_osx": "~/butler push ~/Desktop/Dotgrid-darwin-x64/ hundredrabbits/dotgrid:osx-64", - "push_linux": "~/butler push ~/Desktop/Dotgrid-linux-x64/ hundredrabbits/dotgrid:linux-64", - "push_win": "~/butler push ~/Desktop/Dotgrid-win32-x64/ hundredrabbits/dotgrid:windows-64", - "push_theme": "~/butler push ~/Github/HundredRabbits/Themes/themes/ hundredrabbits/dotgrid:themes", - "push_status": "~/butler status hundredrabbits/dotgrid", - "push": "npm run build ; npm run push_theme ; npm run push_osx ; npm run push_linux ; npm run push_win ; npm run clean ; npm run push_status" + "push_osx": "~/Applications/butler push ~/Documents/Dotgrid-darwin-x64/ hundredrabbits/ronin:osx-64", + "push_linux": "~/Applications/butler push ~/Documents/Dotgrid-linux-x64/ hundredrabbits/ronin:linux-64", + "push_win": "~/Applications/butler push ~/Documents/Dotgrid-win32-x64/ hundredrabbits/ronin:windows-64", + "status": "~/Applications/butler status hundredrabbits/ronin", + "push": "npm run build ; npm run push_osx ; npm run push_linux ; npm run push_win ; npm run clean ; npm run status" }, "devDependencies": { "electron": "^7.0.0", diff --git a/desktop/sources/scripts/dotgrid.js b/desktop/sources/scripts/dotgrid.js index d2512c9..01a13db 100644 --- a/desktop/sources/scripts/dotgrid.js +++ b/desktop/sources/scripts/dotgrid.js @@ -21,8 +21,8 @@ function Dotgrid () { this.acels = new Acels() this.theme = new Theme() this.history = new History() + this.source = new Source() - this.source = new Source(this) this.manager = new Manager(this) this.renderer = new Renderer(this) this.tool = new Tool(this) @@ -44,9 +44,9 @@ function Dotgrid () { window.addEventListener('drop', this.onDrop) this.acels.set('File', 'New', 'CmdOrCtrl+N', () => { this.source.new() }) - this.acels.set('File', 'Save', 'CmdOrCtrl+S', () => { this.source.save('export.grid', this.tool.export(), 'text/plain') }) - this.acels.set('File', 'Export Vector', 'CmdOrCtrl+E', () => { this.source.download('export.svg', this.manager.toString(), 'image/svg+xml') }) - this.acels.set('File', 'Export Image', 'CmdOrCtrl+Shift+E', () => { this.manager.toPNG(this.tool.settings.size, (dataUrl) => { this.source.download('export.png', dataUrl, 'image/png') }) }) + this.acels.set('File', 'Save', 'CmdOrCtrl+S', () => { this.source.download('dotgrid','grid' , this.tool.export(), 'text/plain') }) + this.acels.set('File', 'Export Vector', 'CmdOrCtrl+E', () => { this.source.download('dotgrid','svg', this.manager.toString(), 'image/svg+xml') }) + this.acels.set('File', 'Export Image', 'CmdOrCtrl+Shift+E', () => { this.manager.toPNG(this.tool.settings.size, (dataUrl) => { this.source.download('dotgrid','png', dataUrl, 'image/png') }) }) this.acels.set('File', 'Open', 'CmdOrCtrl+O', () => { this.source.open('grid', this.whenOpen) }) this.acels.set('File', 'Revert', 'CmdOrCtrl+W', () => { this.source.revert() }) this.acels.set('History', 'Undo', 'CmdOrCtrl+Z', () => { this.history.undo() }) diff --git a/desktop/sources/scripts/lib/source.js b/desktop/sources/scripts/lib/source.js index 7c007c1..c69f0f8 100644 --- a/desktop/sources/scripts/lib/source.js +++ b/desktop/sources/scripts/lib/source.js @@ -35,9 +35,9 @@ function Source () { this.saveAs(name, content, type, callback) } - this.saveAs = (name, content, type = 'text/plain', callback) => { + this.saveAs = (name,ext, content, type = 'text/plain', callback) => { console.log('Source', 'Save new file..') - this.download(name, content, type, callback) + this.download(name, ext,content, type, callback) } this.revert = () => { @@ -55,10 +55,9 @@ function Source () { reader.readAsText(file, 'UTF-8') } - this.download = (name, content, type, settings = 'charset=utf-8') => { - console.info('Source', `Downloading ${name}(${type})`) + this.download = (name, ext,content, type, settings = 'charset=utf-8') => { const link = document.createElement('a') - link.setAttribute('download', name) + link.setAttribute('download', `${name}-${timestamp()}.${ext}`) if (type === 'image/png' || type === 'image/jpeg') { link.setAttribute('href', content) } else { @@ -66,4 +65,10 @@ function Source () { } link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window })) } + + + function timestamp (d = new Date(), e = new Date(d)) { + const ms = e - d.setHours(0, 0, 0, 0) + return (ms / 8640 / 10000).toFixed(6).substr(2, 6) + } } diff --git a/desktop/sources/scripts/tool.js b/desktop/sources/scripts/tool.js index 6ced32f..c6009d3 100644 --- a/desktop/sources/scripts/tool.js +++ b/desktop/sources/scripts/tool.js @@ -206,9 +206,9 @@ function Tool (dotgrid) { this.source = function (type) { if (type === 'grid') { dotgrid.renderer.toggle() } if (type === 'open') { dotgrid.source.open('grid', dotgrid.whenOpen) } - if (type === 'save') { dotgrid.source.save('export.grid', dotgrid.tool.export(), 'text/plain') } - if (type === 'export') { dotgrid.source.download('export.svg', dotgrid.manager.toString(), 'image/svg+xml') } - if (type === 'render') { dotgrid.manager.toPNG(dotgrid.tool.settings.size, (dataUrl) => { dotgrid.source.download('export.png', dataUrl, 'image/png') }) } + if (type === 'save') { dotgrid.source.download('dotgrid','grid', dotgrid.tool.export(), 'text/plain') } + if (type === 'export') { dotgrid.source.download('dotgrid','svg', dotgrid.manager.toString(), 'image/svg+xml') } + if (type === 'render') { dotgrid.manager.toPNG(dotgrid.tool.settings.size, (dataUrl) => { dotgrid.source.download('dotgrid','png', dataUrl, 'image/png') }) } } this.canAppend = function (content, index = this.index) {