mirror of
https://github.com/ducbao414/win32.run.git
synced 2025-12-17 17:52:50 +09:00
init the awkward code
This commit is contained in:
91
static/html/jspaint/lib/tracky-mouse/tracky-mouse-electron/.gitignore
vendored
Normal file
91
static/html/jspaint/lib/tracky-mouse/tracky-mouse-electron/.gitignore
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
copied/
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
.DS_Store
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
||||
# nuxt.js build output
|
||||
.nuxt
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# Webpack
|
||||
.webpack/
|
||||
|
||||
# Electron-Forge
|
||||
out/
|
||||
@@ -0,0 +1,74 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const glob = require("glob");
|
||||
|
||||
const logFile = fs.createWriteStream(path.join(__dirname, "forge-hook.log"));
|
||||
logFile.write("Hello World\n\n");
|
||||
|
||||
module.exports = {
|
||||
"packagerConfig": {},
|
||||
"makers": [
|
||||
{
|
||||
"name": "@electron-forge/maker-squirrel",
|
||||
"config": {
|
||||
"name": "tracky_mouse_electron"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "@electron-forge/maker-zip",
|
||||
"platforms": [
|
||||
"darwin"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "@electron-forge/maker-deb",
|
||||
"config": {}
|
||||
},
|
||||
{
|
||||
"name": "@electron-forge/maker-rpm",
|
||||
"config": {}
|
||||
}
|
||||
],
|
||||
hooks: {
|
||||
prePackage: (forgeConfig) => {
|
||||
logFile.write("prePackage hook\n\n");
|
||||
return new Promise((resolve, reject) => {
|
||||
const fromFolder = path.resolve(`${__dirname}/../`);
|
||||
const toFolder = `${__dirname}/copied/`;
|
||||
const appGlob = `${fromFolder}/**`;
|
||||
logFile.write(`appGlob: ${appGlob} \n\n`);
|
||||
glob(appGlob, {
|
||||
ignore: [
|
||||
".*/**",
|
||||
"**/tracky-mouse-electron/**",
|
||||
"**/node_modules/**",
|
||||
"**/private/**",
|
||||
]
|
||||
}, async (error, files) => {
|
||||
logFile.write(`glob callback, files:\n${JSON.stringify(files)}\n\n`);
|
||||
|
||||
logFile.write(`Deleting ${toFolder}\n\n`);
|
||||
await fs.promises.rmdir(toFolder, { recursive: true });
|
||||
|
||||
if (error) {
|
||||
logFile.write(`Failed to copy app files:\n${error}`);
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
const copyPromises = [];
|
||||
for (const file of files) {
|
||||
const newFile = path.join(toFolder, path.relative(fromFolder, file));
|
||||
if (!fs.statSync(file).isDirectory()) {
|
||||
await fs.promises.mkdir(path.dirname(newFile), { recursive: true });
|
||||
logFile.write(`Copy: ${file}\n`);
|
||||
logFile.write(`To: ${newFile}\n`);
|
||||
copyPromises.push(fs.promises.copyFile(file, newFile));
|
||||
}
|
||||
}
|
||||
await Promise.all(copyPromises);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
11402
static/html/jspaint/lib/tracky-mouse/tracky-mouse-electron/package-lock.json
generated
Normal file
11402
static/html/jspaint/lib/tracky-mouse/tracky-mouse-electron/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,64 @@
|
||||
{
|
||||
"name": "tracky-mouse-electron",
|
||||
"productName": "Tracky Mouse",
|
||||
"version": "1.0.0",
|
||||
"description": "Control your computer with your head movements",
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"name": "Isaiah Odhner",
|
||||
"email": "isaiahodhner@gmail.com",
|
||||
"url": "https://isaiahodhner.io"
|
||||
},
|
||||
"keywords": [
|
||||
"camera-mouse",
|
||||
"mouse",
|
||||
"camera",
|
||||
"webcam",
|
||||
"head-tracker",
|
||||
"head-tracking",
|
||||
"face-tracker",
|
||||
"face-tracking",
|
||||
"headmouse",
|
||||
"facial-mouse",
|
||||
"accessibility",
|
||||
"cursor",
|
||||
"pointer",
|
||||
"pointing",
|
||||
"input-method",
|
||||
"hands-free",
|
||||
"handsfree",
|
||||
"desktop-automation"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/1j01/tracky-mouse.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/1j01/tracky-mouse/issues"
|
||||
},
|
||||
"homepage": "https://github.com/1j01/tracky-mouse#readme",
|
||||
"main": "src/electron-main.js",
|
||||
"scripts": {
|
||||
"start": "electron-forge start",
|
||||
"package": "electron-forge package",
|
||||
"make": "electron-forge make",
|
||||
"publish": "electron-forge publish",
|
||||
"lint": "echo \"No linting configured\""
|
||||
},
|
||||
"config": {
|
||||
"forge": "forge.config.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"electron-squirrel-startup": "^1.0.0",
|
||||
"robotjs": "^0.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@electron-forge/cli": "^6.0.0-beta.54",
|
||||
"@electron-forge/maker-deb": "^6.0.0-beta.54",
|
||||
"@electron-forge/maker-rpm": "^6.0.0-beta.54",
|
||||
"@electron-forge/maker-squirrel": "^6.0.0-beta.54",
|
||||
"@electron-forge/maker-zip": "^6.0.0-beta.54",
|
||||
"electron": "12.0.7",
|
||||
"glob": "^7.1.7"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
const { app, globalShortcut, BrowserWindow } = require('electron');
|
||||
const path = require('path');
|
||||
|
||||
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
|
||||
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
|
||||
app.quit();
|
||||
}
|
||||
|
||||
// Needed for RobotJS native module in renderer process (could be moved to main with IPC)
|
||||
app.allowRendererProcessReuse = false;
|
||||
|
||||
// Allow recovering from WebGL crash unlimited times.
|
||||
// (To test the recovery, I've been using Ctrl+Alt+F1 and Ctrl+Alt+F2 in Ubuntu.
|
||||
// Note, if Ctrl + Alt + F2 doesn't get you back, try Ctrl+Alt+F7.)
|
||||
app.commandLine.appendSwitch("--disable-gpu-process-crash-limit");
|
||||
|
||||
|
||||
const trackyMouseFolder = app.isPackaged ? `${app.getAppPath()}/copied/` : `${__dirname}/../../`;
|
||||
|
||||
let mainWindow;
|
||||
|
||||
const createWindow = () => {
|
||||
// Create the browser window.
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
webPreferences: {
|
||||
preload: path.join(app.getAppPath(), 'src/preload.js'),
|
||||
},
|
||||
// icon: `${trackyMouseFolder}/images/tracky-mouse-logo-16.png`,
|
||||
icon: `${trackyMouseFolder}/images/tracky-mouse-logo-512.png`,
|
||||
});
|
||||
|
||||
// and load the index.html of the app.
|
||||
mainWindow.loadFile(`${trackyMouseFolder}/index.html`);
|
||||
|
||||
// Toggle the DevTools with F12
|
||||
mainWindow.webContents.on("before-input-event", (e, input) => {
|
||||
if (input.type === "keyDown" && input.key === "F12") {
|
||||
mainWindow.webContents.toggleDevTools();
|
||||
|
||||
mainWindow.webContents.on('devtools-opened', () => {
|
||||
// Can't use mainWindow.webContents.devToolsWebContents.on("before-input-event") - it just doesn't intercept any events.
|
||||
mainWindow.webContents.devToolsWebContents.executeJavaScript(`
|
||||
new Promise((resolve)=> {
|
||||
addEventListener("keydown", (event) => {
|
||||
if (event.key === "F12") {
|
||||
resolve();
|
||||
}
|
||||
}, { once: true });
|
||||
})
|
||||
`)
|
||||
.then(() => {
|
||||
mainWindow.webContents.toggleDevTools();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.on('ready', () => {
|
||||
createWindow();
|
||||
|
||||
const success = globalShortcut.register('F9', () => {
|
||||
// console.log('Toggle tracking');
|
||||
mainWindow.webContents.send("shortcut", "toggle-tracking");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// Prevent multiple instances of the app
|
||||
if (!app.requestSingleInstanceLock()) {
|
||||
app.quit();
|
||||
}
|
||||
|
||||
app.on('second-instance', () => {
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) {
|
||||
mainWindow.restore();
|
||||
}
|
||||
|
||||
mainWindow.show();
|
||||
}
|
||||
});
|
||||
|
||||
// Quit when all windows are closed, except on macOS. There, it's common
|
||||
// for applications and their menu bar to stay active until the user quits
|
||||
// explicitly with Cmd + Q.
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on('activate', () => {
|
||||
// On OS X it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
|
||||
// In this file you can include the rest of your app's specific main process
|
||||
// code. You can also put them in separate files and import them here.
|
||||
@@ -0,0 +1,11 @@
|
||||
const { moveMouse } = require('robotjs');
|
||||
const { contextBridge, ipcRenderer } = require('electron')
|
||||
|
||||
contextBridge.exposeInMainWorld("moveMouse", (...args) => moveMouse(...args));
|
||||
|
||||
contextBridge.exposeInMainWorld("onShortcut", (callback) => {
|
||||
ipcRenderer.on("shortcut", (event, data) => {
|
||||
// console.log("shortcut", data);
|
||||
callback(data);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user