Skip to content

Commit

Permalink
fix: ribbon commands + special logos
Browse files Browse the repository at this point in the history
  • Loading branch information
phibr0 committed Dec 16, 2022
1 parent 540a1be commit 62d4ac2
Show file tree
Hide file tree
Showing 18 changed files with 199 additions and 158 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "cmdr",
"name": "Commander",
"version": "0.4.4",
"version": "0.4.5",
"minAppVersion": "1.1.0",
"description": "Customize your workspace by adding commands everywhere, create Macros and supercharge your mobile toolbar.",
"author": "jsmorabito & phibr0",
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cmdr",
"version": "0.4.2",
"version": "0.4.5",
"description": "Customize your workspace by adding commands /everywhere/.",
"main": "main.js",
"scripts": {
Expand Down Expand Up @@ -44,7 +44,6 @@
"typescript": "^4.9.3"
},
"dependencies": {
"@codemirror/lang-javascript": "^6.1.1",
"array-move": "^4.0.0",
"canvas-confetti": "^1.6.0",
"preact": "^10.11.3"
Expand Down
16 changes: 14 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/assets/commander-logo-christmas.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/commander-logo-halloween.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 12 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,41 @@ import {
RibbonManager,
StatusBarManager,
} from "./manager/commands";
import { Action, CommanderSettings, Macro } from "./types";
import { Action, CommanderSettings } from "./types";
import CommanderSettingTab from "./ui/settingTab";
import SettingTabModal from "./ui/settingTabModal";

import './styles/styles.scss';
import './styles/advanced-toolbar.scss';
import "./styles/styles.scss";
import "./styles/advanced-toolbar.scss";
import { updateHiderStylesheet } from "./util";
import registerCustomIcons from "./ui/icons";
import LeftRibbonManager from "./manager/commands/leftRibbonManager";

export default class CommanderPlugin extends Plugin {
public settings: CommanderSettings;
public manager: {
editorMenu: EditorMenuCommandManager;
fileMenu: FileMenuCommandManager;
leftRibbon: RibbonManager;
leftRibbon: LeftRibbonManager;
//rightRibbon: RibbonManager,
//titleBar: TitleBarManager,
statusBar: StatusBarManager;
pageHeader: PageHeaderManager;
explorerManager: ExplorerManager;
};

async executeStartupMacros() {
public async executeStartupMacros(): Promise<void> {
const ref = setTimeout(() => {
this.settings.macros.forEach((macro, idx) => {
this.settings.macros.forEach(async (macro, idx) => {
if (macro.startup) {
this.executeMacro(idx);
await this.executeMacro(idx);
}
});
}, 1000);
this.register(() => clearTimeout(ref));
}

async executeMacro(id: number) {
public async executeMacro(id: number): Promise<void> {
const macro = this.settings.macros[id];
if (!macro) throw new Error("Macro not found");

Expand Down Expand Up @@ -77,6 +78,7 @@ export default class CommanderPlugin extends Plugin {

public async onload(): Promise<void> {
await this.loadSettings();
delete this.settings.hide.leftRibbon;

registerCustomIcons();

Expand All @@ -86,7 +88,7 @@ export default class CommanderPlugin extends Plugin {
this.settings.editorMenu
),
fileMenu: new FileMenuCommandManager(this, this.settings.fileMenu),
leftRibbon: new RibbonManager("left", this),
leftRibbon: new LeftRibbonManager(this),
//rightRibbon: new RibbonManager("right", this),
//titleBar: new TitleBarManager(this, this.settings.titleBar),
statusBar: new StatusBarManager(this, this.settings.statusBar),
Expand Down Expand Up @@ -141,7 +143,7 @@ export default class CommanderPlugin extends Plugin {
await this.saveData(this.settings);
}

public listActiveToolbarCommands(): String[] {
public listActiveToolbarCommands(): string[] {
//@ts-ignore
const activeCommands = this.app.vault.getConfig(
"mobileToolbarCommands"
Expand Down
2 changes: 0 additions & 2 deletions src/manager/commands/explorerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,11 @@ export default class ExplorerManager extends CommandManagerBase {

const setNormal = (): void => {
btn.empty();
btn.style.setProperty("--icon-size", `12px`);
setIcon(btn, pair.icon);
btn.onclick = (): void => app.commands.executeCommandById(pair.id);
};
const setRemovable = (): void => {
btn.empty();
btn.style.setProperty("--icon-size", `12px`);
setIcon(btn, "trash");
btn.onclick = async (): Promise<void> => {
if (
Expand Down
61 changes: 61 additions & 0 deletions src/manager/commands/leftRibbonManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import CommanderPlugin from "src/main";
import { CommandIconPair } from "src/types";
import CommandManagerBase from "./commandManager";

export default class LeftRibbonManager extends CommandManagerBase {
public plugin: CommanderPlugin;
//private addBtn: HTMLDivElement;

public constructor(plugin: CommanderPlugin) {
super(plugin, plugin.settings.leftRibbon);
this.plugin = plugin;

app.workspace.onLayoutReady(() => {
this.plugin.settings.leftRibbon.forEach((pair) =>
this.addCommand(pair, false)
);
// if (this.plugin.settings.showAddCommand) {
// this.plugin.addRibbonIcon("plus", t("Add new"), async () =>
// this.addCommand(await chooseNewCommand(plugin))
// );
// }
});
}

public async addCommand(
pair: CommandIconPair,
newlyAdded = true
): Promise<void> {
if (newlyAdded) {
this.plugin.settings.leftRibbon.push(pair);
await this.plugin.saveSettings();
}
this.plugin.addRibbonIcon(pair.icon, pair.name, () =>
app.commands.executeCommandById(pair.id)
);
this.plugin.register(() => this.removeCommand(pair, false));
}

public async removeCommand(
pair: CommandIconPair,
remove = true
): Promise<void> {
if (remove) {
this.plugin.settings.leftRibbon.remove(pair);
await this.plugin.saveSettings();
}
// @ts-expect-error
const nativeAction = app.workspace.leftRibbon.items.find(
// @ts-expect-error
(i) => i.icon === pair.icon && i.name === i.name
);
if (nativeAction) {
nativeAction.buttonEl.remove();
}
// @ts-expect-error
app.workspace.leftRibbon.items.remove(nativeAction);
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
public reorder(): void {}
}
Loading

0 comments on commit 62d4ac2

Please sign in to comment.