welsonjs/uriloader.js

89 lines
2.3 KiB
JavaScript
Raw Normal View History

// uriloader.js
// URI scheme loader for WelsonJS framework
// Namhyeon Go <abuse@catswords.net>
// https;//github.com/gnh1201/welsonjs
2020-08-13 06:44:13 +00:00
var SYS = require("lib/system");
2020-07-07 23:16:52 +00:00
var SHELL = require("lib/shell");
2020-07-27 02:31:52 +00:00
var URI = require("lib/uri");
2020-08-13 06:43:26 +00:00
var WINLIBS = require("lib/winlibs");
2020-07-27 02:31:52 +00:00
2022-08-21 16:42:14 +00:00
function main(args) {
2020-07-27 02:31:52 +00:00
var uri = args[0];
var pos = uri.indexOf(":///");
2020-11-04 07:56:55 +00:00
if (pos < 0) {
2020-07-27 02:31:52 +00:00
console.log("Not vaild URI scheme");
} else {
2020-11-04 08:38:04 +00:00
var commands = [],
2020-07-27 02:31:52 +00:00
queryString = uri.substring(pos + 4),
query = URI.parseQueryString(queryString);
2020-11-04 08:38:04 +00:00
if (!query.application)
2020-07-27 02:31:52 +00:00
query.application = "";
2020-07-07 15:55:50 +00:00
2020-11-04 07:56:55 +00:00
switch (query.application) {
2020-07-27 02:31:52 +00:00
case "app":
2020-11-04 08:38:04 +00:00
commands.push([
"start",
"/d",
SYS.getCurrentScriptDirectory(),
"app.hta",
uri
]);
2020-07-27 02:31:52 +00:00
break;
2020-11-04 07:57:50 +00:00
2020-07-27 02:31:52 +00:00
case "mscalc":
2020-11-04 08:38:04 +00:00
commands.push([
"calc.exe"
]);
2020-07-27 02:31:52 +00:00
break;
2020-11-04 07:57:50 +00:00
2020-07-27 02:31:52 +00:00
case "msie":
2020-08-13 06:43:26 +00:00
WINLIBS.loadLibrary("url").call("FileProtocolHandler", [
"https://github.com/gnh1201/welsonjs"
]);
2020-07-27 02:31:52 +00:00
break;
2020-11-04 07:57:50 +00:00
2020-07-27 02:31:52 +00:00
case "msexcel":
2020-11-04 08:38:04 +00:00
commands.push([
"%PROGRAMFILES%\\Microsoft Office\\Office15\\EXCEL.EXE"
]);
2020-07-27 02:31:52 +00:00
break;
2020-11-04 07:57:50 +00:00
2020-07-27 02:31:52 +00:00
case "mspowerpoint":
2020-11-04 08:38:04 +00:00
commands.push([
"%PROGRAMFILES%\\Microsoft Office\\Office15\\POWERPNT.EXE"
]);
2020-07-27 02:31:52 +00:00
break;
2020-11-04 07:57:50 +00:00
2020-07-27 02:31:52 +00:00
case "msword":
2020-11-04 08:38:04 +00:00
commands.push([
"%PROGRAMFILES%\\Microsoft Office\\Office15\\WINWORD.EXE"
]);
2020-07-27 02:31:52 +00:00
break;
2020-11-04 07:57:50 +00:00
2020-07-27 02:31:52 +00:00
case "msaccess":
2020-11-04 08:38:04 +00:00
commands.push([
"%PROGRAMFILES%\\Microsoft Office\\Office15\\MSACCESS.EXE"
]);
2020-07-27 02:31:52 +00:00
break;
2020-11-04 07:57:50 +00:00
2020-11-04 08:31:30 +00:00
case "arduino":
2020-11-04 08:38:04 +00:00
commands.push([
"%PROGRAMFILES(X86)%\\Arduino\\arduino.exe"
]);
2020-11-04 08:31:30 +00:00
break;
2020-11-04 07:57:50 +00:00
dafault:
console.log("Unknown application");
2020-07-07 23:16:52 +00:00
}
2020-07-27 00:54:52 +00:00
2020-11-04 08:38:04 +00:00
if (commands.length > 0) {
SHELL.run(commands.pop());
2020-07-27 00:54:52 +00:00
}
2020-07-27 02:31:52 +00:00
}
return 0;
2022-08-21 16:43:15 +00:00
}
2022-08-21 16:42:14 +00:00
exports.main = main;