自作スクリプトをルートフォルダに移動

This commit is contained in:
ocogeclub 2021-09-08 22:33:19 +09:00
parent f511aba1f7
commit 99fd55d53a
6 changed files with 23 additions and 29 deletions

View File

@ -931,8 +931,8 @@
<script src="./google-blockly/blocks_compressed.js"></script>
<script src="./google-blockly/msg/js/ja.js"></script>
<script src="./scripts/custom-dialog.js"></script>
<script src="./scripts/ugj_blocks.js"></script>
<script src="./scripts/ugj_script.js"></script>
<script src="./ugj_blocks.js"></script>
<script src="./ugj_script.js"></script>
<script src="./scripts/beautify.min.js"></script>
<script src="./scripts/prettify.js"></script>
<script src="./.shared/skyway_key.js"></script>

View File

@ -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: "

View File

@ -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];
};

3
ugj_const.js Normal file
View File

@ -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/';

View File

@ -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) => {

View File

@ -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 {
//ブラウザ動作