From 99fd55d53a2fc3f20be351c288a073537ac1f0b1 Mon Sep 17 00:00:00 2001 From: ocogeclub Date: Wed, 8 Sep 2021 22:33:19 +0900 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E4=BD=9C=E3=82=B9=E3=82=AF=E3=83=AA?= =?UTF-8?q?=E3=83=97=E3=83=88=E3=82=92=E3=83=AB=E3=83=BC=E3=83=88=E3=83=95?= =?UTF-8?q?=E3=82=A9=E3=83=AB=E3=83=80=E3=81=AB=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 4 ++-- installer/install.sh | 4 ---- scripts/ugj_blocks.js => ugj_blocks.js | 11 +++++----- ugj_const.js | 3 +++ scripts/eleclib.js => ugj_eleclib.js | 28 +++++++++++--------------- scripts/ugj_script.js => ugj_script.js | 2 +- 6 files changed, 23 insertions(+), 29 deletions(-) rename scripts/ugj_blocks.js => ugj_blocks.js (99%) create mode 100644 ugj_const.js rename scripts/eleclib.js => ugj_eleclib.js (91%) rename scripts/ugj_script.js => ugj_script.js (99%) diff --git a/index.html b/index.html index 41e4768..6324495 100644 --- a/index.html +++ b/index.html @@ -931,8 +931,8 @@ - - + + diff --git a/installer/install.sh b/installer/install.sh index cbee69e..9a60f9a 100644 --- a/installer/install.sh +++ b/installer/install.sh @@ -17,9 +17,5 @@ else fi # build ocoge -# uncomment if electron will be installed on RPi OS -# echo 'arch=armv7l' > ~/.npmrc cd .. npm install - -read -p "Press enter to exit: " diff --git a/scripts/ugj_blocks.js b/ugj_blocks.js similarity index 99% rename from scripts/ugj_blocks.js rename to ugj_blocks.js index 72f629c..ef66b17 100644 --- a/scripts/ugj_blocks.js +++ b/ugj_blocks.js @@ -1,5 +1,4 @@ -/** Hard Coding!!! */ -const appDocRoot = '/home/pi/Documents/ocoge_docs/' +const ugj_const = require('./ugj_const'); /** Fix Basic Blocks ****************************************************************************************/ var ugjConsrolForDefinition = { @@ -1280,9 +1279,9 @@ Blockly.JavaScript['ugj_canvas_loadimg'] = function (block) { var value_imgfilename = Blockly.JavaScript.valueToCode(block, 'imgfilename', Blockly.JavaScript.ORDER_ATOMIC); var code = [ `let img = new Image();`, - `img.src = '${appDocRoot}' + ${value_imgfilename};`, + `img.src = '${ugj_const.doc_root}' + ${value_imgfilename};`, `img.onload = () => ctx.drawImage(img,0,0);`, - // `ugj_canvasImg('${appDocRoot}' + ${value_imgfilename});`, + // `ugj_canvasImg('${ugj_const.doc_root}' + ${value_imgfilename});`, '' ].join('\n'); return code; @@ -2086,7 +2085,7 @@ Blockly.Blocks['ugj_file_readsync'] = { Blockly.JavaScript['ugj_file_readsync'] = function (block) { var value_filename = Blockly.JavaScript.valueToCode(block, 'filename', Blockly.JavaScript.ORDER_ATOMIC); var dropdown_encoding = block.getFieldValue('encoding'); - let filepath = appDocRoot + value_filename.replace(/\'/g, ''); + let filepath = ugj_const.doc_root + value_filename.replace(/\'/g, ''); var code = `fs.readFileSync('${filepath}', '${dropdown_encoding}')`; return [code, Blockly.JavaScript.ORDER_ATOMIC]; }; @@ -2406,7 +2405,7 @@ Blockly.Blocks['ugj_child_fswebcam'] = { }; Blockly.JavaScript['ugj_child_fswebcam'] = function (block) { var value_filename = Blockly.JavaScript.valueToCode(block, 'filename', Blockly.JavaScript.ORDER_ATOMIC); - var code = `'fswebcam', ['-r', '480x360', '${appDocRoot}' + ${value_filename}]`; + var code = `'fswebcam', ['-r', '480x360', '${ugj_const.doc_root}' + ${value_filename}]`; return [code, Blockly.JavaScript.ORDER_NONE]; }; diff --git a/ugj_const.js b/ugj_const.js new file mode 100644 index 0000000..3bce958 --- /dev/null +++ b/ugj_const.js @@ -0,0 +1,3 @@ +module.exports.doc_root = '/home/pi/Documents/ocoge_docs/'; +module.exports.app_name = 'ocoge'; +module.exports.mascot_path = '/home/pi/Applications/ocoge/img/'; diff --git a/scripts/eleclib.js b/ugj_eleclib.js similarity index 91% rename from scripts/eleclib.js rename to ugj_eleclib.js index 3467f9d..dfa8093 100644 --- a/scripts/eleclib.js +++ b/ugj_eleclib.js @@ -2,14 +2,10 @@ /** Node.js または Electron 固有の機能を利用した関数のモジュール ************* */ -// ローカルプロパティ -// Hard Coding!!! -const appName = 'ocoge'; -const defpath = '/home/pi/Documents/ocoge_docs/'; -const mascotDefPath = '/home/pi/Applications/ocoge/img/'; // Require const fs = require('fs'); const path = require("path"); +const ugj_const = require('./ugj_const'); const mainWin = require('@electron/remote').getCurrentWindow(); const dialog = require('@electron/remote').dialog; @@ -18,7 +14,7 @@ const clipboard = require('electron').clipboard; var saveFilepath = null; var wsChanged = false; -var mascotFilePath = mascotDefPath + 'cogechee.png'; +var mascotFilePath = ugj_const.mascot_path + 'cogechee.png'; // 0で数値の桁合わせ // NUM=値 LEN=桁数 @@ -28,7 +24,7 @@ const zeroPadding = (NUM, LEN) => (Array(LEN).join('0') + NUM).slice(-LEN); const getUniqueFilepath = () => { let today = new Date(); let filename = today.getFullYear() + '-' + zeroPadding((today.getMonth() + 1), 2) + '-' + zeroPadding(today.getDate(), 2) + '-' + zeroPadding(today.getHours(), 2) + '-' + zeroPadding(today.getMinutes(), 2) + '-' + zeroPadding(today.getSeconds(), 2); - let filepath = path.join(defpath, filename); + let filepath = path.join(ugj_const.doc_root, filename); return filepath; } @@ -42,8 +38,8 @@ exports.openURL = (url) => { // タイトルバーにファイル名を表示 // const setTitle = () => { -// if (saveFilepath) let title = appName; -// else let title = saveFilepath + ' - ' + appName; +// if (saveFilepath) let title = ugj_const.app_name; +// else let title = saveFilepath + ' - ' + ugj_const.app_name; // mainWin.setTitle(title); // } @@ -52,8 +48,8 @@ exports.openURL = (url) => { const setSaveFilepath = filepath => { let title; saveFilepath = filepath; - // if (filepath) title = filepath + ' - ' + appName; - // else title = appName; + // if (filepath) title = filepath + ' - ' + ugj_const.app_name; + // else title = ugj_const.app_name; // mainWin.setTitle(title); this.setWsChanged(false); } @@ -63,8 +59,8 @@ const setSaveFilepath = filepath => { exports.setWsChanged = changed => { let title; wsChanged = changed; - if (saveFilepath) title = saveFilepath + ' - ' + appName; - else title = appName; + if (saveFilepath) title = saveFilepath + ' - ' + ugj_const.app_name; + else title = ugj_const.app_name; if (changed) title = '*' + title; mainWin.setTitle(title); } @@ -74,7 +70,7 @@ exports.newFile = () => setSaveFilepath(null); // ワークスペースファイル読み込みの一連の動作のラッパ exports.loadWsFile = () => { - let filepath = openFile('xml', defpath); + let filepath = openFile('xml', ugj_const.doc_root); if (filepath.length > 0) { if (saveFilepath === null) { setSaveFilepath(filepath); @@ -86,7 +82,7 @@ exports.loadWsFile = () => { } // その他ファイル読み込みの一連の動作のラッパ exports.loadFile = ext => { - let filepath = openFile(ext, defpath); + let filepath = openFile(ext, ugj_const.doc_root); if (filepath.length > 0) { return readFromFile(filepath); } else { @@ -94,7 +90,7 @@ exports.loadFile = ext => { } } exports.selectMascotFile = () => { - return openFile('png', mascotDefPath); + return openFile('png', ugj_const.mascot_path); } // オープンファイルダイアログ const openFile = (ext, dpath) => { diff --git a/scripts/ugj_script.js b/ugj_script.js similarity index 99% rename from scripts/ugj_script.js rename to ugj_script.js index 891bf2a..1610230 100644 --- a/scripts/ugj_script.js +++ b/ugj_script.js @@ -630,7 +630,7 @@ window.onbeforeunload = () => { // Electron動作とブラウザ動作を自動で仕分け if (typeof require == 'function') { // requireが使える = Electron - var elec = require('./scripts/eleclib'); + var elec = require('./ugj_eleclib'); console.log('elec loaded.'); } else { //ブラウザ動作