Skip to content

Commit

Permalink
feat: macos open with handling
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed Jan 25, 2024
1 parent 191e84b commit 49bef69
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,8 @@ define(function (require, exports, module) {

async function _singleInstanceHandler(args) {
const isPrimary = await Phoenix.app.isPrimaryDesktopPhoenixWindow();
if(!isPrimary){
const bootTimeMacOsFlag = (args[0] === "macOSBootTimeDeepLink");
if(!bootTimeMacOsFlag && !isPrimary){
// only primary phoenix windows can open a new window, else every window is going to make its own
// window and cause a runaway phoenix window explosion.
return;
Expand Down
21 changes: 18 additions & 3 deletions src/phoenix/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Phoenix.app = {
* double clicking a file in file explorer in os, the handler will be called with the command line args with the
* file that was double-clicked (or folder using open with) in os file explorer/cli.
* @param {function(cliArgs, cwd)} handlerFn - the handler function will receive two args on callback, the cliArgs
* of the other phoenix process that was invoked to open the file and its current working dir.
* of the other phoenix process that was invoked to open the file and its current working dir. cwd may be null
* @return {*}
*/
setSingleInstanceCLIArgsHandler: function (handlerFn) {
Expand All @@ -171,10 +171,25 @@ Phoenix.app = {
window.__TAURI__.event.listen("single-instance", ({payload})=> {
handlerFn(payload.args, payload.cwd);
});
window.__TAURI__.tauri.invoke("get_mac_deep_link_requests").then(filesURLList=>{
if(!filesURLList.length){
return;
}
// this is special handling for open with to work from mac finder. Mac will raise and event which will
// be buffered in the shell till the app reads the opened file list. Once read, the file list will be
// emptied in shell and no other instances will get the data, so we have to process it here.
const platformSimulatedArgs = ["macOSBootTimeDeepLink"];
for(const fileURL of filesURLList){
platformSimulatedArgs.push(fileURL.replace("file://", ""));
}
handlerFn(platformSimulatedArgs, "");
});
window.__TAURI__.event.listen("scheme-request-received", (receivedEvent)=> {
// this is for mac-os open with processing from finder.
console.error("Macos not handled", receivedEvent);
alert(JSON.stringify(receivedEvent));
console.log("Macos received Event from OS:", receivedEvent);
const fileURL = receivedEvent.payload;
window.__TAURI__.tauri.invoke("get_mac_deep_link_requests");// this will clear the cached queue in shell
handlerFn(["macOSEvent", fileURL.replace("file://", "")], "");
});
}
},
Expand Down

0 comments on commit 49bef69

Please sign in to comment.