|
1 | | -import { observable, computed, action, autorun, toJS, makeObservable } from 'mobx'; |
| 1 | +import { observable, computed, action, makeObservable } from 'mobx'; |
2 | 2 | const { dialog } = require('@electron/remote'); |
3 | 3 | import { errorMsg } from '#util/dialog'; |
4 | 4 | import { removeBackground } from './remove-background'; |
5 | 5 | import { colorMatch } from './color-match'; |
6 | 6 | import { getSpriteBBoxes } from './get-sprite'; |
7 | 7 | import { getMappings } from './generate-mappings'; |
8 | 8 | import { importSprite } from './import-sprite'; |
| 9 | +import { readFile } from 'fs'; |
9 | 10 |
|
10 | 11 | class ImportState { |
11 | 12 | config = { |
@@ -65,21 +66,27 @@ class ImportState { |
65 | 66 | this.ctx = node.getContext('2d'); |
66 | 67 |
|
67 | 68 | if (this.path) { |
68 | | - const img = new Image(); |
69 | | - |
70 | | - img.onload = () => { |
71 | | - node.width = img.width; |
72 | | - node.height = img.height; |
73 | | - this.ctx.drawImage(img, 0, 0); |
74 | | - requestAnimationFrame(this.loaded); |
75 | | - }; |
76 | | - |
77 | | - img.onerror = (e) => { |
78 | | - errorMsg('Import Error', `Error loading ${this.path}`); |
79 | | - this.cancel(); |
80 | | - }; |
81 | | - |
82 | | - img.src = this.path; |
| 69 | + readFile(this.path, (_err, data) => { |
| 70 | + if (data) { |
| 71 | + const blob = new Blob([data]); |
| 72 | + const url = URL.createObjectURL(blob); |
| 73 | + const img = new Image(); |
| 74 | + img.onload = () => { |
| 75 | + node.width = img.width; |
| 76 | + node.height = img.height; |
| 77 | + this.ctx.drawImage(img, 0, 0); |
| 78 | + requestAnimationFrame(this.loaded); |
| 79 | + URL.revokeObjectURL(url); |
| 80 | + }; |
| 81 | + img.onerror = (e) => { |
| 82 | + errorMsg('Import Error', `Error loading ${this.path}`); |
| 83 | + this.cancel(); |
| 84 | + }; |
| 85 | + img.src = url; |
| 86 | + } else { |
| 87 | + errorMsg('Import Error', `Error loading ${this.path}`); |
| 88 | + } |
| 89 | + }); |
83 | 90 |
|
84 | 91 | } else if (this.rotCanvas) { |
85 | 92 | this.ctx.drawImage(this.rotCanvas, 0, 0); |
|
0 commit comments