@@ -8,7 +8,9 @@ import AddCommandModal from "./ui/addCommandModal";
88import ChooseIconModal from "./ui/chooseIconModal" ;
99import { Command , Platform , setIcon } from "obsidian" ;
1010import ChooseCustomNameModal from "./ui/chooseCustomNameModal" ;
11- import { ComponentProps , h } from "preact" ;
11+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
12+ import { ComponentProps , h , JSX } from "preact" ;
13+ /** @jsx h */
1214import { useRef , useLayoutEffect } from "preact/hooks" ;
1315import confetti from "canvas-confetti" ;
1416
@@ -55,7 +57,7 @@ export function ObsidianIcon({
5557 icon,
5658 size,
5759 ...props
58- } : ObsidianIconProps ) : h . JSX . Element {
60+ } : ObsidianIconProps ) : JSX . Element {
5961 const iconEl = useRef < HTMLDivElement > ( null ) ;
6062
6163 useLayoutEffect ( ( ) => {
@@ -88,19 +90,17 @@ export function updateHiderStylesheet(settings: CommanderSettings): void {
8890 document . head . querySelector ( "style#cmdr" ) ?. remove ( ) ;
8991
9092 if ( style ) {
91- document . head . appendChild (
92- createEl ( "style" , {
93- attr : { id : "cmdr" } ,
94- text : style ,
95- type : "text/css" ,
96- } )
97- ) ;
93+ const styleEl = document . createElement ( "style" ) ;
94+ styleEl . id = "cmdr" ;
95+ styleEl . type = "text/css" ;
96+ styleEl . textContent = style ;
97+ document . head . appendChild ( styleEl ) ;
9898 }
9999}
100100
101101export async function showConfetti ( { target } : MouseEvent ) : Promise < void > {
102- const myCanvas = activeDocument . createElement ( "canvas" ) ;
103- activeDocument . body . appendChild ( myCanvas ) ;
102+ const myCanvas = document . createElement ( "canvas" ) ;
103+ document . body . appendChild ( myCanvas ) ;
104104 myCanvas . style . position = "fixed" ;
105105 myCanvas . style . width = "100vw" ;
106106 myCanvas . style . height = "100vh" ;
@@ -126,16 +126,16 @@ export async function showConfetti({ target }: MouseEvent): Promise<void> {
126126 ticks : 250 ,
127127 origin : {
128128 //Center of the target component using values from 0 to 1
129- x : ( pos . x + pos . width / 2 ) / activeWindow . innerWidth ,
130- y : ( pos . y + pos . height / 2 ) / activeWindow . innerHeight ,
129+ x : ( pos . x + pos . width / 2 ) / window . innerWidth ,
130+ y : ( pos . y + pos . height / 2 ) / window . innerHeight ,
131131 } ,
132132 } ) ;
133133
134134 myCanvas . remove ( ) ;
135135}
136136
137137export function updateSpacing ( spacing : number ) : void {
138- activeDocument . body . style . setProperty ( "--cmdr-spacing" , `${ spacing } px` ) ;
138+ document . body . style . setProperty ( "--cmdr-spacing" , `${ spacing } px` ) ;
139139}
140140
141141export function updateMacroCommands ( plugin : CommanderPlugin ) : void {
@@ -144,22 +144,44 @@ export function updateMacroCommands(plugin: CommanderPlugin): void {
144144 ) ;
145145 for ( const command of oldCommands ) {
146146 //@ts -ignore
147- app . commands . removeCommand ( command ) ;
147+ plugin . app . commands . removeCommand ( command ) ;
148148 }
149149
150150 const macros = plugin . settings . macros ;
151- for ( const [ idx , macro ] of Object . entries ( macros ) ) {
151+ for ( const [ idx , macro ] of macros . entries ( ) ) {
152+ const commandId = `macro-${ idx } ` ;
153+
154+ // Create the command with direct icon assignment
152155 plugin . addCommand ( {
153- id : `macro- ${ idx } ` ,
156+ id : commandId ,
154157 name : macro . name ,
158+ icon : macro . icon , // Set icon directly on the command
155159 callback : ( ) => {
156- plugin . executeMacro ( parseInt ( idx ) ) ;
160+ plugin . executeMacro ( Number ( idx ) ) ;
157161 } ,
158162 } ) ;
163+
164+ // Also maintain icon mapping for mobile toolbar compatibility
165+ if ( macro . icon ) {
166+ const existingMapping = plugin . settings . advancedToolbar . mappedIcons . find (
167+ m => m . commandID === `cmdr:${ commandId } `
168+ ) ;
169+ if ( existingMapping ) {
170+ existingMapping . iconID = macro . icon ;
171+ } else {
172+ plugin . settings . advancedToolbar . mappedIcons . push ( {
173+ commandID : `cmdr:${ commandId } ` ,
174+ iconID : macro . icon
175+ } ) ;
176+ }
177+ }
159178 }
179+
180+ // Save the updated settings
181+ void plugin . saveSettings ( ) ;
160182}
161183
162- export function updateStyles ( settings : AdvancedToolbarSettings ) {
184+ export function updateStyles ( settings : AdvancedToolbarSettings ) : void {
163185 const { classList : c , style : s } = document . body ;
164186 s . setProperty ( "--at-button-height" , ( settings . rowHeight ?? 48 ) + "px" ) ;
165187 s . setProperty ( "--at-button-width" , ( settings . buttonWidth ?? 48 ) + "px" ) ;
@@ -172,7 +194,7 @@ export function updateStyles(settings: AdvancedToolbarSettings) {
172194 c . toggle ( "AT-no-toolbar" , settings . rowCount === 0 ) ;
173195}
174196
175- export function removeStyles ( ) {
197+ export function removeStyles ( ) : void {
176198 const { classList : c , style : s } = document . body ;
177199 s . removeProperty ( "--at-button-height" ) ;
178200 s . removeProperty ( "--at-button-width" ) ;
@@ -189,13 +211,14 @@ export function removeStyles() {
189211export function injectIcons (
190212 settings : AdvancedToolbarSettings ,
191213 plugin : CommanderPlugin
192- ) {
214+ ) : void {
193215 settings . mappedIcons . forEach ( ( mapped ) => {
194- const command = plugin . app . commands . commands [ mapped . commandID ] ;
216+ const commandId = mapped . commandID . replace ( 'cmdr:' , '' ) ;
217+ const command = plugin . app . commands . commands [ commandId ] ;
195218 if ( command ) {
196219 command . icon = mapped . iconID ;
197220 } else {
198- settings . mappedIcons . remove ( mapped ) ;
221+ settings . mappedIcons = settings . mappedIcons . filter ( m => m !== mapped ) ;
199222 }
200223 } ) ;
201224}
0 commit comments