Skip to content

Commit

Permalink
Merge pull request #4 from boemska-nik/master
Browse files Browse the repository at this point in the history
Update plugin to work with latest CodeMirror / Obsidian versions
  • Loading branch information
cobalamin authored Apr 13, 2022
2 parents bd945b0 + 328b130 commit 117b046
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This a plugin integrating the [reMarkable](https://remarkable.com) paper tablet

- Set up [reSnap](https://github.com/cloudsftp/reSnap) on your reMarkable tablet and on your computer.
- Set up your reMarkable so you have passwordless access over SSH, see https://www.reddit.com/r/RemarkableTablet/comments/78u90n/passwordless_ssh_setup_for_remarkable_tablet/
- Install and activate this plugin in Obsidian.
- Install and activate this plugin in Obsidian, either directly or via the [Obsidian42 BRAT plugin](https://github.com/TfTHacker/obsidian42-brat)

Now, go to this plugin's settings page and configure them as described below.

Expand Down
39 changes: 26 additions & 13 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ export default class MyPlugin extends Plugin {
this.addCommand({
id: 'insert-remarkable-drawing',
name: 'Insert a drawing from the reMarkable',
checkCallback: mkCheckCallback(plugin.tryInsertingDrawing.bind(plugin, false)).bind(plugin)
callback: () => {
plugin.tryInsertingDrawing(false)
}
});

this.addCommand({
id: 'insert-remarkable-drawing-landscape',
name: 'Insert a landscape-format drawing from the reMarkable',
checkCallback: mkCheckCallback(plugin.tryInsertingDrawing.bind(plugin, true)).bind(plugin)
callback: () => {
plugin.tryInsertingDrawing(true)
}
});

this.addSettingTab(new SampleSettingTab(this.app, this));
Expand Down Expand Up @@ -125,7 +129,7 @@ export default class MyPlugin extends Plugin {

const now = moment();
const drawingFileName = `rM drawing ${now.format("YYYY-MM-DD-HH.mm.ss")}.png`;
const absOutputFolderPath = this.resolveLibraryPath(this.settings.outputPath);
const absOutputFolderPath = adapter.getFullRealPath(this.settings.outputPath);
const drawingFilePath = path.join(absOutputFolderPath, drawingFileName);

let args = ['-o', drawingFilePath, '-s', rmAddress];
Expand Down Expand Up @@ -171,8 +175,17 @@ export default class MyPlugin extends Plugin {
/* Taken and adapted from hans/obsidian-citation-plugin. Cheers! */
get editor(): Editor {
const view = this.app.workspace.activeLeaf.view;
if (!(view instanceof MarkdownView) || !(view.currentMode instanceof MarkdownSourceView)) return null;
return view.editor;
try {
if (view.editMode.type == "source") {
return view.editor;
}
else {
return null;
}
}
catch (error) {
return null;
}
}

/* Taken from hans/obsidian-citation-plugin. Cheers! */
Expand Down Expand Up @@ -208,20 +221,18 @@ class SampleSettingTab extends PluginSettingTab {
const adapter = this.app.vault.adapter;
if (adapter instanceof FileSystemAdapter) {
const resolvedPath = outputFolder;//this.plugin.resolveLibraryPath(outputFolder);
const exists = await adapter.exists(resolvedPath);
//if(!exists) { throw new Error('Chosen output folder does not exist!'); }
const stat = await adapter.stat(resolvedPath);
if(stat.type !== 'folder') { throw new Error('Chosen output folder is not a folder!'); }
}
else {
throw new Error('Could not get FileSystemAdapter! Is this running on mobile...?');
}
} catch (e) {
this.outputPathSuccess.addClass('d-none');
this.outputPathError.removeClass('d-none');
this.outputPathSuccess.style.display = "none";
this.outputPathError.style.display = "block";
return false;
} finally {
this.outputPathInfo.addClass('d-none');
this.outputPathInfo.style.display = "none";
}

return true;
Expand Down Expand Up @@ -266,9 +277,8 @@ class SampleSettingTab extends PluginSettingTab {
if(success) {
this.plugin.settings.outputPath = value;
await this.plugin.saveSettings();

this.outputPathError.addClass('d-none');
this.outputPathSuccess.removeClass('d-none');
this.outputPathError.style.display = "none";
this.outputPathSuccess.style.display = "block";
}
}));
this.outputPathInfo = containerEl.createEl('p', {
Expand All @@ -284,6 +294,9 @@ class SampleSettingTab extends PluginSettingTab {
cls: 'remarkable-output-path-success d-none',
text: 'Successfully set the output folder.',
});
this.outputPathInfo.style.display = "none";
this.outputPathError.style.display = "none";
this.outputPathSuccess.style.display = "none";

new Setting(containerEl)
.setName('Postprocessing script')
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-remarkable",
"name": "Obsidian & reMarkable",
"version": "1.0.1",
"version": "1.1.0",
"minAppVersion": "0.9.12",
"description": "A plugin to integrate the reMarkable tablet into an Obsidian workflow, allowing users to insert drawings captured from their reMarkable",
"author": "Simon Welker (cobalamin)",
Expand Down

0 comments on commit 117b046

Please sign in to comment.