diff options
author | LinuxWizard42 <computerwizard@linuxmail.org> | 2022-09-30 19:44:44 +0300 |
---|---|---|
committer | LinuxWizard42 <computerwizard@linuxmail.org> | 2022-09-30 19:44:44 +0300 |
commit | 11344687f76e789837ea0a04131e7937e97273d4 (patch) | |
tree | 3f666d5db9a9dd0e867239e946b3fe8d8a0e2fe8 /src/flashrunner.js | |
download | FlashRunner-11344687f76e789837ea0a04131e7937e97273d4.tar.gz FlashRunner-11344687f76e789837ea0a04131e7937e97273d4.tar.zst |
First commit
Diffstat (limited to 'src/flashrunner.js')
-rw-r--r-- | src/flashrunner.js | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/src/flashrunner.js b/src/flashrunner.js new file mode 100644 index 0000000..65f9bdb --- /dev/null +++ b/src/flashrunner.js @@ -0,0 +1,211 @@ +const { mainWindow, ipcRenderer, ipcMain, dialog } = require( 'electron' ); + +const r_fsys = require( 'fs' ); + +const version_str = '2.0.7'; + +var open_menu_name = ''; + +const flash_container = document.getElementById( 'flash_container' ); + +/* + * window_resize is used to resize + * the container element of flash content + * container to fit under the menu bar. +*/ +function window_resize(){ + flash_container.style.height = window.innerHeight - 35; +} + +/* + * set_container_content function + * is used to set the flash container + * element's flash content +*/ +function set_container_content( flash_url ){ + if ( flash_url[flash_url.indexOf('.swf') + 4] === undefined ){ + document.getElementById( 'flash_container' ).style.height = window.innerHeight - 35; + document.getElementById( 'flash_container' ).innerHTML = '<embed src="' + flash_url + '" type="application/x-shockwave-flash" width="100%" height="100%" style="position: relative; top: 0px; left: 0px;"></embed>'; + } + else + { + alert( 'Error: That doesn\'t look like a swf link because it doesn\'t end in .swf' ); + } +} + +/* + * open_url is used to open file/url +*/ +function open_url( runner_url ){ + try { + if ( runner_url === undefined || runner_url === null || runner_url === '' ) + throw new Error( 'Link must not be empty' ); + if ( !runner_url.startsWith('http://') && !runner_url.startsWith('https://') && !runner_url.startsWith('file:///') ) + throw new Error( 'Invalid link' ); + if ( !runner_url.endsWith('.swf') ) + throw new Error( 'Invalid swf file link or location' ); + if ( runner_url.startsWith('file:///') ){ + if ( !r_fsys.existsSync(runner_url.replace('file:///', '')) ) + throw new Error( 'File doesn\'t exist' ); + } + if ( runner_url[runner_url.indexOf('.swf') + 4] === undefined ){ + set_container_content( runner_url ); + if ( document.getElementById( 'file_opener' ).style.display === 'block' ) + document.getElementById( 'file_opener' ).style.display = 'none'; + if ( document.getElementById( 'file_opener_bg' ).style.display === 'block' ); + document.getElementById( 'file_opener_bg' ).style.display = 'none'; + if ( document.getElementById( 'game_selector' ).style.display === 'block' ) + document.getElementById( 'game_selector' ).style.display = 'none'; + if ( document.getElementById( 'games_list' ).style.display === 'block' ) + document.getElementById( 'games_list' ).style.display = 'none'; + } + else + { + alert( 'Error: that doesn\'t look like a swf link because it doesn\'t end in .swf' ); + } + runner_url = undefined; + } catch( err_c ){ + alert( 'Error:\n' + err_c ); + } +} + +/* + * open_modal opens the file/url opener dialog +*/ +function open_modal(){ + open_menu_name = 'url_opener'; + document.getElementById( 'file_opener_bg' ).style.display = 'block'; + document.getElementById( 'file_opener' ).style.display = 'block'; +} + +/* + * close_modal closes the file/url opener dialog +*/ +function close_modal(){ + open_menu_name = ''; + document.getElementById( 'file_opener' ).style.display = 'none'; + document.getElementById( 'file_opener_bg' ).style.display = 'none'; +} + +/* + * open_game_selector_menu opens the easy to use + * game selection menu +*/ +function open_game_selector_menu(){ + open_menu_name = 'game_selector'; + document.getElementById( 'file_opener_bg' ).style.display = 'block'; + document.getElementById( 'game_selector' ).style.display = 'block'; + document.getElementById( 'games_list' ).style.display = 'block'; +} + +/* + * close_game_selector_menu closes the easy to use + * game selection menu +*/ +function close_game_selector_menu(){ + open_menu_name = ''; + document.getElementById( 'file_opener_bg' ).style.display = 'none'; + document.getElementById( 'game_selector' ).style.display = 'none'; + document.getElementById( 'games_list' ).style.display = 'none'; +} + +/* + * create_games_list creates the easy to use + * list of games received from JSON file on server +*/ +function create_games_list( parsed_json ){ + var g_list = document.getElementById( 'games_list' ); + g_list.innerHTML = ''; + var game_index = null; + for ( game_index in parsed_json.games_menu ) + if ( parsed_json.games_menu[game_index].game_name !== undefined && parsed_json.games_menu[game_index].game_name !== null && parsed_json.games_menu[game_index].game_name !== '' && typeof parsed_json.games_menu[game_index].game_name === 'string' && parsed_json.games_menu[game_index].game_swf !== undefined && parsed_json.games_menu[game_index].game_swf !== null && parsed_json.games_menu[game_index].game_swf !== '' && typeof parsed_json.games_menu[game_index].game_swf === 'string' ) + g_list.innerHTML += '<a href="#" onclick="open_url(\'' + parsed_json.games_menu[game_index].game_swf + '\');" class="modal_game_selector_menu_item">' + parsed_json.games_menu[game_index].game_name + '</a>'; + game_index = undefined; + g_list = undefined; +} + +/* + * flashrunner_get_game_list gets the list of games + * from JSON file for the easy to use game selection menu +*/ +function flashrunner_get_game_list(){ + try { + if ( r_fsys.existsSync('./flashrunner_game_list.json') ){ + var game_list_json = r_fsys.readFileSync( './flashrunner_game_list.json', { + encoding: 'utf8', + flag: 'r' + } ); + var games_list_parsed = JSON.parse( game_list_json ); + create_games_list( games_list_parsed ); + games_list_parsed = undefined; + game_list_json = undefined; + } + else + { + document.getElementById( 'game_list' ).innerHTML = '<span class="wtext">Error: could not find games list file</span>'; + } + } catch ( err_m ){ + document.getElementById( 'game_list' ).innerHTML = '<span class="wtext">Error loading games list</span>'; + } +} + +/* + * flashrunner_about is the about dialog, simple +*/ +function flashrunner_about(){ + alert( 'FlashRunner by VoidNet\nVersion: ' + version_str + '\n\nFlash copyright:\n\u00A9 Adobe Systems Incorporated and its licensors. All rights reserved.' ); +} + +document.getElementById( 'menu_open' ).addEventListener( 'click', function(){ + open_modal(); +} ); + +document.getElementById( 'menu_about' ).addEventListener( 'click', function(){ + flashrunner_about(); +} ); + +document.getElementById( 'modal_run_btn' ).addEventListener( 'click', function(){ + if ( document.getElementById('flash_file').value !== undefined && document.getElementById('flash_file').value !== null && document.getElementById('flash_file').value !== '' ){ + if ( document.getElementById('flash_file').value.startsWith('http://') || document.getElementById('flash_file').value.startsWith('https://') ) + open_url( document.getElementById('flash_file').value ); + else + open_url( 'file:///' + document.getElementById('flash_file').value ); + } + else + { + alert( 'Flash file URL or path can\'t be empty' ); + } +} ); + +document.getElementById( 'menu_game_selector' ).addEventListener( 'click', function(){ + open_game_selector_menu(); +} ); + +document.getElementById( 'menu_steamgroup' ).addEventListener( 'click', function(){ + ipcRenderer.send( 'asyncmsg', 'OPEN_URL https://steamcommunity.com/groups/VoidNet_' ); +} ); + +window.addEventListener( 'resize', window_resize ); + +document.getElementById( 'menu_exit' ).addEventListener( 'click', function(){ + ipcRenderer.send( 'asyncmsg', 'APP_SHUTDOWN' ); +} ); + +document.getElementById( 'close_flash_opener' ).addEventListener( 'click', function(){ + switch ( open_menu_name ){ + case 'url_opener': + close_modal(); + break; + case 'game_selector': + close_game_selector_menu(); + break; + default: + break; + } +} ); + +document.addEventListener( 'contextmenu', function(ctx_event){ + ctx_event.preventDefault(); +} ); + +flashrunner_get_game_list(); |