Skip to content

Commit

Permalink
add bookmarks to html, md, notes viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
kevodwyer committed Sep 30, 2024
1 parent d00615e commit 4b4de0f
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 51 deletions.
18 changes: 0 additions & 18 deletions assets/apps/sandbox/sandbox.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
var mainWindow;
var origin;
var streamWriter;
var currentPath = '';
var currentTitle = '';
let msgHandler = function (e) {
// You must verify that the origin of the message's sender matches your
// expectations. In this case, we're only planning on accepting messages
Expand All @@ -14,26 +12,13 @@ let msgHandler = function (e) {
return;
mainWindow = e.source;
origin = e.origin;

let appIFrame = document.getElementById("appSandboxId");
if (appIFrame != null && appIFrame.contentDocument != null) {
let path = appIFrame.contentDocument.location.pathname;
let title = appIFrame.contentDocument.title;
if (path != null && path != currentPath) {
currentTitle = title;
currentPath = path;
}
}

if (e.data.type == "ping") {
mainWindow.postMessage({action:'pong'}, e.origin);
} else if (e.data.type == "init") {
load(e.data.appName, e.data.appPath, e.data.allowBrowsing, e.data.theme, e.data.chatId,
e.data.username, e.data.props);
} else if(e.data.type == "respondToLoadedChunk") {
respondToLoadedChunk(e.data.bytes);
} else if(e.data.type == "currentTitleRequest") {
currentTitleRequest(e);
}
};
function resizeHandler() {
Expand All @@ -55,9 +40,6 @@ function actionRequest(filePath, requestId, api, apiMethod, bytes, hasFormData,
mainWindow.postMessage({action:'actionRequest', requestId: requestId, filePath: filePath, api: api, apiMethod: apiMethod,
bytes: bytes, hasFormData: hasFormData, params: params, isFromRedirect: isFromRedirect, isNavigate: isNavigate}, origin);
}
function currentTitleRequest(e) {
e.source.postMessage({action:'currentTitleResponse', path: currentPath, title: currentTitle}, e.origin);
}
function load(appName, appPath, allowBrowsing, theme, chatId, username, props) {
let that = this;
let iframe = document.getElementById("appSandboxId");
Expand Down
2 changes: 2 additions & 0 deletions assets/images/bookmark-o.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions assets/images/bookmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 91 additions & 27 deletions src/components/sandbox/AppSandbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@
</Confirm>
<div v-if="!fullscreenMode" class="modal-header" style="padding:0;min-height: 52px;">
<center><h2>{{ getFullPathForDisplay() }}
<span v-if="displayFullScreenIcon" @click="requestFullscreenFromToolbar" tabindex="0" v-on:keyup.enter="requestFullscreenFromToolbar" style="cursor:pointer;">
<img src="./images/arrows-alt.svg" style="height:24px;width:24px">
<span v-if="browserMode && !isSecretLink && fullPathForDisplay.length > 0 && !this.isMobile" style="z-index:9999">
<img v-if="displayToBookmark" src="./images/bookmark-o.svg" @click="toggleBookmark(false)" style="height:24px;width:24px;cursor:pointer;">
<img v-if="!displayToBookmark" src="./images/bookmark.svg" @click="toggleBookmark(true)" style="height:24px;width:24px;cursor:pointer;">
</span>
<span v-if="displayFullScreenIcon" @click="requestFullscreenFromToolbar" v-on:keyup.enter="requestFullscreenFromToolbar" style="cursor:pointer;">
<img src="./images/arrows-alt.svg" style="height:24px;width:24px;cursor:pointer">
</span>
</h2>
</center>
Expand Down Expand Up @@ -239,6 +243,7 @@ module.exports = {
confirm_body: "",
confirm_consumer_cancel_func: () => {},
confirm_consumer_func: () => {},
displayToBookmark: true,
}
},
computed: {
Expand All @@ -248,7 +253,8 @@ module.exports = {
'context',
"sandboxedApps",
'mirrorBatId',
"socialData"
"socialData",
"shortcuts"
]),
...Vuex.mapGetters([
'isSecretLink',
Expand Down Expand Up @@ -313,7 +319,7 @@ module.exports = {
that.appRegisteredWithFileAssociation = that.appHasFileAssociation(that.currentProps);
that.appRegisteredWithWildcardFileAssociation = that.appHasWildcardFileRegistration(that.currentProps);
}
that.startListener();
that.start();
});
} else {
this.loadAppProperties().thenApply(props => {
Expand Down Expand Up @@ -345,15 +351,15 @@ module.exports = {
that.clientMailboxAddress = clientAddress.ref.toLowerCase();
that.getMailboxPropertiesFile().thenApply(props => {
that.mailboxClientProperties = props;
that.startListener();
that.start();
});
}
});
});
}
});
} else {
that.startListener();
that.start();
}
});
});
Expand Down Expand Up @@ -487,11 +493,6 @@ module.exports = {
extractWorkspace: function(path) {
return path.substring(1, path.indexOf('/', 1));
},
startTitleDetection: function() {
if (!this.running) return;
this.postMessage({type: 'currentTitleRequest'});
setTimeout(() => this.startTitleDetection(), 300);
},
loadAppProperties: function(appFolderLocation) {
let that = this;
var future = peergos.shared.util.Futures.incomplete();
Expand All @@ -504,20 +505,66 @@ module.exports = {
}
return future;
},
currentTitleResponse: function(fullPath, title) {
if (fullPath != "blank") {
this.setFullPathForDisplay(fullPath);
}
},
getFullPathForDisplay: function() {
let pathToDisplay = this.fullPathForDisplay;
if (pathToDisplay.length > 0 && this.browserMode && !this.isMobile) {
this.displayFullScreenIcon = true;
}
return pathToDisplay;
},
setFullPathForDisplay: function(path) {
this.fullPathForDisplay = path;
toggleBookmark: function(remove) {
if(this.showSpinner || this.isSecretLink) {
return;
}
let that = this;
let address = this.fullPathForDisplay;
if (address.length <= 1) {
return;
}
let bookmark = this.shortcuts.shortcutsMap.get(address);
let fileCreatedDate = new Date(this.targetFile.getFileProperties().created.toString() + "+00:00")
if (remove) {
if (bookmark != null) {
this.refreshAndDeleteBookmark(address);
}
} else {
if (bookmark == null) {
this.refreshAndAddBookmark(address, fileCreatedDate);
}
}
},
refreshAndAddBookmark(link, created) {
let that = this;
this.showSpinner = true;
this.loadShortcutsFile(this.launcherApp).thenApply(shortcutsMap => {
if (shortcutsMap.get(link) == null) {
let entry = {added: new Date(), created: created};
shortcutsMap.set(link, entry)
that.updateShortcutsFile(that.launcherApp, shortcutsMap).thenApply(res => {
that.showSpinner = false;
that.displayToBookmark = false;
that.$store.commit("SET_SHORTCUTS", shortcutsMap);
});
} else {
that.showSpinner = false;
}
})
},
refreshAndDeleteBookmark(link) {
let that = this;
this.showSpinner = true;
this.loadShortcutsFile(this.launcherApp).thenApply(shortcutsMap => {
if (shortcutsMap.get(link) != null) {
shortcutsMap.delete(link)
that.updateShortcutsFile(that.launcherApp, shortcutsMap).thenApply(res => {
that.showSpinner = false;
that.displayToBookmark = true;
that.$store.commit("SET_SHORTCUTS", shortcutsMap);
});
} else {
that.showSpinner = false;
}
})
},
validatePermissions: function(props) {
let allPermissions = new Map();
Expand Down Expand Up @@ -606,12 +653,17 @@ module.exports = {
} else if(e.data.action == 'actionRequest') {
that.actionRequest(e.data.filePath, e.data.requestId, e.data.api, e.data.apiMethod, e.data.bytes,
e.data.hasFormData, e.data.params, e.data.isFromRedirect, e.data.isNavigate);
} else if(e.data.action == 'currentTitleResponse') {
that.currentTitleResponse(e.data.path, e.data.title);
}
}
}
},
start: function() {
let that = this;
peergos.shared.user.App.init(this.context, "launcher").thenApply(launcher => {
that.launcherApp = launcher;
that.startListener();
});
},
startListener: function() {
var that = this;
var iframeContainer = document.getElementById("sandbox-container");
Expand Down Expand Up @@ -826,7 +878,7 @@ module.exports = {
that.showError("App attempted to access file without permission :" + path);
that.buildResponse(headerFunc(), null, that.ACTION_FAILED);
} else {
that.readFileOrFolder(headerFunc, '/data/' + path, params, true);
that.readFileOrFolder(headerFunc, '/data/' + path, params, true, false);
}
} else {
let prefix = !this.browserMode
Expand All @@ -838,7 +890,7 @@ module.exports = {
if (this.browserMode) {
that.handleBrowserRequest(headerFunc, path, params, isFromRedirect, isNavigate);
} else {
that.readFileOrFolder(headerFunc, prefix + path, params);
that.readFileOrFolder(headerFunc, prefix + path, params, false, false);
}
}
} else {
Expand Down Expand Up @@ -2921,10 +2973,11 @@ module.exports = {
});
} else {
if (isNavigate) {
that.fullPathForDisplay = path;
if (!that.running) {
that.running = true;
that.startTitleDetection();
that.readFileOrFolder(headerFunc, path, params);
that.setBookmarkIcon();
that.readFileOrFolder(headerFunc, path, params, false, false);
} else {
let fullPath = that.expandFilePath(path, isFromRedirect);
var app = that.getApp(file, fullPath);
Expand All @@ -2936,24 +2989,32 @@ module.exports = {
}
// If we are navigating to an 'external' link, use a new context on a different subdomain
if (app == 'htmlviewer' && that.extractWorkspace(fullPath) == that.workspaceName) {
that.readFileOrFolder(headerFunc, path, params);
that.setBookmarkIcon();
that.readFileOrFolder(headerFunc, path, params, false, true);
} else {
that.closeAndLaunchApp(headerFunc, app, navigationPath, navigationFilename);
}
}
} else {
that.readFileOrFolder(headerFunc, path, params);
that.readFileOrFolder(headerFunc, path, params, false, false);
}
}
}
});
},
setBookmarkIcon: function() {
if (this.shortcuts.shortcutsMap.get(this.fullPathForDisplay) == null) {
this.displayToBookmark = true;
} else {
this.displayToBookmark = false;
}
},
closeAndLaunchApp: function(headerFunc, app, path, filename) {
this.buildResponse(headerFunc(), null, this.NAVIGATE_TO);
this.navigateTo = { app: app, navigationPath: path, navigationFilename: filename};
this.closeSandbox();
},
readFileOrFolder: function(headerFunc, path, params, ignoreHiddenFolderCheck) {
readFileOrFolder: function(headerFunc, path, params, ignoreHiddenFolderCheck, updateTargetFile) {
let that = this;
let expandedFilePath = this.expandFilePath(path);
if (this.browserMode && expandedFilePath.includes('/.')) {
Expand Down Expand Up @@ -2990,6 +3051,9 @@ module.exports = {
that.buildResponse(headerFunc(), null, that.ACTION_FAILED);
}
} else {
if (updateTargetFile) {
that.targetFile = resp;
}
that.readInFile(headerFunc, resp);
}
}
Expand Down
Loading

0 comments on commit 4b4de0f

Please sign in to comment.