@@ -13,7 +13,8 @@ import TrainTypeSettingView from './components/TrainTypeSettingView.js';
1313import View , { viewTypeString } from './components/View.js' ;
1414import DiagramParser , { DiagramFile , Train } from './DiagramParser.js' ;
1515import Encoding from 'encoding-japanese' ;
16- import { h , Menu } from './Util.js' ;
16+ import { Dialog , h , Menu } from './Util.js' ;
17+ import './styles/app.css' ;
1718
1819export interface SelectionObject {
1920 train ?: Train ;
@@ -94,7 +95,9 @@ export default class App {
9495 private menu : MenuItem [ ] ;
9596
9697 constructor ( root : Element ) {
97- this . version = '0.4.4' ;
98+ this . version = import . meta. env . PROD
99+ ? import . meta. env . VITE_APP_VERSION
100+ : 'dev-build' ;
98101 this . sidebarElm = h ( 'aside' , { id : 'sidebar' } , null ) ;
99102 this . toolbarElm = h ( 'div' , { id : 'toolbar' } , null ) ;
100103 this . tabbarElm = h ( 'div' , { id : 'tabbar' } , null ) ;
@@ -221,7 +224,7 @@ export default class App {
221224 public save ( ) {
222225 //const bom = new Uint8Array([0xef, 0xbb, 0xbf]);
223226 const unicodeArray : number [ ] = [ ] ;
224- const oudiaString = this . data . saveAsOud ( 'CloudDia v ' + this . version ) ;
227+ const oudiaString = this . data . saveAsOud ( 'CloudDia ' + this . version ) ;
225228 for ( let i = 0 ; i < oudiaString . length ; i ++ ) {
226229 unicodeArray . push ( oudiaString . charCodeAt ( i ) ) ;
227230 }
@@ -248,6 +251,12 @@ export default class App {
248251 . catch ( ( e : Error ) => {
249252 // tslint:disable-next-line: no-console
250253 console . error ( 'parse error.' , e ) ;
254+ const dialog = new Dialog ( {
255+ title : 'ファイル読み込みエラー' ,
256+ message : '時刻表ファイルとして認識できませんでした。' ,
257+ buttons : [ 'OK' ] ,
258+ } ) ;
259+ dialog . show ( ) ;
251260 } ) ;
252261 }
253262 public initialize ( diagram : DiagramFile ) {
@@ -260,19 +269,40 @@ export default class App {
260269 this . showTrainTimetableView ( 0 , 0 ) ;
261270 }
262271 public loadOnlineFile ( fileURL : string ) {
263- const url = 'http://soasa.starfree.jp/fileRequest.php?url=' + fileURL ;
264- fetch ( url , { mode : 'cors' } )
265- . then ( ( response ) => response . blob ( ) )
266- . then (
267- ( blob ) =>
268- new Promise ( ( ) => {
269- const reader = new FileReader ( ) ;
270- reader . onload = ( ) =>
271- this . loadOudia ( reader . result as string , 'Web上のファイル' ) ;
272- reader . readAsText ( blob , 'shift-jis' ) ;
273- } )
274- )
272+ fetch ( fileURL , { mode : 'cors' } )
273+ . then ( ( response ) => {
274+ if ( ! response . ok ) {
275+ throw new Error ( `HTTPステータスコード: ${ response . status } ` ) ;
276+ }
277+ return response . blob ( ) ;
278+ } )
279+ . then ( ( blob ) => {
280+ const reader = new FileReader ( ) ;
281+ reader . onload = ( ) =>
282+ this . loadOudia ( reader . result as string , 'Web上のファイル' ) ;
283+ reader . onerror = ( e ) => {
284+ const dialog = new Dialog ( {
285+ title : 'ファイル読み込みエラー' ,
286+ message : 'ファイルの読み取りに失敗しました。' ,
287+ buttons : [ 'OK' ] ,
288+ } ) ;
289+ dialog . show ( ) ;
290+ } ;
291+ reader . readAsText ( blob , 'shift-jis' ) ;
292+ } )
275293 . catch ( ( err ) => {
294+ const message =
295+ err instanceof TypeError
296+ ? 'CORSポリシーにより、読み込みがブロックされている可能性があります。'
297+ : err instanceof Error
298+ ? err . message
299+ : '' ;
300+ const dialog = new Dialog ( {
301+ title : 'ファイル読み込みエラー' ,
302+ message : '指定のURLからファイルを読み込めませんでした。' + message ,
303+ buttons : [ 'OK' ] ,
304+ } ) ;
305+ dialog . show ( ) ;
276306 throw err ;
277307 } ) ;
278308 }
0 commit comments