Skip to content

Commit

Permalink
code review corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
UUoocl committed Jan 8, 2025
1 parent 0e94485 commit b16f92a
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 40 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ After choosing to insert a tag, then a list of tags appear in the command palett

In the UUhimsy settings, click the "Add UUhimsy scripts to Slides Extended Template" button.



## UUhimsy system

This plugin is a part of the [UUhimsy](https://github.com/UUoocl/UUhimsy) system.
Expand Down
55 changes: 26 additions & 29 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ import { uuhimsySettingsTab } from 'settings';
import { UUhimsyEntranceSuggest, UUhimsyExitSuggest } from 'suggest';
import { UUHIMSY_VIEW_TYPE, UUhimsyView } from 'view';

//include system command
const { execSync } = require('child_process');
import { execSync } from 'node:child_process';
import path from 'node:path';
import util from 'util';
import { exec } from 'child_process';
import { promisify } from 'util';
const execAsync = promisify(exec);

// pathToPlugin contains "my-folder/file" not "//my-folder\"

const { Client, Server, Message } = require("node-osc")
const OBSWebSocket = require("obs-websocket-js").default;
import { Client, Server, Message } from 'node-osc';
import { OBSWebSocket } from 'obs-websocket-js';

interface uuhimsyPluginSettings{
uvcUtil_folder: string;
websocketIP_Text: string;
websocketPort_Text: string;
websocketPW_Text: string;
Expand All @@ -36,7 +39,8 @@ const DEFAULT_SETTINGS: Partial<uuhimsyPluginSettings> = {
obsAppPath_Text: "C:\\\\Program Files\\\\obs-studio\\\\bin\\\\64bit\\\\",
obsCollection_Text: "Key_and_Mouse_Visuals_Collection",
obsDebug_Text: "Y",
obsDebugPort_Text: "9222"
obsDebugPort_Text: "9222",
uvcUtil_folder:"_uvc-util"
};

export default class uuhimsyPlugin extends Plugin {
Expand Down Expand Up @@ -68,7 +72,6 @@ export default class uuhimsyPlugin extends Plugin {

new Notice("Enabled OSC plugin")
new Notice(this.settings.websocketIP_Text)
new Notice(this.app.vault.configDir)

//
//
Expand Down Expand Up @@ -366,15 +369,14 @@ export default class uuhimsyPlugin extends Plugin {

//https://forum.obsidian.md/t/how-to-get-vault-absolute-path/22965
//@ts-ignore
const vaultPath = normalizePath(`${this.app.vault.adapter.basePath}/${this.app.vault.configDir}/plugins/UUhimsyPlugin`)
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const uvcUtilPath = normalizePath(`${this.app.vault.adapter.basePath}/${this.settings.uvcUtil_folder}`)

let previousPTZ ="";

setInterval( async() =>{

let pt = await getCameraPanTilt(vaultPath, util, exec);
let z = await getCameraZoom(vaultPath, util, exec);
let pt = await getCameraPanTilt(uvcUtilPath, util, execAsync);
let z = await getCameraZoom(uvcUtilPath, util, execAsync);
let ptzMessage = `${pt}${z}}`

if(ptzMessage != previousPTZ){
Expand All @@ -401,10 +403,10 @@ export default class uuhimsyPlugin extends Plugin {
}
}, 2000);

async function getCameraPanTilt(vaultPath, util, exec) {
async function getCameraPanTilt(uvcUtilPath, util, exec) {
try {
//console.log(vaultPath)
const { stdout, stderr } = await exec(`'${vaultPath}/uvc-util' -I 0 -o pan-tilt-abs`);
//console.log(uvcUtilPath)
const { stdout, stderr } = await exec(`'${uvcUtilPath}/uvc-util' -I 0 -o pan-tilt-abs`);
//console.log('stdout:', stdout);
//console.log('stderr:', stderr);
let ptResult = stdout.toString();
Expand All @@ -416,9 +418,9 @@ export default class uuhimsyPlugin extends Plugin {
}
}

async function getCameraZoom(vaultPath, util, exec) {
async function getCameraZoom(uvcUtilPath, util, exec) {
try {
const { stdout, stderr } = await exec(`'${vaultPath}/uvc-util' -I 0 -o zoom-abs`);
const { stdout, stderr } = await exec(`'${uvcUtilPath}/uvc-util' -I 0 -o zoom-abs`);
//console.log('stdout:', stdout);
//console.log('stderr:', stderr);
return stdout.replace(/\n/g, "");
Expand All @@ -433,7 +435,7 @@ export default class uuhimsyPlugin extends Plugin {
//console.log("Message from OBS",event);
if (event.event_name === "set-ptz") {
//console.log('command',`'shortcuts' run ${event.shortcut_name}`)
const stdout = await exec(`'${vaultPath}/uvc-util' -I 0 -o pan-tilt-abs`);
const stdout = await exec(`'${uvcUtilPath}/uvc-util' -I 0 -o pan-tilt-abs`);
//console.log(stdout)
}
})
Expand Down Expand Up @@ -480,8 +482,6 @@ this.addCommand({
if (Platform.isMacOS){
if(!checking){
//This is a Mac computer run the command
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const { stdout, stderr } = await exec(`'shortcuts' list`);
//let shortcuts = JSON.stringify(stdout)
let shortcuts = stdout.split('\n')
Expand Down Expand Up @@ -592,8 +592,6 @@ this.addCommand({
id: 'open-obs',
name: 'Open OBS',
callback: async () => {
const util = require('util');
const exec = util.promisify(require('child_process').exec);
//build command string

let commandString ="hello"
Expand All @@ -605,10 +603,9 @@ this.addCommand({
commandString += ` --websocket_port "${this.settings.websocketPort_Text}"`;
commandString += ` --websocket_password "${this.settings.websocketPW_Text}"`;
commandString += ` --multi`;
exec(commandString);
execAsync(commandString);
}
if (Platform.isWin) {
const path = require('path');
const obsPath = `${this.settings.obsAppPath_Text}${this.settings.obsAppName_Text}`
const obsDir = path.dirname(obsPath);
process.chdir(obsDir)
Expand All @@ -621,9 +618,9 @@ this.addCommand({
commandString += ` --websocket_password "${this.settings.websocketPW_Text}"`;
commandString += ` --multi`;

exec(commandString, (error, stdout, stderr) => {
execAsync(commandString, (error, stdout, stderr) => {
if (error) {
//console.error(`exec error: ${error}`);
//console.error(`execAsync error: ${error}`);
return;
}
//console.log(`stdout: ${stdout}`);
Expand Down Expand Up @@ -702,13 +699,13 @@ this.addCommand({

async openView(){
const { workspace } = this.app;
this.app.workspace.detachLeavesOfType(UUHIMSY_VIEW_TYPE)
let leaf: WorkspaceLeaf | null = null;
const leaves = workspace.getLeavesOfType(UUHIMSY_VIEW_TYPE);

if (leaves.length > 0) {
// A leaf with our view already exists, use that
leaf = leaves[0];

} else {
// Our view could not be found in the workspace, create a new leaf
// in the right sidebar for it
Expand All @@ -721,7 +718,7 @@ async openView(){
}

onunload() {
this.app.workspace.detachLeavesOfType(UUHIMSY_VIEW_TYPE)
//this.app.workspace.detachLeavesOfType(UUHIMSY_VIEW_TYPE)
new Notice("Disabled UUhimsy plugin")

}
Expand Down
44 changes: 38 additions & 6 deletions settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import uuhimsyPlugin from "main";
import {App, Notice, PluginSettingTab, Setting, normalizePath } from "obsidian";
import {App, Notice, Platform, PluginSettingTab, Setting, normalizePath } from "obsidian";

export class uuhimsySettingsTab extends PluginSettingTab {
plugin: uuhimsyPlugin;
Expand Down Expand Up @@ -57,7 +57,7 @@ export class uuhimsySettingsTab extends PluginSettingTab {
.setHeading()
.setDesc("Open OBS with these options.")

if(process.platform === "darwin"){
if(Platform.isMacOS){
new Setting(containerEl)
.setName("Name")
.setDesc("Enter 'OBS' or a custom name")
Expand All @@ -70,7 +70,7 @@ export class uuhimsySettingsTab extends PluginSettingTab {
});
}

if(process.platform === "win32"){
if(Platform.isWin){
new Setting(containerEl)
.setName("Name")
.setDesc("Enter 'obs64.exe' or a custom name")
Expand Down Expand Up @@ -140,7 +140,7 @@ export class uuhimsySettingsTab extends PluginSettingTab {
});

new Setting(containerEl)
.setName("Out going Message PORT")
.setName("Outgoing Message PORT")
.addText((item) => {
item.setValue(this.plugin.settings.oscOutPort_Text).onChange(
(value) => {
Expand All @@ -149,7 +149,7 @@ export class uuhimsySettingsTab extends PluginSettingTab {

})
});

new Setting(containerEl)
.setName("Add UUhimsy scripts to Slides Extended Template")
.setHeading()
Expand All @@ -160,7 +160,7 @@ export class uuhimsySettingsTab extends PluginSettingTab {
.setTooltip("UUhimsy scripts are included when exporting from Slides Extended")
.setCta()
.onClick(async ()=>{
const fileName = `.obsidian/plugins/slides-extended/template/reveal.html`;
const fileName = `${this.app.vault.configDir}/plugins/slides-extended/template/reveal.html`;
const existing = await this.app.vault.adapter.exists(normalizePath(`${fileName}`));
if (existing) {
let file = await this.app.vault.adapter.read(normalizePath(`${fileName}`))
Expand All @@ -187,6 +187,38 @@ export class uuhimsySettingsTab extends PluginSettingTab {
// })
});

if(Platform.isMacOS){
new Setting(containerEl)
.setName("UVC-Util")
.setHeading()
.setDesc(`USB Video Class (UVC) control management utility for Mac OS X`)
.addButton((button) =>{
button
.setButtonText("Learn More")
.onClick(() => {window.open("https://github.com/jtfrey/uvc-util")})

})
.addButton((button) =>{
button
.setCta()
.setButtonText("Download")
.onClick(() => {window.open("https://github.com/UUoocl/UUhimsy/tree/main/UUhimsy_Demo_Vault/_uvc-util")})

})

new Setting(containerEl)
.setName("Path to UVC-util")
.setDesc("save 'uvc-util' to a folder in this vault")
.addText((item) => {
item.setValue(this.plugin.settings.uvcUtil_folder).onChange(
(value) => {
this.plugin.settings.uvcUtil_folder = value;
this.plugin.saveSettings()

})
});
}

async function refresh_websocketDetailsJS(obsidian){
const fileName = `_browser_Sources/obs_webSocket_details/websocketDetails.js`;
const existing = await obsidian.app.vault.adapter.exists(normalizePath(`${fileName}`));
Expand Down
Binary file removed uvc-util
Binary file not shown.
25 changes: 22 additions & 3 deletions view.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ItemView, WorkspaceLeaf, Setting, Notice, Editor, MarkdownView, MarkdownEditView } from "obsidian";
import { ItemView, WorkspaceLeaf, Setting, Notice, Editor, MarkdownView, MarkdownEditView, IconName } from "obsidian";

export const UUHIMSY_VIEW_TYPE = "uuhimsy-view"

Expand All @@ -15,11 +15,30 @@ export class UUhimsyView extends ItemView{
return "UUhimsy Tags";
}

getIcon(): IconName {
return "wand-sparkles";
}

async onOpen() {
const container = this.containerEl.children[1];

container.empty();
container.createEl('h4', { text: 'UUhimsy Tags' });
container.createDiv('Header')
new Setting(container).setName('UUhimsy Tags')
.setHeading()
.setDesc('refresh the view after running a "Get tags" command')
.addButton((button) =>{
button.setButtonText("refresh view")
.onClick(() => {this.addTagButtons(tagsContainer)})
})

const tagsContainer = container.createDiv('tags')

this.addTagButtons(tagsContainer)
}

addTagButtons(container){
container.empty()
const files = this.app.vault.getFolderByPath("_slide_Tags").children;
files.forEach(file => {
let tag = file.basename.split(' - ')
Expand Down Expand Up @@ -53,7 +72,7 @@ export class UUhimsyView extends ItemView{
})
});
}

async onClose() {
// Nothing to clean up.
}
Expand Down

0 comments on commit b16f92a

Please sign in to comment.